diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 79ed1d64c..837e6a02c 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -231,14 +231,14 @@ bool FeedsModel::removeItem(const QModelIndex &index) { return false; } -void FeedsModel::assignNodeToNewParent(RootItem *item, RootItem *parent) { - // Get index of parent item (parent standard category). - QModelIndex parent_index = indexForItem(parent); +void FeedsModel::assignNodeToNewParent(RootItem *item, RootItem *new_parent) { + QModelIndex parent_index = indexForItem(new_parent); + int new_index_of_item = new_parent->childCount(); - // TODO: todle jde sloučit s metodou reassignNodeToNewParent. + // TODO: sloučit do funkce reassignNodeToNewParent. - beginInsertRows(parent_index, parent->childCount(), parent->childCount()); - parent->appendChild(item); + beginInsertRows(parent_index, new_index_of_item, new_index_of_item); + new_parent->appendChild(item); endInsertRows(); } @@ -246,18 +246,18 @@ void FeedsModel::reassignNodeToNewParent(RootItem *original_node, RootItem *new_ RootItem *original_parent = original_node->parent(); if (original_parent != new_parent) { - // User edited category and set it new parent item, + // User edited item and set it new parent item, // se we need to move the item in the model too. - int original_index_of_feed = original_parent->childItems().indexOf(original_node); - int new_index_of_feed = new_parent->childCount(); + int original_index_of_item = original_parent->childItems().indexOf(original_node); + int new_index_of_item = new_parent->childCount(); // Remove the original item from the model... - beginRemoveRows(indexForItem(original_parent), original_index_of_feed, original_index_of_feed); + beginRemoveRows(indexForItem(original_parent), original_index_of_item, original_index_of_item); original_parent->removeChild(original_node); endRemoveRows(); // ... and insert it under the new parent. - beginInsertRows(indexForItem(new_parent), new_index_of_feed, new_index_of_feed); + beginInsertRows(indexForItem(new_parent), new_index_of_item, new_index_of_item); new_parent->appendChild(original_node); endInsertRows(); } @@ -334,6 +334,10 @@ QList FeedsModel::messagesForFeeds(const QList &feeds) { return messages; } +QList FeedsModel::allCategories() { + return categoriesForItem(m_rootItem); +} + int FeedsModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent) @@ -572,3 +576,16 @@ QList FeedsModel::feedsForItem(RootItem *root) { return feeds; } + +QList FeedsModel::categoriesForItem(RootItem *root) { + QList children = root->getRecursiveChildren(); + QList categories; + + foreach (RootItem *child, children) { + if (child->kind() == RootItemKind::Category) { + categories.append(child->toCategory()); + } + } + + return categories; +} diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index 8bec2362c..3c4c6b23e 100755 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -23,8 +23,6 @@ #include "core/messagesmodel.h" #include "core/rootitem.h" -#include - class Category; class Feed; @@ -64,7 +62,7 @@ class FeedsModel : public QAbstractItemModel { bool removeItem(const QModelIndex &index); // Assigns item to the new parent. - void assignNodeToNewParent(RootItem *item, RootItem *parent); + void assignNodeToNewParent(RootItem *item, RootItem *new_parent); // Checks if new parent node is different from one used by original node. // If it is, then it reassigns original_node to new parent. @@ -82,11 +80,18 @@ class FeedsModel : public QAbstractItemModel { // in "newspaper" mode. QList messagesForFeeds(const QList &feeds); + // Returns list of all categories contained in the model. + QList allCategories(); + + // Get list of categories from tree with particular item + // as root. + QList categoriesForItem(RootItem *root); + // Returns list of all feeds contained in the model. QList allFeeds(); // Get list of feeds from tree with particular item - // as root. If root itself is a feed, then it is returned. + // as root. QList feedsForItem(RootItem *root); // Returns list of ALL CHILD feeds which belong to given parent indexes. diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index d780bcf61..7beb4f10e 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -112,8 +112,8 @@ void FeedsView::saveExpandedStates() { // TODO: doědlat // Iterate all categories and save their expand statuses. - - /*foreach (Category *category, sourceModel()->allCategories().values()) { +/* + foreach (Category *category, sourceModel()->allCategories().values()) { settings->setValue(GROUP(Categories), QString::number(category->id()), isExpanded(model()->mapFromSource(sourceModel()->indexForItem(category))));