From bd3673615d92508c71ba4b8e76410532dad9536b Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 3 Nov 2015 14:24:07 +0100 Subject: [PATCH] Saving/loading of expand states is partially working now. --- src/core/feedsmodel.cpp | 16 ++++++++++++---- src/core/rootitem.cpp | 1 + src/core/rootitem.h | 9 +++++---- src/gui/feedsview.cpp | 22 ++++++++++++---------- src/services/abstract/serviceroot.cpp | 1 + 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 837e6a02c..faa773715 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -578,13 +578,21 @@ QList FeedsModel::feedsForItem(RootItem *root) { } QList FeedsModel::categoriesForItem(RootItem *root) { - QList children = root->getRecursiveChildren(); QList categories; + QList parents; - foreach (RootItem *child, children) { - if (child->kind() == RootItemKind::Category) { - categories.append(child->toCategory()); + parents.append(root); + + while (!parents.isEmpty()) { + RootItem *item = parents.takeFirst(); + + if (item->kind() == RootItemKind::Category) { + // This item is category, add it to the output list and + // scan its children. + categories.append( item->toCategory()); } + + parents.append(item->childItems()); } return categories; diff --git a/src/core/rootitem.cpp b/src/core/rootitem.cpp index 62f7cf587..b06e00271 100755 --- a/src/core/rootitem.cpp +++ b/src/core/rootitem.cpp @@ -91,6 +91,7 @@ QList RootItem::getRecursiveChildren() { // Iterate all nested categories. while (!traversable_items.isEmpty()) { RootItem *active_item = traversable_items.takeFirst(); + children.append(active_item); foreach (RootItem *child, active_item->childItems()) { if (child->childCount() == 0) { diff --git a/src/core/rootitem.h b/src/core/rootitem.h index 812528ed9..b36cf12c5 100755 --- a/src/core/rootitem.h +++ b/src/core/rootitem.h @@ -28,10 +28,11 @@ class Feed; namespace RootItemKind { // Describes the kind of the item. enum Kind { - Root = 1001, - Bin = 1002, - Feed = 1003, - Category = 1004 + Root = 1001, + Bin = 1002, + Feed = 1003, + Category = 1004, + ServiceRoot = 1005 }; } diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 7beb4f10e..21dc93101 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -109,27 +109,29 @@ Feed *FeedsView::selectedFeed() const { void FeedsView::saveExpandedStates() { Settings *settings = qApp->settings(); - // TODO: doědlat - // Iterate all categories and save their expand statuses. -/* - foreach (Category *category, sourceModel()->allCategories().values()) { + foreach (Category *category, sourceModel()->allCategories()) { + QString setting_name = QString::number(qHash(category->title())) + QL1S("-") + QString::number(category->id()); + settings->setValue(GROUP(Categories), - QString::number(category->id()), + setting_name, isExpanded(model()->mapFromSource(sourceModel()->indexForItem(category)))); - }*/ + } } void FeedsView::loadExpandedStates() { Settings *settings = qApp->settings(); - // TODO: doědlat + // TODO: nastavit všechny service rooty automaticky na expanded + // toto obnáší vytvoření metody sourceModel()->serviceRoots() // Iterate all categories and save their expand statuses. - /*foreach (Category *category, sourceModel()->allCategories().values()) { + foreach (Category *category, sourceModel()->allCategories()) { + QString setting_name = QString::number(qHash(category->title())) + QL1S("-") + QString::number(category->id()); + setExpanded(model()->mapFromSource(sourceModel()->indexForItem(category)), - settings->value(GROUP(Categories), QString::number(category->id()), true).toBool()); - }*/ + settings->value(GROUP(Categories), setting_name, true).toBool()); + } } void FeedsView::invalidateReadFeedsFilter(bool set_new_value, bool show_unread_only) { diff --git a/src/services/abstract/serviceroot.cpp b/src/services/abstract/serviceroot.cpp index 5a455e306..ebd5f21d3 100755 --- a/src/services/abstract/serviceroot.cpp +++ b/src/services/abstract/serviceroot.cpp @@ -21,6 +21,7 @@ ServiceRoot::ServiceRoot(FeedsModel *feeds_model, RootItem *parent) : RootItem(parent), m_feedsModel(feeds_model) { + m_kind = RootItemKind::ServiceRoot; } ServiceRoot::~ServiceRoot() {