summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
authorNils Schwabe2014-03-20 18:47:48 +0100
committerNils Schwabe2014-03-20 18:47:48 +0100
commitf3a0b4d09379e63a26ec410088617fe20d5cd27f (patch)
treee34adf2e0bf92ad5e0e03602c0d6060efbcdbead /src/dialog.cpp
parentremoved the file and path option for XMLs (diff)
downloadvmchooser2-f3a0b4d09379e63a26ec410088617fe20d5cd27f.tar.gz
vmchooser2-f3a0b4d09379e63a26ec410088617fe20d5cd27f.tar.xz
vmchooser2-f3a0b4d09379e63a26ec410088617fe20d5cd27f.zip
- added tab view
- added filter box
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp172
1 files changed, 137 insertions, 35 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index 3adfef6..798d6be 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -16,7 +16,10 @@
Dialog::Dialog(QWidget *parent)
: QDialog(parent), ui(new Ui::Dialog) {
- model_ = new SessionTreeModel(parent);
+ model_[0] = new SessionTreeModel(parent);
+ model_[1] = new SessionTreeModel(parent);
+ model_[2] = new SessionTreeModel(parent);
+
ui->setupUi(this);
pvsSettings_ = NULL;
@@ -29,7 +32,10 @@ Dialog::Dialog(QWidget *parent)
connect(centerTimer_, SIGNAL(timeout()), this, SLOT(onCenterTimer()));
centerTimer_->start(1000);
- ui->treeView->setModel(model_);
+ activeTab = 0;
+ ui->tabButtonLocal->setChecked(true);
+
+ setListModel(model_[0]);
QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)),
this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&)));
@@ -37,7 +43,9 @@ Dialog::Dialog(QWidget *parent)
Dialog::~Dialog() {
delete ui;
- delete model_;
+ delete model_[0];
+ delete model_[1];
+ delete model_[2];
}
void Dialog::changeEvent(QEvent *e) {
@@ -83,19 +91,25 @@ void Dialog::on_treeView_activated(QModelIndex index) {
}
}
-void Dialog::addItems(const QList<Session*>& entries, const QString& section) {
- this->model_->addItems(entries, section);
- ui->treeView->expandAll();
+void Dialog::addItems(const QList<Session*>& entries, int tab) {
+ if (tab < 0 || tab > 2) {
+ return;
+ }
+ this->model_[tab]->addItems(entries);
}
-void Dialog::addLabelItem(const QString& label, const QString& section) {
- this->model_->addLabelItem(label, section);
- ui->treeView->expandAll();
+void Dialog::addLabelItem(const QString& label, int tab) {
+ if (tab < 0 || tab > 2) {
+ return;
+ }
+ this->model_[tab]->addLabelItem(label);
}
-void Dialog::removeItem(const QString& name, const QString& section) {
- this->model_->removeItem(name, section);
- ui->treeView->expandAll();
+void Dialog::removeItem(const QString& name, int tab) {
+ if (tab < 0 || tab > 2) {
+ return;
+ }
+ this->model_[tab]->removeItem(name);
}
void Dialog::on_pushButtonAbort_clicked() {
@@ -168,23 +182,25 @@ void Dialog::on_comboBoxOthers_currentIndexChanged(int index) {
bool Dialog::selectSession(const QString& name) {
QModelIndex root(ui->treeView->rootIndex());
- for (int i = 0; i < model_->rowCount(root); ++i) {
- QModelIndex section = model_->index(i, 0, root);
- if (!section.isValid()) break;
- for (int row = 0; row < model_->rowCount(section); ++row) {
- QModelIndex index = model_->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 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;
+ }
+ }
+ }
}
return false;
}
@@ -273,8 +289,8 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
if (debugMode) {
qDebug() << "Cannot read backup file " << xml_backup_filename << " either";
}
- this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."),QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
- this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "URL Error"), QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
+ this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."), 1);
+ this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "URL Error"), 1);
return;
}
@@ -288,7 +304,7 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
qSort(sessions.begin(), sessions.end(), myLessThan);
- this->addItems(sessions, QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
+ this->addItems(sessions, 1);
} else {
@@ -312,12 +328,12 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
const QList<Session*> sessions = VSession::readXmlFile(xml_filename);
- this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."),QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
+ this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."), 1);
if (!sessions.isEmpty()) {
- this->addItems(sessions, QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
+ this->addItems(sessions, 1);
} else {
- this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "No Items"), QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
+ this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "No Items"), 1);
}
}
@@ -327,12 +343,16 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI
const Session* s(item->session());
if (!s) {
+ if (debugMode) {
+ qDebug() << "invalid selection";
+ }
// no valid session has been selected, do nothing
return;
}
if (s->type() == Session::VSESSION) {
const VSession* vs = (VSession*) s;
+
ui->label_name->setText(vs->getAttribute("short_description", "param"));
ui->label_name->setToolTip(vs->getAttribute("short_description", "param"));
@@ -351,3 +371,85 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI
ui->textBrowser->setPlainText(QCoreApplication::instance()->translate("Dialog", "Running on this machine."));
}
}
+
+void Dialog::on_tabButtonLocal_clicked() {
+ onTabButtonChanged(0);
+}
+
+void Dialog::on_tabButtonMyClasses_clicked() {
+ onTabButtonChanged(1);
+}
+
+void Dialog::on_tabButtonAllClasses_clicked() {
+ onTabButtonChanged(2);
+}
+
+void Dialog::onTabButtonChanged(int tab) {
+ if (tab < 0 || tab > 2) {
+ // no valid button
+ return;
+ }
+
+ // give focus to treeView
+ ui->treeView->setFocus();
+
+ // one button needs to be enabled
+ if (this->activeTab == tab) {
+ switch (tab) {
+ case 0: ui->tabButtonLocal->setChecked(true); break;
+ case 1: ui->tabButtonMyClasses->setChecked(true); break;
+ case 2: ui->tabButtonAllClasses->setChecked(true); break;
+ }
+ }
+
+
+ this->activeTab = tab;
+
+ // when button was pressed disable the other buttons
+ if (tab == 0) {
+ ui->tabButtonMyClasses->setChecked(false);
+ ui->tabButtonAllClasses->setChecked(false);
+ } else if (tab == 1) {
+ ui->tabButtonLocal->setChecked(false);
+ ui->tabButtonAllClasses->setChecked(false);
+ } else {
+ ui->tabButtonLocal->setChecked(false);
+ ui->tabButtonMyClasses->setChecked(false);
+ }
+
+ // 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() {
+ SessionTreeModel *newModel;
+
+ // filter the current model
+ if (ui->filterEdit->text() != "" && ui->filterEdit->text().length() > 2) {
+ newModel = new SessionTreeModel(this);
+ newModel->addItems(this->model_[activeTab]->lookForItem(ui->filterEdit->text()));
+ } else {
+ newModel = model_[activeTab];
+ }
+
+ setListModel(newModel);
+ if (ui->treeView->selectionModel()->selectedRows(0).count() == 0) {
+ ui->treeView->selectionModel()->clearSelection();
+ ui->treeView->selectionModel()->setCurrentIndex(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select);
+ }
+ // reconnect the treeModel
+ QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)),
+ this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&)));
+}
+
+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);
+}