From 5b9f20c14a59b7a9f19cd4509e10174fc0b0dde4 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 11 Dec 2013 21:37:59 +0100 Subject: [PATCH] csacsa --- src/core/feedsmodel.cpp | 20 +++++++++++++++++--- src/core/feedsmodelitem.h | 7 ++++--- src/core/feedsmodelrootitem.cpp | 10 ++++++++++ src/core/feedsmodelrootitem.h | 1 + 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index f7d81b836..60c1e087c 100644 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -1,12 +1,16 @@ #include "core/feedsmodel.h" #include "core/feedsmodelrootitem.h" #include "core/feedsmodelnonrootitem.h" - +#include "core/feedsmodelfeed.h" +#include "core/feedsmodelcategory.h" FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) { m_rootItem = new FeedsModelRootItem(); - m_rootItem->m_childItems.append(new FeedsModelNonRootItem(m_rootItem)); + FeedsModelCategory *cat = new FeedsModelCategory(m_rootItem); + cat->m_childItems.append(new FeedsModelFeed(cat)); + m_rootItem->m_childItems.append(cat); + } @@ -16,7 +20,17 @@ FeedsModel::~FeedsModel() { } QVariant FeedsModel::data(const QModelIndex &index, int role) const { - return QVariant(); + if (!index.isValid()) { + return QVariant(); + } + + if (role != Qt::DisplayRole) { + return QVariant(); + } + + FeedsModelItem *item = static_cast(index.internalPointer()); + + return item->data(index.column(), Qt::DisplayRole); } QVariant FeedsModel::headerData(int section, diff --git a/src/core/feedsmodelitem.h b/src/core/feedsmodelitem.h index 7aca9d88c..41c68d8b8 100644 --- a/src/core/feedsmodelitem.h +++ b/src/core/feedsmodelitem.h @@ -1,7 +1,6 @@ #ifndef BASEFEEDSMODELITEM_H #define BASEFEEDSMODELITEM_H -#include #include @@ -13,13 +12,15 @@ class FeedsModelItem { virtual ~FeedsModelItem(); // Returns parent item of this item. - // NOTE: Model ROOT item has NULL parent. virtual FeedsModelItem *parent() = 0; + virtual FeedsModelItem *child(int row) = 0; virtual int childCount() const = 0; virtual int columnCount() const = 0; - virtual FeedsModelItem *child(int row) = 0; virtual int row() const = 0; + // NOTE: Reimplement this in target particular feed/category classes. + virtual QVariant data(int column, int role) const = 0; + protected: QIcon m_icon; diff --git a/src/core/feedsmodelrootitem.cpp b/src/core/feedsmodelrootitem.cpp index 14b9a2c51..14f41ff50 100644 --- a/src/core/feedsmodelrootitem.cpp +++ b/src/core/feedsmodelrootitem.cpp @@ -1,3 +1,5 @@ +#include + #include "core/feedsmodelrootitem.h" @@ -29,3 +31,11 @@ int FeedsModelRootItem::row() const { int FeedsModelRootItem::childCount() const { return m_childItems.count(); } + +QVariant FeedsModelRootItem::data(int column, int role) const { + if (role == Qt::DisplayRole) { + return "aaa"; + } + + return QVariant(); +} diff --git a/src/core/feedsmodelrootitem.h b/src/core/feedsmodelrootitem.h index 6db9a785d..0f190affa 100644 --- a/src/core/feedsmodelrootitem.h +++ b/src/core/feedsmodelrootitem.h @@ -21,6 +21,7 @@ class FeedsModelRootItem : public FeedsModelItem { int childCount() const; int columnCount() const; int row() const; + QVariant data(int column, int role) const; protected: QList m_childItems;