summaryrefslogtreecommitdiffstats
path: root/src/sessiontreemodel.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2016-01-19 17:23:23 +0100
committerSimon Rettberg2016-01-19 17:23:23 +0100
commit5177db6d63e48e7ff6ee9ffcef2dee9d77b80075 (patch)
tree2b45af855d00dac72f009d77390cd1a5d74d8e0e /src/sessiontreemodel.cpp
parentFix filter logic (diff)
downloadvmchooser2-5177db6d63e48e7ff6ee9ffcef2dee9d77b80075.tar.gz
vmchooser2-5177db6d63e48e7ff6ee9ffcef2dee9d77b80075.tar.xz
vmchooser2-5177db6d63e48e7ff6ee9ffcef2dee9d77b80075.zip
Re-introduce tree structure: Allow server-defined sections
Diffstat (limited to 'src/sessiontreemodel.cpp')
-rw-r--r--src/sessiontreemodel.cpp48
1 files changed, 33 insertions, 15 deletions
diff --git a/src/sessiontreemodel.cpp b/src/sessiontreemodel.cpp
index cf4f2cf..69c7302 100644
--- a/src/sessiontreemodel.cpp
+++ b/src/sessiontreemodel.cpp
@@ -125,8 +125,27 @@ QModelIndex SessionTreeModel::parent(const QModelIndex &index) const {
}
void SessionTreeModel::addItems(const QList<Session*>& sessions) {
+ SessionTreeItem* parentItem;
+
foreach (Session* s, sessions) {
- root_->appendChild(new SessionTreeItem(s, root_));
+ bool sectionExists = false;
+ QString section(s->section());
+
+ for (int i = 0; i < root_->childCount(); ++i) {
+ SessionTreeItem* item = root_->child(i);
+ if (item->text() == section) {
+ parentItem = item;
+ sectionExists = true;
+ break;
+ }
+ }
+
+ if (!sectionExists) {
+ parentItem = new SessionTreeItem(section, root_);
+ root_->appendChild(parentItem);
+ }
+
+ parentItem->appendChild(new SessionTreeItem(s, parentItem));
}
}
@@ -143,32 +162,31 @@ void SessionTreeModel::removeItem(const QString& name) {
}
}
+static void lookDeeper(QList<Session*>& result, QList<QString>& items, SessionTreeItem* root) {
+ for (int i = 0; i < root->childCount(); ++i) {
+ SessionTreeItem* item = root->child(i);
+ if (item->session() != NULL && item->session()->containsKeywords(items)) {
+ result.append(const_cast<Session*>(item->session()));
+ }
+ lookDeeper(result, items, item);
+ }
+}
+
QList<Session*> SessionTreeModel::lookForItem(const QString& label) {
QList<Session*> result;
+ QList<QString> items;
if (label.startsWith("\"")) {
QString searchTerm = label;
searchTerm.remove(0, 1);
if (label.endsWith("\"")) {
searchTerm.chop(1);
}
- QList<QString> items;
items.append(searchTerm);
- for (int i = 0; i < root_->childCount(); ++i) {
- SessionTreeItem* item = root_->child(i);
- if (item->session() != NULL && item->session()->containsKeywords(items)) {
- result.append(const_cast<Session*>(item->session()));
- }
- }
} else {
- QList<QString> items = label.split(" ", QString::SkipEmptyParts);
- for (int i = 0; i < root_->childCount(); ++i) {
- SessionTreeItem* item = root_->child(i);
- if (item->session() != NULL && item->session()->containsKeywords(items)) {
- result.append(const_cast<Session*>(item->session()));
- }
- }
+ items = label.split(" ", QString::SkipEmptyParts);
}
+ lookDeeper(result, items, root_);
return result;