Simplified proxy sorting for feeds.

This commit is contained in:
Martin Rotter 2013-12-16 09:11:14 +01:00
parent d1814c8d10
commit 29a10dd6a1
11 changed files with 42 additions and 45 deletions

8
src/core/feedsmodelcategory.cpp Normal file → Executable file
View File

@ -36,14 +36,6 @@ void FeedsModelCategory::setType(const Type &type) {
m_type = type; m_type = type;
} }
QString FeedsModelCategory::title() const {
return m_title;
}
void FeedsModelCategory::setTitle(const QString &title) {
m_title = title;
}
QString FeedsModelCategory::description() const { QString FeedsModelCategory::description() const {
return m_description; return m_description;
} }

4
src/core/feedsmodelcategory.h Normal file → Executable file
View File

@ -33,9 +33,6 @@ class FeedsModelCategory : public FeedsModelRootItem {
Type type() const; Type type() const;
void setType(const Type &type); void setType(const Type &type);
QString title() const;
void setTitle(const QString &title);
QString description() const; QString description() const;
void setDescription(const QString &description); void setDescription(const QString &description);
@ -44,7 +41,6 @@ class FeedsModelCategory : public FeedsModelRootItem {
protected: protected:
Type m_type; Type m_type;
QString m_title;
QDateTime m_creationDate; QDateTime m_creationDate;
QString m_description; QString m_description;
}; };

8
src/core/feedsmodelfeed.cpp Normal file → Executable file
View File

@ -33,11 +33,3 @@ FeedsModelFeed::Type FeedsModelFeed::type() const {
void FeedsModelFeed::setType(const Type &type) { void FeedsModelFeed::setType(const Type &type) {
m_type = type; m_type = type;
} }
void FeedsModelFeed::setTitle(const QString &title) {
m_title = title;
}
QString FeedsModelFeed::title() const {
return m_title;
}

4
src/core/feedsmodelfeed.h Normal file → Executable file
View File

@ -33,12 +33,8 @@ class FeedsModelFeed : public FeedsModelRootItem {
Type type() const; Type type() const;
void setType(const Type &type); void setType(const Type &type);
QString title() const;
void setTitle(const QString &title);
protected: protected:
Type m_type; Type m_type;
QString m_title;
int m_totalCount; int m_totalCount;
int m_unreadCount; int m_unreadCount;
}; };

15
src/core/feedsmodelrootitem.cpp Normal file → Executable file
View File

