From ee3f7eafae9e2e570c95e1afa9bea156ba3bf736 Mon Sep 17 00:00:00 2001 From: Jan Darmochwal Date: Sun, 3 Oct 2010 18:39:42 +0200 Subject: 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 --- src/dialog.cpp | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'src/dialog.cpp') 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(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& 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()); } -- cgit v1.2.3-55-g7522