From 459f58c57bfa1021783134b11853e8e4140055f3 Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 2 Jun 2013 00:43:09 +0200 Subject: Remember expanded Items For the current SortOrder the expanded items are written to the config file and read on startup. --- archivemodel.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'archivemodel.cpp') diff --git a/archivemodel.cpp b/archivemodel.cpp index c317c32..de95328 100644 --- a/archivemodel.cpp +++ b/archivemodel.cpp @@ -57,6 +57,31 @@ QVariant ArchiveModel::data(const QModelIndex &index, int role) const{ return SmTreeModel::data(index, role); } +QStringList ArchiveModel::indexToPath(const QModelIndex &idx) const { + QStringList retval; + SmTreeItem *item = itemAt(idx); + while (item) { + retval << item->data(Name).toString(); + item = item->parent(); + } + std::reverse(retval.begin(), retval.end()); + return retval; +} + +QModelIndexList ArchiveModel::pathToIndex(const QStringList &path) const { + QModelIndexList retval; + QModelIndex parentIdx = QModelIndex(); + for(int i = 0; i < path.count(); ++i){ + QString curItem = path.at(i); + QModelIndex found = find(curItem, Name, parentIdx); + if(found.isValid()){ + retval << found; + parentIdx = found; + } + } + return retval; +} + void ArchiveModel::setOrder(int order) { mOrder = order; SmTreeItem *rootItem = new SmTreeItem(NumFields); -- cgit v1.2.3-70-g09d2