Work on feeed model.
This commit is contained in:
parent
efdf00883f
commit
421336bf5b
3 changed files with 18 additions and 5 deletions
|
@ -169,7 +169,7 @@ FeedsModelRootItem *FeedsModel::itemForIndex(const QModelIndex &index) {
|
|||
}
|
||||
|
||||
void FeedsModel::loadFromDatabase() {
|
||||
qDeleteAll(m_rootItem->m_childItems);
|
||||
qDeleteAll(m_rootItem->childItems());
|
||||
|
||||
QSqlDatabase database = DatabaseFactory::getInstance()->addConnection(objectName());
|
||||
CategoryAssignment categories;
|
||||
|
@ -241,7 +241,7 @@ void FeedsModel::loadFromDatabase() {
|
|||
QHash<int, FeedsModelCategory *> FeedsModel::getCategories(FeedsModelRootItem *root) {
|
||||
QHash<int, FeedsModelCategory*> categories;
|
||||
|
||||
foreach (FeedsModelRootItem *child, root->m_childItems) {
|
||||
foreach (FeedsModelRootItem *child, root->childItems()) {
|
||||
FeedsModelCategory *converted = dynamic_cast<FeedsModelCategory*>(child);
|
||||
|
||||
if (converted != NULL) {
|
||||
|
|
|
@ -37,6 +37,7 @@ void FeedsModelRootItem::appendChild(FeedsModelRootItem *child) {
|
|||
}
|
||||
|
||||
int FeedsModelRootItem::columnCount() const {
|
||||
// FeedsModel offers exactly two columns.
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@ -45,6 +46,7 @@ int FeedsModelRootItem::row() const {
|
|||
return m_parentItem->m_childItems.indexOf(const_cast<FeedsModelRootItem*>(this));
|
||||
}
|
||||
else {
|
||||
// This item has no parent. Therefore, its row index is 0.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +59,7 @@ QVariant FeedsModelRootItem::data(int column, int role) const {
|
|||
Q_UNUSED(column)
|
||||
Q_UNUSED(role)
|
||||
|
||||
// Do not return anything for the root item.
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
@ -88,3 +91,6 @@ void FeedsModelRootItem::setTitle(const QString &title) {
|
|||
m_title = title;
|
||||
}
|
||||
|
||||
QList<FeedsModelRootItem *> FeedsModelRootItem::childItems() const {
|
||||
return m_childItems;
|
||||
}
|
||||
|
|
|
@ -8,9 +8,8 @@
|
|||
// NOTE: This class is derived to add functionality for
|
||||
// all other non-root items of FeedsModel.
|
||||
class FeedsModelRootItem {
|
||||
friend class FeedsModel;
|
||||
|
||||
public:
|
||||
// Describes the kind of the item.
|
||||
enum Kind {
|
||||
RootItem,
|
||||
Feed,
|
||||
|
@ -22,8 +21,8 @@ class FeedsModelRootItem {
|
|||
virtual ~FeedsModelRootItem();
|
||||
|
||||
// Basic operations.
|
||||
virtual void setParent(FeedsModelRootItem *parent_item);
|
||||
virtual FeedsModelRootItem *parent();
|
||||
virtual void setParent(FeedsModelRootItem *parent_item);
|
||||
virtual FeedsModelRootItem *child(int row);
|
||||
virtual void appendChild(FeedsModelRootItem *child);
|
||||
virtual int childCount() const;
|
||||
|
@ -36,6 +35,9 @@ class FeedsModelRootItem {
|
|||
virtual int countOfAllMessages() const;
|
||||
|
||||
// Each item can be "updated".
|
||||
// NOTE: This method is used in the "update worker".
|
||||
// For example, it can fetch new messages from a remote destination
|
||||
// and store them in a local database and so on.
|
||||
virtual void update();
|
||||
|
||||
virtual Kind kind() const;
|
||||
|
@ -47,9 +49,14 @@ class FeedsModelRootItem {
|
|||
int id() const;
|
||||
void setId(int id);
|
||||
|
||||
// Each item has its title.
|
||||
// NOTE: This is note entirely true for the root item.
|
||||
QString title() const;
|
||||
void setTitle(const QString &title);
|
||||
|
||||
// Acess to children.
|
||||
QList<FeedsModelRootItem *> childItems() const;
|
||||
|
||||
protected:
|
||||
Kind m_kind;
|
||||
QString m_title;
|
||||
|
|
Loading…
Add table
Reference in a new issue