blob: a7b3a5ee7e03300b2ba83eb5fb5acef7e303553f (
plain) (
tree)
|
|
#include "dialog.h"
#include "ui_dialog.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)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void Dialog::on_treeView_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?
SessionTreeItem* item =
static_cast<SessionTreeItem*>(index.internalPointer());
const Session* s(item->session());
if (!s) {
return;
}
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());
this->model_->addItems(entries, section);
// TODO: do this only once?
ui->treeView->setModel(model_);
ui->treeView->expandAll();
}
void Dialog::on_pushButtonAbort_clicked()
{
close();
}
void Dialog::on_pushButtonStart_clicked()
{
// TODO: check if a model is selected
this->on_treeView_activated(ui->treeView->selectionModel()->currentIndex());
}
|