summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
authorNils Schwabe2014-03-24 14:59:05 +0100
committerNils Schwabe2014-03-24 14:59:05 +0100
commit37e2f2292981bf6227482f762db15b86e42d089f (patch)
tree61a98fe401aa985b5194972812d14dec5ed008bc /src/dialog.cpp
parentadded help and news box (diff)
downloadvmchooser2-37e2f2292981bf6227482f762db15b86e42d089f.tar.gz
vmchooser2-37e2f2292981bf6227482f762db15b86e42d089f.tar.xz
vmchooser2-37e2f2292981bf6227482f762db15b86e42d089f.zip
added choosersettings which remember the last selected session
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp71
1 files changed, 38 insertions, 33 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index 1249561..9fdbaa9 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -9,10 +9,10 @@
#include <QDesktopWidget>
#include "ui_dialog.h"
-#include "save_restore_session.h"
#include "sessiontreeitem.h"
#include "globals.h"
#include "vsession.h"
+#include "choosersettings.h"
Dialog::Dialog(QWidget *parent)
: QDialog(parent), ui(new Ui::Dialog) {
@@ -85,7 +85,7 @@ void Dialog::on_treeView_activated(QModelIndex index) {
if (s->run()) {
writePVSSettings();
- writeSessionName(s->shortDescription());
+ ChooserSettings::setSetting("last-session", (s->shortDescription()));
setVisible(false);
} else {
@@ -186,31 +186,34 @@ void Dialog::on_comboBoxOthers_currentIndexChanged(int index) {
bool Dialog::selectSession(const QString& name) {
QModelIndex root(ui->treeView->rootIndex());
- for (int k = 0; k <= 2; ++k) {
- for (int i = 0; i < model_[k]->rowCount(root); ++i) {
- QModelIndex section = model_[k]->index(i, 0, root);
- if (!section.isValid()) break;
- for (int row = 0; row < model_[k]->rowCount(section); ++row) {
- QModelIndex index = model_[k]->index(row, 0, section);
- if (!index.isValid()) break;
-
- SessionTreeItem* item =
- static_cast<SessionTreeItem*>(index.internalPointer());
- const Session* s(item->session());
- if (!s) continue;
- if (s->shortDescription() == name) {
- ui->treeView->selectionModel()
- ->setCurrentIndex(index, QItemSelectionModel::Select);
- return true;
- }
+ for (int tab = 0; tab <= 2; ++tab) {
+ for (int i = 0; i < model_[tab]->rowCount(root); ++i) {
+ QModelIndex index = model_[tab]->index(i, 0, root);
+ if (!index.isValid()) {
+ break;
}
- }
+ SessionTreeItem* item = static_cast<SessionTreeItem*>(index.internalPointer());
+ const Session* s(item->session());
+ if (!s) {
+ continue;
+ }
+ if (s->shortDescription() == name) {
+ // change the tab
+ onTabButtonChanged(tab);
+ // set selection
+ ui->treeView->selectionModel()
+ ->setCurrentIndex(index, QItemSelectionModel::Select);
+ return true;
+ }
+ }
}
+
return false;
}
void Dialog::selectPreviousSession() {
- selectSession(readSessionName());
+ qDebug() << "selecting previous session";
+ selectSession(ChooserSettings::getSetting("last-session"));
}
void Dialog::startSession(const QString& name) {
@@ -339,6 +342,9 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
} else {
this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "No Items"), 1);
}
+
+ // select last-session
+ selectPreviousSession();
}
void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelIndex&) {
@@ -417,25 +423,24 @@ void Dialog::onTabButtonChanged(int tab) {
// when button was pressed disable the other buttons
if (tab == 0) {
+ ui->tabButtonLocal->setChecked(true);
ui->tabButtonMyClasses->setChecked(false);
ui->tabButtonAllClasses->setChecked(false);
ui->filterEdit->setEnabled(false);
} else if (tab == 1) {
ui->tabButtonLocal->setChecked(false);
+ ui->tabButtonMyClasses->setChecked(true);
ui->tabButtonAllClasses->setChecked(false);
ui->filterEdit->setEnabled(true);
} else {
ui->tabButtonLocal->setChecked(false);
ui->tabButtonMyClasses->setChecked(false);
+ ui->tabButtonAllClasses->setChecked(true);
ui->filterEdit->setEnabled(true);
}
// load the new list
setListModel(model_[tab]);
-
- // reconnect the treeModel
- QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)),
- this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&)));
}
void Dialog::on_filterEdit_textChanged() {
@@ -450,6 +455,14 @@ void Dialog::on_filterEdit_textChanged() {
}
setListModel(newModel);
+}
+
+void Dialog::setListModel(QAbstractItemModel *model) {
+ if (ui->treeView->model() == model_[0] || ui->treeView->model() == model_[1] || ui->treeView->model() == model_[2]) {
+ } else {
+ ui->treeView->model()->deleteLater();
+ }
+ ui->treeView->setModel(model);
// reconnect the treeModel
QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)),
@@ -461,14 +474,6 @@ void Dialog::on_filterEdit_textChanged() {
}
}
-void Dialog::setListModel(QAbstractItemModel *model) {
- if (ui->treeView->model() == model_[0] || ui->treeView->model() == model_[1] || ui->treeView->model() == model_[2]) {
- } else {
- ui->treeView->model()->deleteLater();
- }
- ui->treeView->setModel(model);
-}
-
void Dialog::on_helpNewsButton_clicked() {
if (ui->helpBox->isVisible()) {
ui->helpBox->hide();