From 4f6cf19e3f0847d6b34a518999ae16a800045040 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 19 Dec 2013 11:35:17 +0100 Subject: [PATCH] Feeds/categories can be sorted by "item" counts/alphabetically + sorting is dynamic for feeds/categories. --- src/core/feedsmodelstandardcategory.cpp | 11 +++++++++++ src/core/feedsmodelstandardfeed.cpp | 14 ++++++++++++++ src/core/feedsproxymodel.cpp | 13 +++++++++++-- src/core/messagesmodel.cpp | 4 ---- src/core/messagesmodel.h | 1 - src/gui/messagesview.h | 3 +++ 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/core/feedsmodelstandardcategory.cpp b/src/core/feedsmodelstandardcategory.cpp index dbf026d89..7e448f60b 100755 --- a/src/core/feedsmodelstandardcategory.cpp +++ b/src/core/feedsmodelstandardcategory.cpp @@ -31,6 +31,17 @@ QVariant FeedsModelStandardCategory::data(int column, int role) const { return QVariant(); } + case Qt::EditRole: + if (column == FDS_MODEL_TITLE_INDEX) { + return m_title; + } + else if (column == FDS_MODEL_COUNTS_INDEX) { + return countOfUnreadMessages(); + } + else { + return QVariant(); + } + case Qt::DisplayRole: if (column == FDS_MODEL_TITLE_INDEX) { return QString("%1%2").arg(m_title, "-C"); diff --git a/src/core/feedsmodelstandardfeed.cpp b/src/core/feedsmodelstandardfeed.cpp index 3d3f8c5fb..5cd44cf45 100755 --- a/src/core/feedsmodelstandardfeed.cpp +++ b/src/core/feedsmodelstandardfeed.cpp @@ -80,6 +80,20 @@ QVariant FeedsModelStandardFeed::data(int column, int role) const { else if (column == FDS_MODEL_COUNTS_INDEX) { return QString("(%1)").arg(QString::number(countOfUnreadMessages())); } + else { + return QVariant(); + } + + case Qt::EditRole: + if (column == FDS_MODEL_TITLE_INDEX) { + return m_title; + } + else if (column == FDS_MODEL_COUNTS_INDEX) { + return countOfUnreadMessages(); + } + else { + return QVariant(); + } case Qt::DecorationRole: return column == FDS_MODEL_TITLE_INDEX ? diff --git a/src/core/feedsproxymodel.cpp b/src/core/feedsproxymodel.cpp index 3027479dd..8dcac04e8 100755 --- a/src/core/feedsproxymodel.cpp +++ b/src/core/feedsproxymodel.cpp @@ -3,6 +3,7 @@ #include "core/feedsmodelcategory.h" #include "core/feedsmodelfeed.h" #include "core/feedsmodelrootitem.h" +#include "core/defs.h" FeedsProxyModel::FeedsProxyModel(QObject *parent) @@ -37,11 +38,19 @@ bool FeedsProxyModel::lessThan(const QModelIndex &left, // NOTE: Here we want to accomplish that ALL // categories are queued one after another and all // feeds are queued one after another too. - // Moreover, sort everything alphabetically. + // Moreover, sort everything alphabetically or + // by item counts, depending on the sort column. if (left_item->kind() == right_item->kind()) { // Both items are feeds or both items are categories. - return left_item->title() < right_item->title(); + if (left.column() == FDS_MODEL_COUNTS_INDEX) { + // User wants to sort according to counts. + return left_item->countOfUnreadMessages() < right_item->countOfUnreadMessages(); + } + else { + // In other cases, sort by title. + return left_item->title() < right_item->title(); + } } else if (left_item->kind() == FeedsModelRootItem::Feed) { // Left item is feed, right item is category. diff --git a/src/core/messagesmodel.cpp b/src/core/messagesmodel.cpp index 55a9408b9..b8d304864 100644 --- a/src/core/messagesmodel.cpp +++ b/src/core/messagesmodel.cpp @@ -418,10 +418,6 @@ bool MessagesModel::setBatchMessagesRead(const QModelIndexList &messages, int re } } -bool MessagesModel::switchAllMessageImportance() { - return false; -} - bool MessagesModel::setAllMessagesDeleted(int deleted) { QSqlDatabase db_handle = database(); diff --git a/src/core/messagesmodel.h b/src/core/messagesmodel.h index 0a6c8f34f..02ab979d4 100644 --- a/src/core/messagesmodel.h +++ b/src/core/messagesmodel.h @@ -70,7 +70,6 @@ class MessagesModel : public QSqlTableModel { // of many messages via DIRECT SQL calls. // List of loaded feed ids is used for WHERE clause. // Model is reset after one of these methods is applied. - bool switchAllMessageImportance(); bool setAllMessagesDeleted(int deleted); bool setAllMessagesRead(int read); diff --git a/src/gui/messagesview.h b/src/gui/messagesview.h index 22b015a44..b96c0344b 100755 --- a/src/gui/messagesview.h +++ b/src/gui/messagesview.h @@ -30,16 +30,19 @@ class MessagesView : public QTreeView { void openSelectedSourceMessagesInternally(); void openSelectedMessagesInternally(); + // Works with SELECTED messages only. void setSelectedMessagesReadStatus(int read); void markSelectedMessagesRead(); void markSelectedMessagesUnread(); void deleteSelectedMessages(); void switchSelectedMessagesImportance(); + // Sets ALL (unfiltered) messages read. void setAllMessagesReadStatus(int read); void setAllMessagesRead(); void setAllMessagesUnread(); + // Sets ALL (unfiltered) messages deleted. void setAllMessagesDeleteStatus(int deleted); void setAllMessagesDeleted();