summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2019-06-05 16:17:16 +0200
committerSimon Rettberg2019-06-05 16:17:16 +0200
commit615ca2f927e8a4c4b5b0591495e7c9417231cab3 (patch)
tree1962e3603a24baa0d4c2cc06c65ab32542243975 /src
parentUse Qt5 style signal/slot connections (diff)
downloadvmchooser2-615ca2f927e8a4c4b5b0591495e7c9417231cab3.tar.gz
vmchooser2-615ca2f927e8a4c4b5b0591495e7c9417231cab3.tar.xz
vmchooser2-615ca2f927e8a4c4b5b0591495e7c9417231cab3.zip
Don't group by type in "recent" tab
Diffstat (limited to 'src')
-rw-r--r--src/dialog.cpp17
-rw-r--r--src/sessiontreemodel.cpp19
-rw-r--r--src/sessiontreemodel.h3
-rw-r--r--src/userconfig.cpp2
4 files changed, 25 insertions, 16 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index 5e7a6b0..984b7ad 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -28,7 +28,7 @@ static bool isProcessRunning(const QString &binary);
Dialog::Dialog(QWidget *parent)
: QDialog(parent), ui(new Ui::Dialog) {
model_[TAB_NATIVE] = new SessionTreeModel(parent);
- model_[TAB_RECENT_COURSES] = new SessionTreeModel(parent);
+ model_[TAB_RECENT_COURSES] = new SessionTreeModel(parent, true);
model_[TAB_ALL_VMS] = new SessionTreeModel(parent);
userInteracted_ = false;
genericExpandedOnce_ = false;
@@ -215,10 +215,12 @@ void Dialog::on_treeView_expanded(const QModelIndex& index) {
}
void Dialog::addItems(const QList<Session*>& entries, int tab) {
- if (tab < 0 || tab > 2) {
- return;
- }
+ if (tab < 0 || tab >= TAB_COUNT)
+ return; // Invalid index
+ if (Config::isSet(Config::EXAM_MODE) && tab == TAB_NATIVE)
+ return; // Exam mode -- keep native sessions empty
if (tab != TAB_RECENT_COURSES) {
+ // If tab is not the recent courses tab, check the list for any recent sessions
auto prev = UserConfig::getLastSessions();
if (!prev.isEmpty()) {
QList<Session*> matches;
@@ -233,8 +235,6 @@ void Dialog::addItems(const QList<Session*>& entries, int tab) {
}
}
}
- if (Config::isSet(Config::EXAM_MODE) && tab == TAB_NATIVE)
- return;
this->model_[tab]->addItems(entries);
tabs_[tab]->setEnabled(this->model_[tab]->rowCount() != 0);
if (tab == activeTab_) {
@@ -769,9 +769,14 @@ void Dialog::on_filterEdit_textChanged() {
void Dialog::setListModel(SessionTreeModel *model) {
QAbstractItemModel *old = nullptr;
if (ui->treeView->model() == model_[TAB_NATIVE] || ui->treeView->model() == model_[TAB_RECENT_COURSES] || ui->treeView->model() == model_[TAB_ALL_VMS]) {
+ // A default model is currently being set; don't delete it
} else {
+ // Remember currently set model so we can delete it after setting the new one
old = ui->treeView->model();
}
+ // Disconnect current model
+ QObject::disconnect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged,
+ this, &Dialog::treeView_selectionChanged);
ui->treeView->setModel(model);
ui->treeView->expandAll();
if (!genericExpandedOnce_ && g_forLocationHandling == LOCATION_EXCLUSIVE && model->rowCount() > 1) {
diff --git a/src/sessiontreemodel.cpp b/src/sessiontreemodel.cpp
index deda9b7..6861158 100644
--- a/src/sessiontreemodel.cpp
+++ b/src/sessiontreemodel.cpp
@@ -11,8 +11,8 @@
#include "sessionsiconholder.h"
#include "globals.h"
-SessionTreeModel::SessionTreeModel(QObject *parent)
- : QAbstractItemModel(parent) {
+SessionTreeModel::SessionTreeModel(QObject *parent, bool ignoreSections)
+ : QAbstractItemModel(parent), ignoreSections_(ignoreSections) {
root_ = new SessionTreeItem(SECTION_nullptr);
}
@@ -130,11 +130,15 @@ void SessionTreeModel::addItems(const QList<Session*>& sessions) {
SessionTreeItem* parentItem = nullptr;
SectionType section = s->section();
- for (int i = 0; i < root_->childCount(); ++i) {
- SessionTreeItem* item = root_->child(i);
- if (item->sectionType() == section) {
- parentItem = item;
- break;
+ if (ignoreSections_) {
+ parentItem = root_;
+ } else {
+ for (int i = 0; i < root_->childCount(); ++i) {
+ SessionTreeItem* item = root_->child(i);
+ if (item->sectionType() == section) {
+ parentItem = item;
+ break;
+ }
}
}
@@ -142,7 +146,6 @@ void SessionTreeModel::addItems(const QList<Session*>& sessions) {
parentItem = new SessionTreeItem(section, root_);
root_->appendChild(parentItem);
}
-
parentItem->appendChild(new SessionTreeItem(s, parentItem));
}
}
diff --git a/src/sessiontreemodel.h b/src/sessiontreemodel.h
index febd0aa..b7943aa 100644
--- a/src/sessiontreemodel.h
+++ b/src/sessiontreemodel.h
@@ -13,7 +13,7 @@ class SessionTreeModel : public QAbstractItemModel {
Q_OBJECT
public:
- explicit SessionTreeModel(QObject *parent = nullptr);
+ explicit SessionTreeModel(QObject *parent = nullptr, bool ignoreSections = false);
~SessionTreeModel();
QVariant data(const QModelIndex &index, int role) const;
@@ -37,6 +37,7 @@ class SessionTreeModel : public QAbstractItemModel {
private:
SessionTreeItem* root_;
+ bool ignoreSections_;
};
#endif // VMCHOOSER_SESSIONTREEMODEL_H
diff --git a/src/userconfig.cpp b/src/userconfig.cpp
index c801b70..7bc83fe 100644
--- a/src/userconfig.cpp
+++ b/src/userconfig.cpp
@@ -49,7 +49,7 @@ QStringList UserConfig::getLastSessions()
ret.append(old);
}
}
- while (ret.size() > 10) {
+ while (ret.size() > 5) {
ret.pop_front();
}
return ret;