csacsa
This commit is contained in:
parent
0cdfdd686d
commit
5b9f20c14a
4 changed files with 32 additions and 6 deletions
|
@ -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 {
|
||||
if (!index.isValid()) {
|
||||
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,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef BASEFEEDSMODELITEM_H
|
||||
#define BASEFEEDSMODELITEM_H
|
||||
|
||||
#include <QList>
|
||||
#include <QIcon>
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include <QVariant>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
|
|
@ -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<FeedsModelItem*> m_childItems;
|
||||
|
|
Loading…
Add table
Reference in a new issue