From 421336bf5b086ffd6c9677b036ae0280c7c2b077 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 16 Dec 2013 10:22:23 +0100 Subject: [PATCH] Work on feeed model. --- src/core/feedsmodel.cpp | 4 ++-- src/core/feedsmodelrootitem.cpp | 6 ++++++ src/core/feedsmodelrootitem.h | 13 ++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 5965c85cd..77db96424 100644 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -169,7 +169,7 @@ FeedsModelRootItem *FeedsModel::itemForIndex(const QModelIndex &index) { } void FeedsModel::loadFromDatabase() { - qDeleteAll(m_rootItem->m_childItems); + qDeleteAll(m_rootItem->childItems()); QSqlDatabase database = DatabaseFactory::getInstance()->addConnection(objectName()); CategoryAssignment categories; @@ -241,7 +241,7 @@ void FeedsModel::loadFromDatabase() { QHash FeedsModel::getCategories(FeedsModelRootItem *root) { QHash categories; - foreach (FeedsModelRootItem *child, root->m_childItems) { + foreach (FeedsModelRootItem *child, root->childItems()) { FeedsModelCategory *converted = dynamic_cast(child); if (converted != NULL) { diff --git a/src/core/feedsmodelrootitem.cpp b/src/core/feedsmodelrootitem.cpp index 2eaffd6e0..1513f0d43 100755 --- a/src/core/feedsmodelrootitem.cpp +++ b/src/core/feedsmodelrootitem.cpp @@ -37,6 +37,7 @@ void FeedsModelRootItem::appendChild(FeedsModelRootItem *child) { } int FeedsModelRootItem::columnCount() const { + // FeedsModel offers exactly two columns. return 2; } @@ -45,6 +46,7 @@ int FeedsModelRootItem::row() const { return m_parentItem->m_childItems.indexOf(const_cast(this)); } else { + // This item has no parent. Therefore, its row index is 0. return 0; } } @@ -57,6 +59,7 @@ QVariant FeedsModelRootItem::data(int column, int role) const { Q_UNUSED(column) Q_UNUSED(role) + // Do not return anything for the root item. return QVariant(); } @@ -88,3 +91,6 @@ void FeedsModelRootItem::setTitle(const QString &title) { m_title = title; } +QList FeedsModelRootItem::childItems() const { + return m_childItems; +} diff --git a/src/core/feedsmodelrootitem.h b/src/core/feedsmodelrootitem.h index 016e6b669..4781ea1c5 100755 --- a/src/core/feedsmodelrootitem.h +++ b/src/core/feedsmodelrootitem.h @@ -8,9 +8,8 @@ // NOTE: This class is derived to add functionality for // all other non-root items of FeedsModel. class FeedsModelRootItem { - friend class FeedsModel; - public: + // Describes the kind of the item. enum Kind { RootItem, Feed, @@ -22,8 +21,8 @@ class FeedsModelRootItem { virtual ~FeedsModelRootItem(); // Basic operations. - virtual void setParent(FeedsModelRootItem *parent_item); virtual FeedsModelRootItem *parent(); + virtual void setParent(FeedsModelRootItem *parent_item); virtual FeedsModelRootItem *child(int row); virtual void appendChild(FeedsModelRootItem *child); virtual int childCount() const; @@ -36,6 +35,9 @@ class FeedsModelRootItem { virtual int countOfAllMessages() const; // Each item can be "updated". + // NOTE: This method is used in the "update worker". + // For example, it can fetch new messages from a remote destination + // and store them in a local database and so on. virtual void update(); virtual Kind kind() const; @@ -47,9 +49,14 @@ class FeedsModelRootItem { int id() const; void setId(int id); + // Each item has its title. + // NOTE: This is note entirely true for the root item. QString title() const; void setTitle(const QString &title); + // Acess to children. + QList childItems() const; + protected: Kind m_kind; QString m_title;