Some changes for feed models.
This commit is contained in:
parent
4f6cf19e3f
commit
4047275361
@ -58,12 +58,14 @@ FeedsModel::~FeedsModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVariant FeedsModel::data(const QModelIndex &index, int role) const {
|
QVariant FeedsModel::data(const QModelIndex &index, int role) const {
|
||||||
if (!index.isValid()) {
|
FeedsModelRootItem *item = itemForIndex(index);
|
||||||
|
|
||||||
|
if (item != NULL) {
|
||||||
|
return item->data(index.column(), role);
|
||||||
|
}
|
||||||
|
else {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
FeedsModelRootItem *item = static_cast<FeedsModelRootItem*>(index.internalPointer());
|
|
||||||
return item->data(index.column(), role);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FeedsModel::headerData(int section,
|
QVariant FeedsModel::headerData(int section,
|
||||||
@ -164,7 +166,7 @@ int FeedsModel::columnCount(const QModelIndex &parent) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FeedsModelRootItem *FeedsModel::itemForIndex(const QModelIndex &index) {
|
FeedsModelRootItem *FeedsModel::itemForIndex(const QModelIndex &index) const {
|
||||||
if (index.isValid() && index.model() == this) {
|
if (index.isValid() && index.model() == this) {
|
||||||
return static_cast<FeedsModelRootItem*>(index.internalPointer());
|
return static_cast<FeedsModelRootItem*>(index.internalPointer());
|
||||||
}
|
}
|
||||||
@ -173,7 +175,7 @@ FeedsModelRootItem *FeedsModel::itemForIndex(const QModelIndex &index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsModel::changeLayout(QModelIndexList list) {
|
void FeedsModel::reloadChangedLayout(QModelIndexList list) {
|
||||||
while (!list.isEmpty()) {
|
while (!list.isEmpty()) {
|
||||||
QModelIndex ix = list.takeLast();
|
QModelIndex ix = list.takeLast();
|
||||||
|
|
||||||
@ -181,21 +183,20 @@ void FeedsModel::changeLayout(QModelIndexList list) {
|
|||||||
emit dataChanged(index(ix.row(), 0, ix.parent()),
|
emit dataChanged(index(ix.row(), 0, ix.parent()),
|
||||||
index(ix.row(), FDS_MODEL_COUNTS_INDEX, ix.parent()));
|
index(ix.row(), FDS_MODEL_COUNTS_INDEX, ix.parent()));
|
||||||
|
|
||||||
|
|
||||||
if (ix.parent().isValid()) {
|
if (ix.parent().isValid()) {
|
||||||
// Make sure that data of parent are changed too.
|
// Make sure that data of parent are changed too.
|
||||||
list.append(ix.parent());
|
list.append(ix.parent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
void FeedsModel::reloadWholeLayout() {
|
||||||
// NOTE: Take a look at docs about this.
|
// NOTE: Take a look at docs about this.
|
||||||
// I have tested that this is LITTLE slower than code above,
|
// I have tested that this is LITTLE slower than code above,
|
||||||
// but it is really SIMPLER, so if code above will be buggy, then
|
// but it is really SIMPLER, so if code above will be buggy, then
|
||||||
// we can use this.
|
// we can use this.
|
||||||
emit layoutAboutToBeChanged();
|
emit layoutAboutToBeChanged();
|
||||||
emit layoutChanged();
|
emit layoutChanged();
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsModel::loadFromDatabase() {
|
void FeedsModel::loadFromDatabase() {
|
||||||
|
@ -45,21 +45,21 @@ class FeedsModel : public QAbstractItemModel {
|
|||||||
// Returns feeds contained within single index.
|
// Returns feeds contained within single index.
|
||||||
QList<FeedsModelFeed*> feedsForIndex(const QModelIndex &index);
|
QList<FeedsModelFeed*> feedsForIndex(const QModelIndex &index);
|
||||||
|
|
||||||
// Returns feed/category which lies at the specified index or
|
|
||||||
// null if index is invalid.
|
|
||||||
FeedsModelRootItem *itemForIndex(const QModelIndex &index);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void reloadWholeLayout();
|
||||||
|
|
||||||
// Signals that SOME data of this model need
|
// Signals that SOME data of this model need
|
||||||
// to be reloaded by ALL attached views.
|
// to be reloaded by ALL attached views.
|
||||||
void changeLayout(QModelIndexList list);
|
void reloadChangedLayout(QModelIndexList list);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// Returns feed/category which lies at the specified index or
|
||||||
|
// null if index is invalid.
|
||||||
|
FeedsModelRootItem *itemForIndex(const QModelIndex &index) const;
|
||||||
|
|
||||||
// Loads feed/categories from the database.
|
// Loads feed/categories from the database.
|
||||||
void loadFromDatabase();
|
void loadFromDatabase();
|
||||||
|
|
||||||
// TODO: Otestovat metody itemForIndex, feedsForIndex, feedsForIndexes.
|
|
||||||
|
|
||||||
// Takes lists of feeds/categories and assembles
|
// Takes lists of feeds/categories and assembles
|
||||||
// them into the tree structure.
|
// them into the tree structure.
|
||||||
void assembleCategories(CategoryAssignment categories);
|
void assembleCategories(CategoryAssignment categories);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include "qtsingleapplication/qtsingleapplication.h"
|
||||||
#include "core/feedsmodelrootitem.h"
|
#include "core/feedsmodelrootitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,8 +21,11 @@ QVariant FeedsModelStandardCategory::data(int column, int role) const {
|
|||||||
if (column == FDS_MODEL_TITLE_INDEX) {
|
if (column == FDS_MODEL_TITLE_INDEX) {
|
||||||
return QObject::tr("%1\n\n"
|
return QObject::tr("%1\n\n"
|
||||||
"Category type: standard\n"
|
"Category type: standard\n"
|
||||||
"Creation date: %2").arg(m_title,
|
"Creation date: %2%3").arg(m_title,
|
||||||
m_creationDate.toString(Qt::DefaultLocaleShortDate));
|
m_creationDate.toString(Qt::DefaultLocaleShortDate),
|
||||||
|
m_childItems.size() == 0 ?
|
||||||
|
QObject::tr("\n\nThis category does not contain any nested items.") :
|
||||||
|
"");
|
||||||
}
|
}
|
||||||
else if (column == FDS_MODEL_COUNTS_INDEX) {
|
else if (column == FDS_MODEL_COUNTS_INDEX) {
|
||||||
return QObject::tr("%n unread message(s).", "", countOfUnreadMessages());
|
return QObject::tr("%n unread message(s).", "", countOfUnreadMessages());
|
||||||
@ -42,6 +45,15 @@ QVariant FeedsModelStandardCategory::data(int column, int role) const {
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Qt::ForegroundRole:
|
||||||
|
if (m_childItems.size() == 0) {
|
||||||
|
// TODO: Make this configurable.
|
||||||
|
return QColor(Qt::red);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
if (column == FDS_MODEL_TITLE_INDEX) {
|
if (column == FDS_MODEL_TITLE_INDEX) {
|
||||||
return QString("%1%2").arg(m_title, "-C");
|
return QString("%1%2").arg(m_title, "-C");
|
||||||
|
@ -34,7 +34,7 @@ void FeedsView::updateCountsOfSelectedFeeds() {
|
|||||||
feed->updateCounts();
|
feed->updateCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sourceModel->changeLayout(mapped_rows);
|
m_sourceModel->reloadChangedLayout(mapped_rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsView::setupAppearance() {
|
void FeedsView::setupAppearance() {
|
||||||
|
@ -188,7 +188,6 @@ void MessagesView::loadFeeds(const QList<int> &feed_ids) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MessagesView::openSelectedSourceArticlesExternally() {
|
void MessagesView::openSelectedSourceArticlesExternally() {
|
||||||
|
|
||||||
QString browser = Settings::getInstance()->value(APP_CFG_MESSAGES,
|
QString browser = Settings::getInstance()->value(APP_CFG_MESSAGES,
|
||||||
"external_browser_executable").toString();
|
"external_browser_executable").toString();
|
||||||
QString arguments = Settings::getInstance()->value(APP_CFG_MESSAGES,
|
QString arguments = Settings::getInstance()->value(APP_CFG_MESSAGES,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user