rssguard/src/core/feedsmodelrootitem.cpp

161 lines
3.5 KiB
C++
Raw Normal View History

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 {
2014-01-10 08:36:08 +01:00
return m_childItems.size();
2013-12-11 14:07:18 +01:00
}
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 {
2014-01-10 09:18:29 +01:00
int total_count = 0;
foreach (FeedsModelRootItem *child_item, m_childItems) {
total_count += child_item->countOfAllMessages();
}
return total_count;
2013-12-12 22:28:51 +01:00
}
int FeedsModelRootItem::countOfUnreadMessages() const {
2014-01-10 09:18:29 +01:00
int total_count = 0;
foreach (FeedsModelRootItem *child_item, m_childItems) {
total_count += child_item->countOfUnreadMessages();
}
return total_count;
2013-12-12 22:28:51 +01:00
}
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;
}
void FeedsModelRootItem::clearChilds() {
m_childItems.clear();
}
2014-01-10 08:36:08 +01:00
bool FeedsModelRootItem::removeChild(int index) {
if (index >= 0 && index < m_childItems.size()) {
m_childItems.removeAt(index);
return true;
}
else {
return false;
}
}
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;
}
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;
}
}