Work on feed models & representation.
This commit is contained in:
parent
ec11ccbfa4
commit
26211cb229
@ -238,6 +238,37 @@ void FeedsModel::loadFromDatabase() {
|
|||||||
assembleFeeds(feeds);
|
assembleFeeds(feeds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<FeedsModelFeed*> FeedsModel::feedsForIndex(const QModelIndex &index) {
|
||||||
|
QList<FeedsModelFeed*> feeds;
|
||||||
|
FeedsModelRootItem *item = itemForIndex(index);
|
||||||
|
|
||||||
|
switch (item->kind()) {
|
||||||
|
case FeedsModelRootItem::Category:
|
||||||
|
feeds.append(static_cast<FeedsModelCategory*>(item)->feeds());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FeedsModelRootItem::Feed:
|
||||||
|
// This item is feed (it SURELY subclasses FeedsModelFeed),add it.
|
||||||
|
feeds.append(static_cast<FeedsModelFeed*>(item));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return feeds;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<FeedsModelFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
|
||||||
|
QList<FeedsModelFeed*> feeds;
|
||||||
|
|
||||||
|
foreach (const QModelIndex &index, indexes) {
|
||||||
|
feeds.append(feedsForIndex(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
return feeds;
|
||||||
|
}
|
||||||
|
|
||||||
QHash<int, FeedsModelCategory *> FeedsModel::getCategories(FeedsModelRootItem *root) {
|
QHash<int, FeedsModelCategory *> FeedsModel::getCategories(FeedsModelRootItem *root) {
|
||||||
QHash<int, FeedsModelCategory*> categories;
|
QHash<int, FeedsModelCategory*> categories;
|
||||||
|
|
||||||
|
@ -30,19 +30,30 @@ class FeedsModel : public QAbstractItemModel {
|
|||||||
int columnCount(const QModelIndex &parent) const;
|
int columnCount(const QModelIndex &parent) const;
|
||||||
int rowCount(const QModelIndex &parent) const;
|
int rowCount(const QModelIndex &parent) const;
|
||||||
|
|
||||||
// Returns feed/category which lies at the specified index.
|
|
||||||
FeedsModelRootItem *itemForIndex(const QModelIndex &index);
|
|
||||||
|
|
||||||
// Loads feed/categories from the database.
|
|
||||||
void loadFromDatabase();
|
|
||||||
|
|
||||||
// Returns all categories.
|
// Returns all categories.
|
||||||
QHash<int, FeedsModelCategory*> getCategories();
|
QHash<int, FeedsModelCategory*> getCategories();
|
||||||
|
|
||||||
// Returns categories from the subtree with given root node.
|
// Returns categories from the subtree with given root node.
|
||||||
QHash<int, FeedsModelCategory*> getCategories(FeedsModelRootItem *root);
|
QHash<int, FeedsModelCategory*> getCategories(FeedsModelRootItem *root);
|
||||||
|
|
||||||
|
// Returns list of feeds which belong to given indexes.
|
||||||
|
// NOTE: If index is "category", then all child feeds are contained in the
|
||||||
|
// result.
|
||||||
|
// NOTE: This is particularly useful for displaying messages of selected feeds.
|
||||||
|
QList<FeedsModelFeed*> feedsForIndexes(const QModelIndexList &indexes);
|
||||||
|
|
||||||
|
// Returns feeds contained within single index.
|
||||||
|
QList<FeedsModelFeed*> feedsForIndex(const QModelIndex &index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// Loads feed/categories from the database.
|
||||||
|
void loadFromDatabase();
|
||||||
|
|
||||||
|
// TODO: Otestovat metody itemForIndex, feedsForIndex, feedsForIndexes.
|
||||||
|
|
||||||
|
// Returns feed/category which lies at the specified index.
|
||||||
|
FeedsModelRootItem *itemForIndex(const QModelIndex &index);
|
||||||
|
|
||||||
// Takes lists of feeds/categories and assembles
|
// Takes lists of feeds/categories and assembles
|
||||||
// them into the tree structure.
|
// them into the tree structure.
|
||||||
void assembleCategories(CategoryAssignment categories);
|
void assembleCategories(CategoryAssignment categories);
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
|
#include <QQueue>
|
||||||
|
|
||||||
#include "core/feedsmodelcategory.h"
|
#include "core/feedsmodelcategory.h"
|
||||||
|
#include "core/feedsmodelstandardcategory.h"
|
||||||
|
#include "core/feedsmodelstandardfeed.h"
|
||||||
|
|
||||||
|
|
||||||
FeedsModelCategory::FeedsModelCategory(FeedsModelRootItem *parent_item)
|
FeedsModelCategory::FeedsModelCategory(FeedsModelRootItem *parent_item)
|
||||||
@ -8,6 +12,35 @@ FeedsModelCategory::FeedsModelCategory(FeedsModelRootItem *parent_item)
|
|||||||
FeedsModelCategory::~FeedsModelCategory() {
|
FeedsModelCategory::~FeedsModelCategory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<FeedsModelFeed*> FeedsModelCategory::feeds() {
|
||||||
|
QList<FeedsModelFeed*> feeds;
|
||||||
|
QQueue<FeedsModelCategory*> categories;
|
||||||
|
|
||||||
|
categories.enqueue(this);
|
||||||
|
|
||||||
|
while (!categories.isEmpty()) {
|
||||||
|
FeedsModelCategory *active_category = categories.dequeue();
|
||||||
|
|
||||||
|
foreach (FeedsModelRootItem *child, active_category->childItems()) {
|
||||||
|
switch (child->kind()) {
|
||||||
|
case FeedsModelRootItem::Feed:
|
||||||
|
feeds.append(static_cast<FeedsModelFeed*>(child));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FeedsModelRootItem::Category:
|
||||||
|
// This is category, so add it to traversed categories.
|
||||||
|
categories.enqueue(static_cast<FeedsModelCategory*>(child));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return feeds;
|
||||||
|
}
|
||||||
|
|
||||||
int FeedsModelCategory::countOfAllMessages() const {
|
int FeedsModelCategory::countOfAllMessages() const {
|
||||||
int total_count = 0;
|
int total_count = 0;
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "core/feedsmodelrootitem.h"
|
#include "core/feedsmodelrootitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
class FeedsModelFeed;
|
||||||
|
|
||||||
// Base class for all categories contained in FeedsModel.
|
// Base class for all categories contained in FeedsModel.
|
||||||
// NOTE: This class should be derived to create PARTICULAR category types.
|
// NOTE: This class should be derived to create PARTICULAR category types.
|
||||||
// NOTE: This class should not be instantiated directly.
|
// NOTE: This class should not be instantiated directly.
|
||||||
@ -23,6 +25,12 @@ class FeedsModelCategory : public FeedsModelRootItem {
|
|||||||
explicit FeedsModelCategory(FeedsModelRootItem *parent_item = NULL);
|
explicit FeedsModelCategory(FeedsModelRootItem *parent_item = NULL);
|
||||||
virtual ~FeedsModelCategory();
|
virtual ~FeedsModelCategory();
|
||||||
|
|
||||||
|
// TODO: Otestovat metodu feeds.
|
||||||
|
|
||||||
|
// Returns list of ALL feeds situated under this category.
|
||||||
|
// NOTE: This is recursive.
|
||||||
|
virtual QList<FeedsModelFeed*> feeds();
|
||||||
|
|
||||||
// Counts of messages.
|
// Counts of messages.
|
||||||
// NOTE: Counts of messages in categories include
|
// NOTE: Counts of messages in categories include
|
||||||
// counts of messages from all children.
|
// counts of messages from all children.
|
||||||
|
@ -11,9 +11,9 @@ class FeedsModelRootItem {
|
|||||||
public:
|
public:
|
||||||
// Describes the kind of the item.
|
// Describes the kind of the item.
|
||||||
enum Kind {
|
enum Kind {
|
||||||
RootItem,
|
RootItem = 1001,
|
||||||
Feed,
|
Feed = 1002,
|
||||||
Category
|
Category = 1003
|
||||||
};
|
};
|
||||||
|
|
||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
|
@ -37,6 +37,7 @@ class FeedsModelStandardFeed : public FeedsModelFeed {
|
|||||||
QString language() const;
|
QString language() const;
|
||||||
void setLanguage(const QString &language);
|
void setLanguage(const QString &language);
|
||||||
|
|
||||||
|
// Loads standard feed object from given SQL record.
|
||||||
static FeedsModelStandardFeed *loadFromRecord(const QSqlRecord &record);
|
static FeedsModelStandardFeed *loadFromRecord(const QSqlRecord &record);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -56,3 +56,23 @@ bool FeedsProxyModel::lessThan(const QModelIndex &left,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QModelIndexList FeedsProxyModel::mapListFromSource(const QModelIndexList &indexes) {
|
||||||
|
QModelIndexList mapped_indexes;
|
||||||
|
|
||||||
|
foreach (const QModelIndex &index, indexes) {
|
||||||
|
mapped_indexes << mapFromSource(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapped_indexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndexList FeedsProxyModel::mapListToSource(const QModelIndexList &indexes) {
|
||||||
|
QModelIndexList source_indexes;
|
||||||
|
|
||||||
|
foreach (const QModelIndex &index, indexes) {
|
||||||
|
source_indexes << mapToSource(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return source_indexes;
|
||||||
|
}
|
||||||
|
@ -17,6 +17,10 @@ class FeedsProxyModel : public QSortFilterProxyModel {
|
|||||||
// Access to the source model.
|
// Access to the source model.
|
||||||
FeedsModel *sourceModel();
|
FeedsModel *sourceModel();
|
||||||
|
|
||||||
|
// Maps list of indexes.
|
||||||
|
QModelIndexList mapListToSource(const QModelIndexList &indexes);
|
||||||
|
QModelIndexList mapListFromSource(const QModelIndexList &indexes);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Compares two rows of data.
|
// Compares two rows of data.
|
||||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||||
|
@ -52,4 +52,3 @@ QModelIndexList MessagesProxyModel::mapListToSource(const QModelIndexList &index
|
|||||||
|
|
||||||
return source_indexes;
|
return source_indexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user