2013-12-21 21:08:52 +01:00
|
|
|
#include "core/feedsmodelrootitem.h"
|
2013-12-11 21:37:59 +01:00
|
|
|
|
2013-12-19 13:52:53 +01:00
|
|
|
#include "qtsingleapplication/qtsingleapplication.h"
|
2013-12-21 21:08:52 +01:00
|
|
|
|
|
|
|
#include <QVariant>
|
2013-12-11 14:07:18 +01:00
|
|
|
|
|
|
|
|
2013-12-12 10:10:17 +01:00
|
|
|
FeedsModelRootItem::FeedsModelRootItem(FeedsModelRootItem *parent_item)
|
2013-12-22 11:29:10 +01:00
|
|
|
: m_kind(FeedsModelRootItem::RootItem),
|
|
|
|
m_parentItem(parent_item) {
|
2013-12-11 14:07:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FeedsModelRootItem::~FeedsModelRootItem() {
|
|
|
|
qDebug("Destroying FeedsModelRootItem instance.");
|
|
|
|
qDeleteAll(m_childItems);
|
|
|
|
}
|
|
|
|
|
2013-12-28 17:40:22 +01:00
|
|
|
FeedsModelRootItem *FeedsModelRootItem::parent() const {
|
2013-12-12 10:10:17 +01:00
|
|
|
return m_parentItem;
|
2013-12-11 14:07:18 +01:00
|
|
|
}
|
|
|
|
|
2013-12-12 15:07:17 +01:00
|
|
|
void FeedsModelRootItem::setParent(FeedsModelRootItem *parent_item) {
|
|
|
|
m_parentItem = parent_item;
|
|
|
|
}
|
|
|
|
|
2013-12-16 09:11:14 +01:00
|
|
|
FeedsModelRootItem::Kind FeedsModelRootItem::kind() const {
|
|
|
|
return m_kind;
|
|
|
|
}
|
|
|
|
|
2013-12-28 16:44:21 +01:00
|
|
|
QIcon FeedsModelRootItem::icon() const {
|
|
|
|
return m_icon;
|
|
|
|
}
|
|
|
|
|
2013-12-12 08:27:05 +01:00
|
|
|
FeedsModelRootItem *FeedsModelRootItem::child(int row) {
|
2013-12-12 10:10:17 +01:00
|
|
|
return m_childItems.value(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedsModelRootItem::appendChild(FeedsModelRootItem *child) {
|
|
|
|
m_childItems.append(child);
|
2013-12-12 15:07:17 +01:00
|
|
|
child->setParent(this);
|
2013-12-11 18:54:09 +01:00
|
|
|
}
|
|
|
|
|
2013-12-11 14:07:18 +01:00
|
|
|
int FeedsModelRootItem::columnCount() const {
|
2013-12-16 10:22:23 +01:00
|
|
|
// FeedsModel offers exactly two columns.
|
2013-12-11 14:07:18 +01:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2013-12-11 18:54:09 +01:00
|
|
|
int FeedsModelRootItem::row() const {
|
2013-12-12 10:10:17 +01:00
|
|
|
if (m_parentItem) {
|
|
|
|
return m_parentItem->m_childItems.indexOf(const_cast<FeedsModelRootItem*>(this));
|
|
|
|
}
|
|
|
|
else {
|
2013-12-16 10:22:23 +01:00
|
|
|
// This item has no parent. Therefore, its row index is 0.
|
2013-12-12 10:10:17 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2013-12-11 18:54:09 +01:00
|
|
|
}
|
|
|
|
|
2013-12-11 14:07:18 +01:00
|
|
|
int FeedsModelRootItem::childCount() const {
|
|
|
|
return m_childItems.count();
|
|
|
|
}
|
2013-12-11 21:37:59 +01:00
|
|
|
|
|
|
|
QVariant FeedsModelRootItem::data(int column, int role) const {
|
2013-12-12 10:10:17 +01:00
|
|
|
Q_UNUSED(column)
|
|
|
|
Q_UNUSED(role)
|
2013-12-11 21:37:59 +01:00
|
|
|
|
2013-12-16 10:22:23 +01:00
|
|
|
// Do not return anything for the root item.
|
2013-12-11 21:37:59 +01:00
|
|
|
return QVariant();
|
|
|
|
}
|
2013-12-12 22:28:51 +01:00
|
|
|
|
|
|
|
int FeedsModelRootItem::countOfAllMessages() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FeedsModelRootItem::countOfUnreadMessages() const {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-13 16:35:52 +01:00
|
|
|
|
|
|
|
void FeedsModelRootItem::setIcon(const QIcon &icon) {
|
|
|
|
m_icon = icon;
|
|
|
|
}
|
2013-12-13 20:48:45 +01:00
|
|
|
|
|
|
|
int FeedsModelRootItem::id() const {
|
|
|
|
return m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedsModelRootItem::setId(int id) {
|
|
|
|
m_id = id;
|
|
|
|
}
|
2013-12-16 09:11:14 +01:00
|
|
|
|
|
|
|
QString FeedsModelRootItem::title() const {
|
|
|
|
return m_title;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedsModelRootItem::setTitle(const QString &title) {
|
|
|
|
m_title = title;
|
|
|
|
}
|
|
|
|
|
2013-12-16 10:22:23 +01:00
|
|
|
QList<FeedsModelRootItem *> FeedsModelRootItem::childItems() const {
|
|
|
|
return m_childItems;
|
|
|
|
}
|
2013-12-17 17:08:11 +01:00
|
|
|
|
|
|
|
void FeedsModelRootItem::clearChilds() {
|
|
|
|
m_childItems.clear();
|
|
|
|
}
|
2013-12-28 16:00:27 +01:00
|
|
|
|
2014-01-07 19:09:19 +01:00
|
|
|
FeedsModelRootItem *FeedsModelRootItem::removeChild(int index) {
|
|
|
|
FeedsModelRootItem *item_to_delete = m_childItems.at(index);
|
|
|
|
|
|
|
|
m_childItems.removeAt(index);
|
|
|
|
|
|
|
|
return item_to_delete;
|
|
|
|
}
|
|
|
|
|
2014-01-05 21:36:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
QDateTime FeedsModelRootItem::creationDate() const {
|
|
|
|
return m_creationDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedsModelRootItem::setCreationDate(const QDateTime &creation_date) {
|
|
|
|
m_creationDate = creation_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FeedsModelRootItem::description() const {
|
|
|
|
return m_description;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedsModelRootItem::setDescription(const QString &description) {
|
|
|
|
m_description = description;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-28 16:00:27 +01:00
|
|
|
bool FeedsModelRootItem::isEqual(FeedsModelRootItem *lhs,
|
|
|
|
FeedsModelRootItem *rhs) {
|
|
|
|
return (lhs->kind() == rhs->kind()) && (lhs->id() == rhs->id());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FeedsModelRootItem::lessThan(FeedsModelRootItem *lhs,
|
|
|
|
FeedsModelRootItem *rhs) {
|
|
|
|
if (lhs->kind() == rhs->kind()) {
|
|
|
|
return lhs->id() < rhs->id();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|