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