@ -4,7 +4,7 @@
FeedsModelRootItem::FeedsModelRootItem(FeedsModelRootItem *parent_item) FeedsModelRootItem::FeedsModelRootItem(FeedsModelRootItem *parent_item)
: m_parentItem(parent_item) { : m_kind(FeedsModelRootItem::RootItem), m_parentItem(parent_item) {
} }
FeedsModelRootItem::~FeedsModelRootItem() { FeedsModelRootItem::~FeedsModelRootItem() {
@ -23,6 +23,10 @@ void FeedsModelRootItem::setParent(FeedsModelRootItem *parent_item) {
void FeedsModelRootItem::update() { void FeedsModelRootItem::update() {
} }
FeedsModelRootItem::Kind FeedsModelRootItem::kind() const {
return m_kind;
}
FeedsModelRootItem *FeedsModelRootItem::child(int row) { FeedsModelRootItem *FeedsModelRootItem::child(int row) {
return m_childItems.value(row); return m_childItems.value(row);
} }
@ -75,3 +79,12 @@ int FeedsModelRootItem::id() const {
void FeedsModelRootItem::setId(int id) { void FeedsModelRootItem::setId(int id) {
m_id = id; m_id = id;
} }
QString FeedsModelRootItem::title() const {
return m_title;
}
void FeedsModelRootItem::setTitle(const QString &title) {
m_title = title;
}

13
src/core/feedsmodelrootitem.h Normal file → Executable file
View File

@ -11,6 +11,12 @@ class FeedsModelRootItem {
friend class FeedsModel; friend class FeedsModel;
public: public:
enum Kind {
RootItem,
Feed,
Category
};
// Constructors and destructors. // Constructors and destructors.
explicit FeedsModelRootItem(FeedsModelRootItem *parent_item = NULL); explicit FeedsModelRootItem(FeedsModelRootItem *parent_item = NULL);
virtual ~FeedsModelRootItem(); virtual ~FeedsModelRootItem();
@ -32,6 +38,8 @@ class FeedsModelRootItem {
// Each item can be "updated". // Each item can be "updated".
virtual void update(); virtual void update();
virtual Kind kind() const;
// Each item has icon. // Each item has icon.
void setIcon(const QIcon &icon); void setIcon(const QIcon &icon);
@ -39,7 +47,12 @@ class FeedsModelRootItem {
int id() const; int id() const;
void setId(int id); void setId(int id);
QString title() const;
void setTitle(const QString &title);
protected: protected:
Kind m_kind;
QString m_title;
int m_id; int m_id;
QIcon m_icon; QIcon m_icon;
QList<FeedsModelRootItem*> m_childItems; QList<FeedsModelRootItem*> m_childItems;

1
src/core/feedsmodelstandardcategory.cpp Normal file → Executable file
View File

@ -8,6 +8,7 @@
FeedsModelStandardCategory::FeedsModelStandardCategory(FeedsModelRootItem *parent_item) FeedsModelStandardCategory::FeedsModelStandardCategory(FeedsModelRootItem *parent_item)
: FeedsModelCategory(parent_item) { : FeedsModelCategory(parent_item) {
m_kind = FeedsModelRootItem::Category;
m_type = Standard; m_type = Standard;
} }

1
src/core/feedsmodelstandardfeed.cpp Normal file → Executable file
View File

@ -8,6 +8,7 @@
FeedsModelStandardFeed::FeedsModelStandardFeed(FeedsModelRootItem *parent_item) FeedsModelStandardFeed::FeedsModelStandardFeed(FeedsModelRootItem *parent_item)
: FeedsModelFeed(parent_item) { : FeedsModelFeed(parent_item) {
m_kind = FeedsModelRootItem::Category;
} }
FeedsModelStandardFeed::~FeedsModelStandardFeed() { FeedsModelStandardFeed::~FeedsModelStandardFeed() {

31
src/core/feedsproxymodel.cpp Normal file → Executable file
View File

@ -9,13 +9,11 @@ FeedsProxyModel::FeedsProxyModel(QObject *parent)
: QSortFilterProxyModel(parent) { : QSortFilterProxyModel(parent) {
m_sourceModel = new FeedsModel(this); m_sourceModel = new FeedsModel(this);
setObjectName("FeedsProxyModel"); setObjectName("FeedsProxyModel");
setSortRole(Qt::EditRole); setSortRole(Qt::EditRole);
setSortCaseSensitivity(Qt::CaseInsensitive); setSortCaseSensitivity(Qt::CaseInsensitive);
setFilterCaseSensitivity(Qt::CaseInsensitive); setFilterCaseSensitivity(Qt::CaseInsensitive);
setFilterKeyColumn(-1); setFilterKeyColumn(0);
setFilterRole(Qt::EditRole); setFilterRole(Qt::EditRole);
setDynamicSortFilter(true); setDynamicSortFilter(true);
setSourceModel(m_sourceModel); setSourceModel(m_sourceModel);
@ -32,34 +30,27 @@ FeedsModel *FeedsProxyModel::sourceModel() {
bool FeedsProxyModel::lessThan(const QModelIndex &left, bool FeedsProxyModel::lessThan(const QModelIndex &left,
const QModelIndex &right) const { const QModelIndex &right) const {
if (left.isValid() && right.isValid()) { if (left.isValid() && right.isValid()) {
// Make necessary castings.
FeedsModelRootItem *left_item = static_cast<FeedsModelRootItem*>(left.internalPointer()); FeedsModelRootItem *left_item = static_cast<FeedsModelRootItem*>(left.internalPointer());
FeedsModelRootItem *right_item = static_cast<FeedsModelRootItem*>(right.internalPointer()); FeedsModelRootItem *right_item = static_cast<FeedsModelRootItem*>(right.internalPointer());
FeedsModelFeed *left_feed = dynamic_cast<FeedsModelFeed*>(left_item); // NOTE: Here we want to accomplish that ALL
FeedsModelFeed *right_feed = dynamic_cast<FeedsModelFeed*>(right_item); // categories are queued one after another and all
// feeds are queued one after another too.
// Moreover, sort everything alphabetically.
FeedsModelCategory *left_category = dynamic_cast<FeedsModelCategory*>(left_item); if (left_item->kind() == right_item->kind()) {
FeedsModelCategory *right_category = dynamic_cast<FeedsModelCategory*>(right_item); // Both items are feeds or both items are categories.
return left_item->title() < right_item->title();
if (left_feed != NULL && right_feed != NULL) {
// Both items are feeds.
return left_feed->title() < right_feed->title();
} }
else if (left_category != NULL && right_category != NULL) { else if (left_item->kind() == FeedsModelRootItem::Feed) {
// Both items are categories.
return left_category->title() < right_category->title();
}
else if (left_feed != NULL) {
// Left item is feed, right item is category. // Left item is feed, right item is category.
return false; return false;
} }
else { else {
// Left item is category, right item is feed. // Left item is category, right item is feed.*/
return true; return true;
} }
return true;
} }
else { else {
return false; return false;

1
src/core/feedsproxymodel.h Normal file → Executable file
View File

@ -14,6 +14,7 @@ class FeedsProxyModel : public QSortFilterProxyModel {
explicit FeedsProxyModel(QObject *parent = 0); explicit FeedsProxyModel(QObject *parent = 0);
virtual ~FeedsProxyModel(); virtual ~FeedsProxyModel();
// Access to the source model.
FeedsModel *sourceModel(); FeedsModel *sourceModel();
protected: protected:

View File

@ -184,6 +184,7 @@ void FormMain::setupIcons() {
m_ui->m_actionDeleteSelectedFeeds->setIcon(IconThemeFactory::getInstance()->fromTheme("edit-delete")); m_ui->m_actionDeleteSelectedFeeds->setIcon(IconThemeFactory::getInstance()->fromTheme("edit-delete"));
m_ui->m_actionDeleteSelectedMessages->setIcon(IconThemeFactory::getInstance()->fromTheme("edit-delete")); m_ui->m_actionDeleteSelectedMessages->setIcon(IconThemeFactory::getInstance()->fromTheme("edit-delete"));
m_ui->m_actionAddNewCategory->setIcon(IconThemeFactory::getInstance()->fromTheme("document-new"));
m_ui->m_actionAddNewFeed->setIcon(IconThemeFactory::getInstance()->fromTheme("document-new")); m_ui->m_actionAddNewFeed->setIcon(IconThemeFactory::getInstance()->fromTheme("document-new"));
m_ui->m_actionEditSelectedFeed->setIcon(IconThemeFactory::getInstance()->fromTheme("document-properties")); m_ui->m_actionEditSelectedFeed->setIcon(IconThemeFactory::getInstance()->fromTheme("document-properties"));
m_ui->m_actionMarkAllMessagesAsRead->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-read")); m_ui->m_actionMarkAllMessagesAsRead->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-read"));