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.");
|
|
|
|
|
2014-01-13 21:43:35 +01:00
|
|
|
qDeleteAll(m_childItems);
|
2013-12-12 15:07:17 +01:00
|
|
|
}
|
|
|
|
|
2013-12-16 09:11:14 +01:00
|
|
|
|
2013-12-11 14:07:18 +01:00
|
|
|
|
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 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
|
|
|
|
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-07 19:09:19 +01:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|