Work on feeds.

This commit is contained in:
Martin Rotter 2013-12-12 22:28:51 +01:00
parent f85de2c819
commit 6ec00ab841
15 changed files with 102 additions and 20 deletions

View File

@ -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.

View File

@ -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 {

View File

@ -27,6 +27,7 @@ class FeedsModel : public QAbstractItemModel {
private:
FeedsModelRootItem *m_rootItem;
QList<QString> m_headerData;
QList<QString> m_tooltipData;
QIcon m_countsIcon;
};

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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<FeedsModelRootItem*> m_childItems;

View File

@ -1,6 +1,7 @@
#include <QVariant>
#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();
}
}

View File

@ -16,7 +16,6 @@ class FeedsModelStandardCategory : public FeedsModelCategory {
virtual ~FeedsModelStandardCategory();
QVariant data(int column, int role) const;
};
#endif // FEEDSMODELSTANDARDCATEGORY_H

View File

@ -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();

View File

@ -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

View File

@ -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() {

View File

@ -1,5 +1,6 @@
#include <QCloseEvent>
#include <QMessageBox>
#include <QSessionManager>
#include "gui/formmain.h"
#include "gui/formabout.h"