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