From 6ec00ab841bed9ecb856f3ba2f174144fb5aeddb Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 12 Dec 2013 22:28:51 +0100 Subject: [PATCH] Work on feeds. --- CMakeLists.txt | 2 +- src/core/feedsmodel.cpp | 11 +++++++-- src/core/feedsmodel.h | 1 + src/core/feedsmodelcategory.cpp | 20 +++++++++++++++++ src/core/feedsmodelcategory.h | 3 +++ src/core/feedsmodelfeed.cpp | 10 ++++++++- src/core/feedsmodelfeed.h | 9 ++++++-- src/core/feedsmodelrootitem.cpp | 8 +++++++ src/core/feedsmodelrootitem.h | 3 +++ src/core/feedsmodelstandardcategory.cpp | 30 ++++++++++++++++++++----- src/core/feedsmodelstandardcategory.h | 1 - src/core/feedsmodelstandardfeed.cpp | 12 ++++++++-- src/core/feedsmodelstandardfeed.h | 5 ++--- src/gui/feedsview.cpp | 6 ++--- src/gui/formmain.cpp | 1 + 15 files changed, 102 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b1cd88fa..54bf069c0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,7 +132,7 @@ message(STATUS "[${APP_LOW_NAME}] Enabling verbose makefile and full warning rep if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) add_definitions(-pedantic -Wall -Wextra) elseif(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)") - add_definitions(/W2) + #add_definitions(/W3) endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) # Verbose compiling ouputs. diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 78b950ee9..bbb206023 100644 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -10,6 +10,8 @@ FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) { m_countsIcon = IconThemeFactory::getInstance()->fromTheme("mail-mark-unread"); m_headerData << tr("Title"); + m_tooltipData << tr("Titles of feeds/categories.") << + tr("Counts of unread/all meesages."); FeedsModelStandardCategory *cat1 = new FeedsModelStandardCategory(); FeedsModelStandardCategory *cat2 = new FeedsModelStandardCategory(); @@ -19,6 +21,12 @@ FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) { FeedsModelStandardFeed *feed4 = new FeedsModelStandardFeed(); FeedsModelStandardFeed *feed5 = new FeedsModelStandardFeed(); + feed1->setTitle("aaa"); + feed2->setTitle("aaa"); + feed3->setTitle("aaa"); + feed4->setTitle("aaa"); + feed5->setTitle("aaa"); + cat1->appendChild(feed1); cat1->appendChild(feed2); cat1->appendChild(cat2); @@ -61,7 +69,7 @@ QVariant FeedsModel::headerData(int section, } case Qt::ToolTipRole: - break; + return m_tooltipData.at(section); case Qt::DecorationRole: if (section == FDS_COUNTS_INDEX) { @@ -74,7 +82,6 @@ QVariant FeedsModel::headerData(int section, default: return QVariant(); } - } QModelIndex FeedsModel::index(int row, int column, const QModelIndex &parent) const { diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index 940ed7c87..cf92ac4b0 100644 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -27,6 +27,7 @@ class FeedsModel : public QAbstractItemModel { private: FeedsModelRootItem *m_rootItem; QList m_headerData; + QList m_tooltipData; QIcon m_countsIcon; }; diff --git a/src/core/feedsmodelcategory.cpp b/src/core/feedsmodelcategory.cpp index 6d781f49c..78adecf29 100644 --- a/src/core/feedsmodelcategory.cpp +++ b/src/core/feedsmodelcategory.cpp @@ -7,3 +7,23 @@ FeedsModelCategory::FeedsModelCategory(FeedsModelRootItem *parent_item) FeedsModelCategory::~FeedsModelCategory() { } + +int FeedsModelCategory::countOfAllMessages() const { + int total_count = 0; + + foreach (FeedsModelRootItem *child_item, m_childItems) { + total_count += child_item->countOfAllMessages(); + } + + return total_count; +} + +int FeedsModelCategory::countOfUnreadMessages() const { + int total_count = 0; + + foreach (FeedsModelRootItem *child_item, m_childItems) { + total_count += child_item->countOfUnreadMessages(); + } + + return total_count; +} diff --git a/src/core/feedsmodelcategory.h b/src/core/feedsmodelcategory.h index e6f3ce4df..5ef38c3a6 100644 --- a/src/core/feedsmodelcategory.h +++ b/src/core/feedsmodelcategory.h @@ -12,6 +12,9 @@ class FeedsModelCategory : public FeedsModelRootItem { explicit FeedsModelCategory(FeedsModelRootItem *parent_item = NULL); virtual ~FeedsModelCategory(); + int countOfAllMessages() const; + int countOfUnreadMessages() const; + }; #endif // FEEDSMODELCLASSICCATEGORY_H diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp index 0fedffa29..eccf16a24 100644 --- a/src/core/feedsmodelfeed.cpp +++ b/src/core/feedsmodelfeed.cpp @@ -2,7 +2,7 @@ FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item) - : FeedsModelRootItem(parent_item) { + : FeedsModelRootItem(parent_item), m_unreadCount(1), m_totalCount(0) { } FeedsModelFeed::~FeedsModelFeed() { @@ -12,3 +12,11 @@ int FeedsModelFeed::childCount() const { // Because feed has no children. return 0; } + +int FeedsModelFeed::countOfAllMessages() const { + return m_totalCount; +} + +int FeedsModelFeed::countOfUnreadMessages() const { + return m_unreadCount; +} diff --git a/src/core/feedsmodelfeed.h b/src/core/feedsmodelfeed.h index 9b66f8032..f5fd0b0d0 100644 --- a/src/core/feedsmodelfeed.h +++ b/src/core/feedsmodelfeed.h @@ -6,8 +6,7 @@ // Represents BASE class for feeds contained in FeedsModel. // NOTE: This class should be derived to create PARTICULAR feed types. -class FeedsModelFeed : public FeedsModelRootItem -{ +class FeedsModelFeed : public FeedsModelRootItem { public: // Describes possible types of feeds. // NOTE: This is equivalent to attribute Feeds(type). @@ -23,6 +22,12 @@ class FeedsModelFeed : public FeedsModelRootItem int childCount() const; + int countOfUnreadMessages() const; + int countOfAllMessages() const; + + protected: + int m_totalCount; + int m_unreadCount; }; #endif // FEEDSMODELFEED_H diff --git a/src/core/feedsmodelrootitem.cpp b/src/core/feedsmodelrootitem.cpp index 073c0992c..0a3696b10 100644 --- a/src/core/feedsmodelrootitem.cpp +++ b/src/core/feedsmodelrootitem.cpp @@ -52,3 +52,11 @@ QVariant FeedsModelRootItem::data(int column, int role) const { return QVariant(); } + +int FeedsModelRootItem::countOfAllMessages() const { + return 0; +} + +int FeedsModelRootItem::countOfUnreadMessages() const { + return 0; +} diff --git a/src/core/feedsmodelrootitem.h b/src/core/feedsmodelrootitem.h index 86b49b0bd..3c779e6bd 100644 --- a/src/core/feedsmodelrootitem.h +++ b/src/core/feedsmodelrootitem.h @@ -25,6 +25,9 @@ class FeedsModelRootItem { virtual int row() const; virtual QVariant data(int column, int role) const; + virtual int countOfUnreadMessages() const; + virtual int countOfAllMessages() const; + protected: QIcon m_icon; QList m_childItems; diff --git a/src/core/feedsmodelstandardcategory.cpp b/src/core/feedsmodelstandardcategory.cpp index 0f14a8799..6c4c26e1d 100644 --- a/src/core/feedsmodelstandardcategory.cpp +++ b/src/core/feedsmodelstandardcategory.cpp @@ -1,6 +1,7 @@ #include #include "core/feedsmodelstandardcategory.h" +#include "core/defs.h" FeedsModelStandardCategory::FeedsModelStandardCategory(FeedsModelRootItem *parent_item) @@ -12,10 +13,29 @@ FeedsModelStandardCategory::~FeedsModelStandardCategory() { } QVariant FeedsModelStandardCategory::data(int column, int role) const { - if (role == Qt::DisplayRole) { - return "aaa"; - } - else { - return QVariant(); + switch (role) { + case Qt::DisplayRole: + if (column == FDS_TITLE_INDEX) { + return "m_title"; + } + else if (column == FDS_COUNTS_INDEX) { + return QString("(%1)").arg(QString::number(countOfUnreadMessages())); + } + + case Qt::DecorationRole: + return column == FDS_TITLE_INDEX ? + m_icon : + QVariant(); + + case Qt::TextAlignmentRole: + if (column == FDS_COUNTS_INDEX) { + return Qt::AlignCenter; + } + else { + return QVariant(); + } + + default: + return QVariant(); } } diff --git a/src/core/feedsmodelstandardcategory.h b/src/core/feedsmodelstandardcategory.h index 850afb227..d18a1c75a 100644 --- a/src/core/feedsmodelstandardcategory.h +++ b/src/core/feedsmodelstandardcategory.h @@ -16,7 +16,6 @@ class FeedsModelStandardCategory : public FeedsModelCategory { virtual ~FeedsModelStandardCategory(); QVariant data(int column, int role) const; - }; #endif // FEEDSMODELSTANDARDCATEGORY_H diff --git a/src/core/feedsmodelstandardfeed.cpp b/src/core/feedsmodelstandardfeed.cpp index 8f6d31728..e9001a86a 100644 --- a/src/core/feedsmodelstandardfeed.cpp +++ b/src/core/feedsmodelstandardfeed.cpp @@ -13,6 +13,14 @@ FeedsModelStandardFeed::~FeedsModelStandardFeed() { qDebug("Destroying FeedsModelStandardFeed instance."); } +void FeedsModelStandardFeed::setDescription(const QString &description) { + m_description = description; +} + +void FeedsModelStandardFeed::setTitle(const QString &title) { + m_title = title; +} + QVariant FeedsModelStandardFeed::data(int column, int role) const { switch (role) { case Qt::DisplayRole: @@ -20,7 +28,7 @@ QVariant FeedsModelStandardFeed::data(int column, int role) const { return m_title; } else if (column == FDS_COUNTS_INDEX) { - return QString("(%1)").arg(QString::number(m_unreadCount)); + return QString("(%1)").arg(QString::number(countOfUnreadMessages())); } case Qt::DecorationRole: @@ -30,7 +38,7 @@ QVariant FeedsModelStandardFeed::data(int column, int role) const { case Qt::TextAlignmentRole: if (column == FDS_COUNTS_INDEX) { - return Qt::AlignRight; + return Qt::AlignCenter; } else { return QVariant(); diff --git a/src/core/feedsmodelstandardfeed.h b/src/core/feedsmodelstandardfeed.h index 90eee5274..0ff214b12 100644 --- a/src/core/feedsmodelstandardfeed.h +++ b/src/core/feedsmodelstandardfeed.h @@ -17,6 +17,8 @@ class FeedsModelStandardFeed : public FeedsModelFeed { QVariant data(int column, int role) const; + void setTitle(const QString &title); + void setDescription(const QString &description); private: QString m_title; @@ -25,9 +27,6 @@ class FeedsModelStandardFeed : public FeedsModelFeed { QString m_url; QString m_description; QString m_language; - - int m_totalCount; - int m_unreadCount; }; #endif // FEEDSMODELSTANDARDFEED_H diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index fb723b49c..7a3dafdf9 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -14,11 +14,11 @@ FeedsView::FeedsView(QWidget *parent) : QTreeView(parent) { #if QT_VERSION >= 0x050000 // Setup column resize strategies. - header()->setSectionResizeMode(FDS_TITLE_INDEX, QHeaderView::Interactive); + header()->setSectionResizeMode(FDS_TITLE_INDEX, QHeaderView::Stretch); header()->setSectionResizeMode(FDS_COUNTS_INDEX, QHeaderView::ResizeToContents); #else // Setup column resize strategies. - header()->setResizeMode(FDS_TITLE_INDEX, QHeaderView::Interactive); + header()->setResizeMode(FDS_TITLE_INDEX, QHeaderView::Stretch); header()->setResizeMode(FDS_COUNTS_INDEX, QHeaderView::ResizeToContents); #endif @@ -28,7 +28,7 @@ FeedsView::FeedsView(QWidget *parent) : QTreeView(parent) { setDragEnabled(false); setDragDropMode(QAbstractItemView::NoDragDrop); setAllColumnsShowFocus(true); - setSelectionMode(QAbstractItemView::ExtendedSelection); + setSelectionMode(QAbstractItemView::SingleSelection); } FeedsView::~FeedsView() { diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index 5fc8af8bc..c045f483e 100755 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "gui/formmain.h" #include "gui/formabout.h"