Saving/loading of expand states is partially working now.

This commit is contained in:
Martin Rotter 2015-11-03 14:24:07 +01:00
parent dad3cc8555
commit bd3673615d
5 changed files with 31 additions and 18 deletions

View file

@ -578,13 +578,21 @@ QList<Feed*> FeedsModel::feedsForItem(RootItem *root) {
}
QList<Category*> FeedsModel::categoriesForItem(RootItem *root) {
QList<RootItem*> children = root->getRecursiveChildren();
QList<Category*> categories;
QList<RootItem*> 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;

View file

@ -91,6 +91,7 @@ QList<RootItem*> 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) {

View file

@ -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
};
}

View file

@ -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) {

View file

@ -21,6 +21,7 @@
ServiceRoot::ServiceRoot(FeedsModel *feeds_model, RootItem *parent) : RootItem(parent), m_feedsModel(feeds_model) {
m_kind = RootItemKind::ServiceRoot;
}
ServiceRoot::~ServiceRoot() {