Added new classes and some removed.

This commit is contained in:
Martin Rotter 2013-12-12 08:27:05 +01:00
parent 5b9f20c14a
commit 93e1fb0ef7
16 changed files with 92 additions and 76 deletions

View File

@ -269,11 +269,12 @@ set(APP_SOURCES
src/core/messagesproxymodel.cpp
src/core/feedsmodel.cpp
src/core/feedsproxymodel.cpp
src/core/feedsmodelitem.cpp
src/core/feedsmodelcategory.cpp
src/core/feedsmodelrootitem.cpp
src/core/feedsmodelnonrootitem.cpp
src/core/feedsmodelfeed.cpp
src/core/feedsmodelstandardcategory.cpp
src/core/feedsmodelstandardfeed.cpp
# Basic application sources.
src/main.cpp

View File

@ -28,7 +28,7 @@ QVariant FeedsModel::data(const QModelIndex &index, int role) const {
return QVariant();
}
FeedsModelItem *item = static_cast<FeedsModelItem*>(index.internalPointer());
FeedsModelRootItem *item = static_cast<FeedsModelRootItem*>(index.internalPointer());
return item->data(index.column(), Qt::DisplayRole);
}
@ -55,16 +55,16 @@ QModelIndex FeedsModel::index(int row, int column, const QModelIndex &parent) co
return QModelIndex();
}
FeedsModelItem *parent_item;
FeedsModelRootItem *parent_item;
if (!parent.isValid()) {
parent_item = m_rootItem;
}
else {
parent_item = static_cast<FeedsModelItem*>(parent.internalPointer());
parent_item = static_cast<FeedsModelRootItem*>(parent.internalPointer());
}
FeedsModelItem *child_item = parent_item->child(row);
FeedsModelRootItem *child_item = parent_item->child(row);
if (child_item) {
return createIndex(row, column, child_item);
@ -79,8 +79,8 @@ QModelIndex FeedsModel::parent(const QModelIndex &child) const {
return QModelIndex();
}
FeedsModelItem *child_item = static_cast<FeedsModelItem*>(child.internalPointer());
FeedsModelItem *parent_item = child_item->parent();
FeedsModelRootItem *child_item = static_cast<FeedsModelRootItem*>(child.internalPointer());
FeedsModelRootItem *parent_item = child_item->parent();
if (parent_item == m_rootItem) {
return QModelIndex();
@ -91,7 +91,7 @@ QModelIndex FeedsModel::parent(const QModelIndex &child) const {
}
int FeedsModel::rowCount(const QModelIndex &parent) const {
FeedsModelItem *parent_item;
FeedsModelRootItem *parent_item;
if (parent.column() > 0) {
return 0;
@ -101,7 +101,7 @@ int FeedsModel::rowCount(const QModelIndex &parent) const {
parent_item = m_rootItem;
}
else {
parent_item = static_cast<FeedsModelItem*>(parent.internalPointer());
parent_item = static_cast<FeedsModelRootItem*>(parent.internalPointer());
}
return parent_item->childCount();
@ -109,7 +109,7 @@ int FeedsModel::rowCount(const QModelIndex &parent) const {
int FeedsModel::columnCount(const QModelIndex &parent) const {
if (parent.isValid()) {
return static_cast<FeedsModelItem*>(parent.internalPointer())->columnCount();
return static_cast<FeedsModelRootItem*>(parent.internalPointer())->columnCount();
}
else {
return m_rootItem->columnCount();

View File

@ -1,7 +1,7 @@
#include "core/feedsmodelcategory.h"
FeedsModelCategory::FeedsModelCategory(FeedsModelItem *parent_item)
FeedsModelCategory::FeedsModelCategory(FeedsModelRootItem *parent_item)
: FeedsModelNonRootItem(parent_item) {
}

View File

@ -5,11 +5,11 @@
// Base class for all categories contained in FeedsModel.
// NOTE: This class is derived to create PARTICULAR category types.
// NOTE: This class should be derived to create PARTICULAR category types.
class FeedsModelCategory : public FeedsModelNonRootItem {
public:
// Constructors and destructors
explicit FeedsModelCategory(FeedsModelItem *parent_item);
explicit FeedsModelCategory(FeedsModelRootItem *parent_item);
virtual ~FeedsModelCategory();
};

View File

@ -1,7 +1,7 @@
#include "core/feedsmodelfeed.h"
FeedsModelFeed::FeedsModelFeed(FeedsModelItem *parent_item)
FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item)
:FeedsModelNonRootItem(parent_item) {
}

View File

@ -5,12 +5,12 @@
// Represents BASE class for feeds contained in FeedsModel.
// NOTE: This class is derived to create PARTICULAR feed types.
// NOTE: This class should be derived to create PARTICULAR feed types.
class FeedsModelFeed : public FeedsModelNonRootItem
{
public:
// Constructors and destructors.
explicit FeedsModelFeed(FeedsModelItem *parent_item);
explicit FeedsModelFeed(FeedsModelRootItem *parent_item);
virtual ~FeedsModelFeed();
int childCount() const;

View File

@ -1,11 +0,0 @@
#include <QDebug>
#include "core/feedsmodelitem.h"
FeedsModelItem::FeedsModelItem() {
}
FeedsModelItem::~FeedsModelItem() {
qDebug("Destroying BaseFeedsModelItem instance.");
}

View File

@ -1,29 +0,0 @@
#ifndef BASEFEEDSMODELITEM_H
#define BASEFEEDSMODELITEM_H
#include <QIcon>
// Base class for all items contained in FeedsModel.
class FeedsModelItem {
public:
// Constructors and destructors.
explicit FeedsModelItem();
virtual ~FeedsModelItem();
// Returns parent item of this item.
virtual FeedsModelItem *parent() = 0;
virtual FeedsModelItem *child(int row) = 0;
virtual int childCount() const = 0;
virtual int columnCount() 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:
QIcon m_icon;
};
#endif // BASEFEEDSMODELITEM_H

View File

@ -1,7 +1,7 @@
#include "core/feedsmodelnonrootitem.h"
FeedsModelNonRootItem::FeedsModelNonRootItem(FeedsModelItem *parent_item)
FeedsModelNonRootItem::FeedsModelNonRootItem(FeedsModelRootItem *parent_item)
: FeedsModelRootItem(), m_parentItem(parent_item) {
}
@ -9,13 +9,13 @@ FeedsModelNonRootItem::~FeedsModelNonRootItem() {
qDebug("Destroying FeedsModelNonRootItem instance.");
}
FeedsModelItem *FeedsModelNonRootItem::parent() {
FeedsModelRootItem *FeedsModelNonRootItem::parent() {
return m_parentItem;
}
int FeedsModelNonRootItem::row() const {
if (m_parentItem) {
return static_cast<FeedsModelRootItem*>(m_parentItem)->m_childItems.indexOf((FeedsModelItem*) this);
return static_cast<FeedsModelRootItem*>(m_parentItem)->m_childItems.indexOf((FeedsModelRootItem*) this);
}
else {
return 0;

View File

@ -10,14 +10,14 @@
class FeedsModelNonRootItem : public FeedsModelRootItem {
public:
// Constructors and destructors.
explicit FeedsModelNonRootItem(FeedsModelItem *parent_item);
explicit FeedsModelNonRootItem(FeedsModelRootItem *parent_item);
virtual ~FeedsModelNonRootItem();
FeedsModelItem *parent();
FeedsModelRootItem *parent();
int row() const;
protected:
FeedsModelItem *m_parentItem;
FeedsModelRootItem *m_parentItem;
};
#endif // FEEDSMODELNONROOTITEM_H

View File

@ -3,8 +3,7 @@
#include "core/feedsmodelrootitem.h"
FeedsModelRootItem::FeedsModelRootItem()
: FeedsModelItem() {
FeedsModelRootItem::FeedsModelRootItem() {
}
FeedsModelRootItem::~FeedsModelRootItem() {
@ -12,11 +11,11 @@ FeedsModelRootItem::~FeedsModelRootItem() {
qDeleteAll(m_childItems);
}
FeedsModelItem *FeedsModelRootItem::parent() {
FeedsModelRootItem *FeedsModelRootItem::parent() {
return NULL;
}
FeedsModelItem *FeedsModelRootItem::child(int row) {
FeedsModelRootItem *FeedsModelRootItem::child(int row) {
return m_childItems.at(0);
}

View File

@ -1,13 +1,13 @@
#ifndef FEEDMODELROOTITEM_H
#define FEEDMODELROOTITEM_H
#include "core/feedsmodelitem.h"
#include <QIcon>
// Represents ROOT item of FeedsModel.
// NOTE: This class is derived to add functionality for
// all non-root items of FeedsModel.
class FeedsModelRootItem : public FeedsModelItem {
// all other non-root items of FeedsModel.
class FeedsModelRootItem {
friend class FeedsModelNonRootItem;
friend class FeedsModel;
@ -16,15 +16,16 @@ class FeedsModelRootItem : public FeedsModelItem {
explicit FeedsModelRootItem();
virtual ~FeedsModelRootItem();
FeedsModelItem *parent();
FeedsModelItem *child(int row);
int childCount() const;
int columnCount() const;
int row() const;
QVariant data(int column, int role) const;
virtual FeedsModelRootItem *parent();
virtual FeedsModelRootItem *child(int row);
virtual int childCount() const;
virtual int columnCount() const;
virtual int row() const;
virtual QVariant data(int column, int role) const;
protected:
QList<FeedsModelItem*> m_childItems;
QIcon m_icon;
QList<FeedsModelRootItem*> m_childItems;
};

View File

@ -0,0 +1,10 @@
#include "core/feedsmodelstandardcategory.h"
FeedsModelStandardCategory::FeedsModelStandardCategory(FeedsModelRootItem *parent_item)
: FeedsModelCategory(parent_item) {
}
FeedsModelStandardCategory::~FeedsModelStandardCategory() {
qDebug("Destroying FeedsModelStandardCategory instance.");
}

View File

@ -0,0 +1,19 @@
#ifndef FEEDSMODELSTANDARDCATEGORY_H
#define FEEDSMODELSTANDARDCATEGORY_H
#include "core/feedsmodelcategory.h"
// Represents STANDARD category container.
// Standard category container can contain:
// a) other standard category containers,
// b) standard feeds,
// c) other containers and feeds (synchronized ones).
class FeedsModelStandardCategory : public FeedsModelCategory {
public:
// Constructors and destructors.
explicit FeedsModelStandardCategory(FeedsModelRootItem *parent_item);
virtual ~FeedsModelStandardCategory();
};
#endif // FEEDSMODELSTANDARDCATEGORY_H

View File

@ -0,0 +1,10 @@
#include "feedsmodelstandardfeed.h"
FeedsModelStandardFeed::FeedsModelStandardFeed(FeedsModelRootItem *parent_item)
: FeedsModelFeed(parent_item) {
}
FeedsModelStandardFeed::~FeedsModelStandardFeed() {
qDebug("Destroying FeedsModelStandardFeed instance.");
}

View File

@ -0,0 +1,16 @@
#ifndef FEEDSMODELSTANDARDFEED_H
#define FEEDSMODELSTANDARDFEED_H
#include "core/feedsmodelfeed.h"
// Represents STANDARD RSS/RDF/ATOM feed with no
// online synchronization services (NO TT-RSS, NO FEEDLY).
class FeedsModelStandardFeed : public FeedsModelFeed {
public:
// Constructors and destructors.
explicit FeedsModelStandardFeed(FeedsModelRootItem *parent_item);
virtual ~FeedsModelStandardFeed();
};
#endif // FEEDSMODELSTANDARDFEED_H