From 40472753617845b921cac4ac0f2e5ec650d551ba Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 19 Dec 2013 13:52:53 +0100 Subject: [PATCH] Some changes for feed models. --- src/core/feedsmodel.cpp | 19 ++++++++++--------- src/core/feedsmodel.h | 16 ++++++++-------- src/core/feedsmodelrootitem.cpp | 1 + src/core/feedsmodelstandardcategory.cpp | 16 ++++++++++++++-- src/gui/feedsview.cpp | 2 +- src/gui/messagesview.cpp | 1 - 6 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index daaedcd82..f5e0b82ad 100644 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -58,12 +58,14 @@ FeedsModel::~FeedsModel() { } QVariant FeedsModel::data(const QModelIndex &index, int role) const { - if (!index.isValid()) { + FeedsModelRootItem *item = itemForIndex(index); + + if (item != NULL) { + return item->data(index.column(), role); + } + else { return QVariant(); } - - FeedsModelRootItem *item = static_cast(index.internalPointer()); - return item->data(index.column(), role); } QVariant FeedsModel::headerData(int section, @@ -164,7 +166,7 @@ int FeedsModel::columnCount(const QModelIndex &parent) const { } } -FeedsModelRootItem *FeedsModel::itemForIndex(const QModelIndex &index) { +FeedsModelRootItem *FeedsModel::itemForIndex(const QModelIndex &index) const { if (index.isValid() && index.model() == this) { return static_cast(index.internalPointer()); } @@ -173,7 +175,7 @@ FeedsModelRootItem *FeedsModel::itemForIndex(const QModelIndex &index) { } } -void FeedsModel::changeLayout(QModelIndexList list) { +void FeedsModel::reloadChangedLayout(QModelIndexList list) { while (!list.isEmpty()) { QModelIndex ix = list.takeLast(); @@ -181,21 +183,20 @@ void FeedsModel::changeLayout(QModelIndexList list) { emit dataChanged(index(ix.row(), 0, ix.parent()), index(ix.row(), FDS_MODEL_COUNTS_INDEX, ix.parent())); - if (ix.parent().isValid()) { // Make sure that data of parent are changed too. list.append(ix.parent()); } } +} -/* +void FeedsModel::reloadWholeLayout() { // NOTE: Take a look at docs about this. // I have tested that this is LITTLE slower than code above, // but it is really SIMPLER, so if code above will be buggy, then // we can use this. emit layoutAboutToBeChanged(); emit layoutChanged(); -*/ } void FeedsModel::loadFromDatabase() { diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index f12f117e7..35d98a922 100644 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -45,21 +45,21 @@ class FeedsModel : public QAbstractItemModel { // Returns feeds contained within single index. QList feedsForIndex(const QModelIndex &index); - // Returns feed/category which lies at the specified index or - // null if index is invalid. - FeedsModelRootItem *itemForIndex(const QModelIndex &index); - public slots: + void reloadWholeLayout(); + // Signals that SOME data of this model need // to be reloaded by ALL attached views. - void changeLayout(QModelIndexList list); + void reloadChangedLayout(QModelIndexList list); + + protected: + // Returns feed/category which lies at the specified index or + // null if index is invalid. + FeedsModelRootItem *itemForIndex(const QModelIndex &index) const; - protected: // Loads feed/categories from the database. void loadFromDatabase(); - // TODO: Otestovat metody itemForIndex, feedsForIndex, feedsForIndexes. - // Takes lists of feeds/categories and assembles // them into the tree structure. void assembleCategories(CategoryAssignment categories); diff --git a/src/core/feedsmodelrootitem.cpp b/src/core/feedsmodelrootitem.cpp index 84cbbe957..49323e5f3 100755 --- a/src/core/feedsmodelrootitem.cpp +++ b/src/core/feedsmodelrootitem.cpp @@ -1,5 +1,6 @@ #include +#include "qtsingleapplication/qtsingleapplication.h" #include "core/feedsmodelrootitem.h" diff --git a/src/core/feedsmodelstandardcategory.cpp b/src/core/feedsmodelstandardcategory.cpp index 7e448f60b..ad605338d 100755 --- a/src/core/feedsmodelstandardcategory.cpp +++ b/src/core/feedsmodelstandardcategory.cpp @@ -21,8 +21,11 @@ QVariant FeedsModelStandardCategory::data(int column, int role) const { if (column == FDS_MODEL_TITLE_INDEX) { return QObject::tr("%1\n\n" "Category type: standard\n" - "Creation date: %2").arg(m_title, - m_creationDate.toString(Qt::DefaultLocaleShortDate)); + "Creation date: %2%3").arg(m_title, + m_creationDate.toString(Qt::DefaultLocaleShortDate), + m_childItems.size() == 0 ? + QObject::tr("\n\nThis category does not contain any nested items.") : + ""); } else if (column == FDS_MODEL_COUNTS_INDEX) { return QObject::tr("%n unread message(s).", "", countOfUnreadMessages()); @@ -42,6 +45,15 @@ QVariant FeedsModelStandardCategory::data(int column, int role) const { return QVariant(); } + case Qt::ForegroundRole: + if (m_childItems.size() == 0) { + // TODO: Make this configurable. + return QColor(Qt::red); + } + else { + return QVariant(); + } + case Qt::DisplayRole: if (column == FDS_MODEL_TITLE_INDEX) { return QString("%1%2").arg(m_title, "-C"); diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index f53c380b6..c0fc823ac 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -34,7 +34,7 @@ void FeedsView::updateCountsOfSelectedFeeds() { feed->updateCounts(); } - m_sourceModel->changeLayout(mapped_rows); + m_sourceModel->reloadChangedLayout(mapped_rows); } void FeedsView::setupAppearance() { diff --git a/src/gui/messagesview.cpp b/src/gui/messagesview.cpp index 0697cf295..948c060bd 100644 --- a/src/gui/messagesview.cpp +++ b/src/gui/messagesview.cpp @@ -188,7 +188,6 @@ void MessagesView::loadFeeds(const QList &feed_ids) { } void MessagesView::openSelectedSourceArticlesExternally() { - QString browser = Settings::getInstance()->value(APP_CFG_MESSAGES, "external_browser_executable").toString(); QString arguments = Settings::getInstance()->value(APP_CFG_MESSAGES,