summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
authorJan Darmochwal2010-10-03 18:39:42 +0200
committerJan Darmochwal2010-10-03 18:39:42 +0200
commitee3f7eafae9e2e570c95e1afa9bea156ba3bf736 (patch)
tree7ffcb71280a344bde5249069991a1b5b841474df /src/dialog.cpp
parentQt port is almost complete (at least it compiles) (diff)
downloadvmchooser-ee3f7eafae9e2e570c95e1afa9bea156ba3bf736.tar.gz
vmchooser-ee3f7eafae9e2e570c95e1afa9bea156ba3bf736.tar.xz
vmchooser-ee3f7eafae9e2e570c95e1afa9bea156ba3bf736.zip
TreeView for sessions (replaces ListView)
TreeView with SessionTreeModel replaces the old List View Other changes: * fixed bad copy and paste in CMakeLists.txt * added make clean to build.sh * removed moc_ and ui_ files from src
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index a1ab266..a7b3a5e 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -1,19 +1,20 @@
#include "dialog.h"
#include "ui_dialog.h"
-#include "model.h"
-#include "session.h"
#include "save_restore_session.h"
+#include "sessiontreeitem.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
+ model_ = new SessionTreeModel(parent);
ui->setupUi(this);
}
Dialog::~Dialog()
{
delete ui;
+ delete model_;
}
void Dialog::changeEvent(QEvent *e)
@@ -28,13 +29,20 @@ void Dialog::changeEvent(QEvent *e)
}
}
-void Dialog::on_listView_activated(QModelIndex index)
+void Dialog::on_treeView_activated(QModelIndex index)
{
//TODO handle failures
- printf ("Item %d has been activated\n", index.row());
+ //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()));
+
+ SessionTreeItem* item =
+ static_cast<SessionTreeItem*>(index.internalPointer());
+
+ const Session* s(item->session());
+ if (!s) {
+ return;
+ }
if (s->run()) {
writeSessionName(s->shortDescription());
close();
@@ -48,15 +56,17 @@ 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;
+ //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());
+
+ this->model_->addItems(entries, section);
+
+ // TODO: do this only once?
+ ui->treeView->setModel(model_);
+ ui->treeView->expandAll();
}
void Dialog::on_pushButtonAbort_clicked()
@@ -67,5 +77,5 @@ void Dialog::on_pushButtonAbort_clicked()
void Dialog::on_pushButtonStart_clicked()
{
// TODO: check if a model is selected
- this->on_listView_activated(ui->listView->selectionModel()->currentIndex());
+ this->on_treeView_activated(ui->treeView->selectionModel()->currentIndex());
}