blob: a1ab2660831fe4c94b5223b5e16214a525e5988e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#include "dialog.h"
#include "ui_dialog.h"
#include "model.h"
#include "session.h"
#include "save_restore_session.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void Dialog::on_listView_activated(QModelIndex index)
{
//TODO handle failures
printf ("Item %d has been activated\n", index.row());
//TODO get rid of this->entries, storing them in the model should be enough
// alternatively use references instead of copies?
Session* s(this->entries_.at(index.row()));
if (s->run()) {
writeSessionName(s->shortDescription());
close();
} else {
// TODO: error instead of close
close();
}
}
void Dialog::addItems(const QList<Session*>& entries, const QString& section) {
// TODO: section
// TODO: this is not the right way to do this
// we probably do not need a copy of the entries vector in Dialog and Model
printf("Dialog::addItems()\n");
printf(" before: %d items\n", this->entries_.size());
printf(" %d new items\n", entries.size());
this->entries_.append(entries);
printf(" after: %d items\n", this->entries_.size());
QAbstractListModel *data = new Model(this->entries_, ui->listView);
QItemSelectionModel *m = ui->listView->selectionModel();
ui->listView->setModel(data);
delete m;
}
void Dialog::on_pushButtonAbort_clicked()
{
close();
}
void Dialog::on_pushButtonStart_clicked()
{
// TODO: check if a model is selected
this->on_listView_activated(ui->listView->selectionModel()->currentIndex());
}
|