This commit is contained in:
Martin Rotter 2013-12-11 21:37:59 +01:00
parent 0cdfdd686d
commit 5b9f20c14a
4 changed files with 32 additions and 6 deletions

View file

@ -1,12 +1,16 @@
#include "core/feedsmodel.h" #include "core/feedsmodel.h"
#include "core/feedsmodelrootitem.h" #include "core/feedsmodelrootitem.h"
#include "core/feedsmodelnonrootitem.h" #include "core/feedsmodelnonrootitem.h"
#include "core/feedsmodelfeed.h"
#include "core/feedsmodelcategory.h"
FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) { FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) {
m_rootItem = new FeedsModelRootItem(); 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,9 +20,19 @@ FeedsModel::~FeedsModel() {
} }
QVariant FeedsModel::data(const QModelIndex &index, int role) const { QVariant FeedsModel::data(const QModelIndex &index, int role) const {
if (!index.isValid()) {
return QVariant(); return QVariant();
} }
if (role != Qt::DisplayRole) {
return QVariant();
}
FeedsModelItem *item = static_cast<FeedsModelItem*>(index.internalPointer());
return item->data(index.column(), Qt::DisplayRole);
}
QVariant FeedsModel::headerData(int section, QVariant FeedsModel::headerData(int section,
Qt::Orientation orientation, Qt::Orientation orientation,
int role) const { int role) const {

View file

@ -1,7 +1,6 @@
#ifndef BASEFEEDSMODELITEM_H #ifndef BASEFEEDSMODELITEM_H
#define BASEFEEDSMODELITEM_H #define BASEFEEDSMODELITEM_H
#include <QList>
#include <QIcon> #include <QIcon>
@ -13,13 +12,15 @@ class FeedsModelItem {
virtual ~FeedsModelItem(); virtual ~FeedsModelItem();
// Returns parent item of this item. // Returns parent item of this item.
// NOTE: Model ROOT item has NULL parent.
virtual FeedsModelItem *parent() = 0; virtual FeedsModelItem *parent() = 0;
virtual FeedsModelItem *child(int row) = 0;
virtual int childCount() const = 0; virtual int childCount() const = 0;
virtual int columnCount() const = 0; virtual int columnCount() const = 0;
virtual FeedsModelItem *child(int row) = 0;
virtual int row() const = 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: protected:
QIcon m_icon; QIcon m_icon;

View file

@ -1,3 +1,5 @@
#include <QVariant>
#include "core/feedsmodelrootitem.h" #include "core/feedsmodelrootitem.h"
@ -29,3 +31,11 @@ int FeedsModelRootItem::row() const {
int FeedsModelRootItem::childCount() const { int FeedsModelRootItem::childCount() const {
return m_childItems.count(); return m_childItems.count();
} }
QVariant FeedsModelRootItem::data(int column, int role) const {
if (role == Qt::DisplayRole) {
return "aaa";
}
return QVariant();
}

View file

@ -21,6 +21,7 @@ class FeedsModelRootItem : public FeedsModelItem {
int childCount() const; int childCount() const;
int columnCount() const; int columnCount() const;
int row() const; int row() const;
QVariant data(int column, int role) const;
protected: protected:
QList<FeedsModelItem*> m_childItems; QList<FeedsModelItem*> m_childItems;