Simplified proxy sorting for feeds.
This commit is contained in:
parent
d1814c8d10
commit
29a10dd6a1
8
src/core/feedsmodelcategory.cpp
Normal file → Executable file
8
src/core/feedsmodelcategory.cpp
Normal file → Executable file
@ -36,14 +36,6 @@ void FeedsModelCategory::setType(const 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 {
|
||||
return m_description;
|
||||
}
|
||||
|
4
src/core/feedsmodelcategory.h
Normal file → Executable file
4
src/core/feedsmodelcategory.h
Normal file → Executable file
@ -33,9 +33,6 @@ class FeedsModelCategory : public FeedsModelRootItem {
|
||||
Type type() const;
|
||||
void setType(const Type &type);
|
||||
|
||||
QString title() const;
|
||||
void setTitle(const QString &title);
|
||||
|
||||
QString description() const;
|
||||
void setDescription(const QString &description);
|
||||
|
||||
@ -44,7 +41,6 @@ class FeedsModelCategory : public FeedsModelRootItem {
|
||||
|
||||
protected:
|
||||
Type m_type;
|
||||
QString m_title;
|
||||
QDateTime m_creationDate;
|
||||
QString m_description;
|
||||
};
|
||||
|
8
src/core/feedsmodelfeed.cpp
Normal file → Executable file
8
src/core/feedsmodelfeed.cpp
Normal file → Executable file
@ -33,11 +33,3 @@ FeedsModelFeed::Type FeedsModelFeed::type() const {
|
||||
void FeedsModelFeed::setType(const 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
4
src/core/feedsmodelfeed.h
Normal file → Executable file
@ -33,12 +33,8 @@ class FeedsModelFeed : public FeedsModelRootItem {
|
||||
Type type() const;
|
||||
void setType(const Type &type);
|
||||
|
||||
QString title() const;
|
||||
void setTitle(const QString &title);
|
||||
|
||||
protected:
|
||||
Type m_type;
|
||||
QString m_title;
|
||||
int m_totalCount;
|
||||
int m_unreadCount;
|
||||
};
|
||||
|
15
src/core/feedsmodelrootitem.cpp
Normal file → Executable file
15
src/core/feedsmodelrootitem.cpp
Normal file → Executable file
@ -4,7 +4,7 @@
|
||||
|
||||
|
||||
FeedsModelRootItem::FeedsModelRootItem(FeedsModelRootItem *parent_item)
|
||||
: m_parentItem(parent_item) {
|
||||
: m_kind(FeedsModelRootItem::RootItem), m_parentItem(parent_item) {
|
||||
}
|
||||
|
||||
FeedsModelRootItem::~FeedsModelRootItem() {
|
||||
@ -23,6 +23,10 @@ void FeedsModelRootItem::setParent(FeedsModelRootItem *parent_item) {
|
||||
void FeedsModelRootItem::update() {
|
||||
}
|
||||
|
||||
FeedsModelRootItem::Kind FeedsModelRootItem::kind() const {
|
||||
return m_kind;
|
||||
}
|
||||
|
||||
FeedsModelRootItem *FeedsModelRootItem::child(int row) {
|
||||
return m_childItems.value(row);
|
||||
}
|
||||
@ -75,3 +79,12 @@ int FeedsModelRootItem::id() const {
|
||||
void FeedsModelRootItem::setId(int 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
13
src/core/feedsmodelrootitem.h
Normal file → Executable file
@ -11,6 +11,12 @@ class FeedsModelRootItem {
|
||||
friend class FeedsModel;
|
||||
|
||||
public:
|
||||
enum Kind {
|
||||
RootItem,
|
||||
Feed,
|
||||
Category
|
||||
};
|
||||
|
||||
// Constructors and destructors.
|
||||
explicit FeedsModelRootItem(FeedsModelRootItem *parent_item = NULL);
|
||||
virtual ~FeedsModelRootItem();
|
||||
@ -32,6 +38,8 @@ class FeedsModelRootItem {
|
||||
// Each item can be "updated".
|
||||
virtual void update();
|
||||
|
||||
virtual Kind kind() const;
|
||||
|
||||
// Each item has icon.
|
||||
void setIcon(const QIcon &icon);
|
||||
|
||||
@ -39,7 +47,12 @@ class FeedsModelRootItem {
|
||||
int id() const;
|
||||
void setId(int id);
|
||||
|
||||
QString title() const;
|
||||
void setTitle(const QString &title);
|
||||
|
||||
protected:
|
||||
Kind m_kind;
|
||||
QString m_title;
|
||||
int m_id;
|
||||
QIcon m_icon;
|
||||
QList<FeedsModelRootItem*> m_childItems;
|
||||
|
1
src/core/feedsmodelstandardcategory.cpp
Normal file → Executable file
1
src/core/feedsmodelstandardcategory.cpp
Normal file → Executable file
@ -8,6 +8,7 @@
|
||||
|
||||
FeedsModelStandardCategory::FeedsModelStandardCategory(FeedsModelRootItem *parent_item)
|
||||
: FeedsModelCategory(parent_item) {
|
||||
m_kind = FeedsModelRootItem::Category;
|
||||
m_type = Standard;
|
||||
}
|
||||
|
||||
|
1
src/core/feedsmodelstandardfeed.cpp
Normal file → Executable file
1
src/core/feedsmodelstandardfeed.cpp
Normal file → Executable file
@ -8,6 +8,7 @@
|
||||
|
||||
FeedsModelStandardFeed::FeedsModelStandardFeed(FeedsModelRootItem *parent_item)
|
||||
: FeedsModelFeed(parent_item) {
|
||||
m_kind = FeedsModelRootItem::Category;
|
||||
}
|
||||
|
||||
FeedsModelStandardFeed::~FeedsModelStandardFeed() {
|
||||
|
31
src/core/feedsproxymodel.cpp
Normal file → Executable file
31
src/core/feedsproxymodel.cpp
Normal file → Executable file
@ -9,13 +9,11 @@ FeedsProxyModel::FeedsProxyModel(QObject *parent)
|
||||
: QSortFilterProxyModel(parent) {
|
||||
m_sourceModel = new FeedsModel(this);
|
||||
|
||||
|
||||
|
||||
setObjectName("FeedsProxyModel");
|
||||
setSortRole(Qt::EditRole);
|
||||
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
setFilterKeyColumn(-1);
|
||||
setFilterKeyColumn(0);
|
||||
setFilterRole(Qt::EditRole);
|
||||
setDynamicSortFilter(true);
|
||||
setSourceModel(m_sourceModel);
|
||||
@ -32,34 +30,27 @@ FeedsModel *FeedsProxyModel::sourceModel() {
|
||||
bool FeedsProxyModel::lessThan(const QModelIndex &left,
|
||||
const QModelIndex &right) const {
|
||||
if (left.isValid() && right.isValid()) {
|
||||
// Make necessary castings.
|
||||
FeedsModelRootItem *left_item = static_cast<FeedsModelRootItem*>(left.internalPointer());
|
||||
FeedsModelRootItem *right_item = static_cast<FeedsModelRootItem*>(right.internalPointer());
|
||||
|
||||
FeedsModelFeed *left_feed = dynamic_cast<FeedsModelFeed*>(left_item);
|
||||
FeedsModelFeed *right_feed = dynamic_cast<FeedsModelFeed*>(right_item);
|
||||
// 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.
|
||||
|
||||
FeedsModelCategory *left_category = dynamic_cast<FeedsModelCategory*>(left_item);
|
||||
FeedsModelCategory *right_category = dynamic_cast<FeedsModelCategory*>(right_item);
|
||||
|
||||
if (left_feed != NULL && right_feed != NULL) {
|
||||
// Both items are feeds.
|
||||
return left_feed->title() < right_feed->title();
|
||||
if (left_item->kind() == right_item->kind()) {
|
||||
// Both items are feeds or both items are categories.
|
||||
return left_item->title() < right_item->title();
|
||||
}
|
||||
else if (left_category != NULL && right_category != NULL) {
|
||||
// Both items are categories.
|
||||
return left_category->title() < right_category->title();
|
||||
}
|
||||
else if (left_feed != NULL) {
|
||||
else if (left_item->kind() == FeedsModelRootItem::Feed) {
|
||||
// Left item is feed, right item is category.
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// Left item is category, right item is feed.
|
||||
// Left item is category, right item is feed.*/
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
|
1
src/core/feedsproxymodel.h
Normal file → Executable file
1
src/core/feedsproxymodel.h
Normal file → Executable file
@ -14,6 +14,7 @@ class FeedsProxyModel : public QSortFilterProxyModel {
|
||||
explicit FeedsProxyModel(QObject *parent = 0);
|
||||
virtual ~FeedsProxyModel();
|
||||
|
||||
// Access to the source model.
|
||||
FeedsModel *sourceModel();
|
||||
|
||||
protected:
|
||||
|
@ -184,6 +184,7 @@ void FormMain::setupIcons() {
|
||||
m_ui->m_actionDeleteSelectedFeeds->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_actionEditSelectedFeed->setIcon(IconThemeFactory::getInstance()->fromTheme("document-properties"));
|
||||
m_ui->m_actionMarkAllMessagesAsRead->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-read"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user