From 56d213b3c8984ef033784e60fccf25d3cfbdbb13 Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Fri, 7 Mar 2014 16:23:16 +0100 Subject: Added function to add info entries if the xml file could not be loaded --- src/sessiontreemodel.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/sessiontreemodel.cpp') diff --git a/src/sessiontreemodel.cpp b/src/sessiontreemodel.cpp index 12eebf5..d63bab5 100644 --- a/src/sessiontreemodel.cpp +++ b/src/sessiontreemodel.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "sessiontreeitem.h" @@ -160,3 +161,49 @@ void SessionTreeModel::addItems(const QList& sessions, parentItem->appendChild(new SessionTreeItem(s, parentItem)); } } + +void SessionTreeModel::addLabelItem(const QString& label, const QString& section) { + SessionTreeItem* parentItem; + + bool sectionExists = false; + + 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(label, parentItem)); +} + +void SessionTreeModel::removeItem(const QString& name, const QString& section) { + SessionTreeItem* parentItem; + + bool sectionExists = false; + + for (int i = 0; i < root_->childCount(); ++i) { + SessionTreeItem* item = root_->child(i); + if (item->text() == section) { + parentItem = item; + sectionExists = true; + break; + } + } + + if (sectionExists) { + for (int i = 0; i < parentItem->childCount(); ++i) { + SessionTreeItem* item = parentItem->child(i); + if (item->text() == name) { + parentItem->removeChild(item); + } + } + } +} -- cgit v1.2.3-55-g7522