21#include "moc_qgsnewsfeedmodel.cpp"
28 : QAbstractItemModel(
parent )
32 const QList< QgsNewsFeedParser::Entry > initialEntries = mParser->entries();
74 case Qt::DecorationRole:
75 if ( entry.
image.isNull() )
84 QHash<int, QByteArray> roles;
96 Qt::ItemFlags
flags = QAbstractItemModel::flags(
index );
102 if ( !hasIndex( row, column,
parent ) )
103 return QModelIndex();
107 return createIndex( row, column );
110 return QModelIndex();
116 return QModelIndex();
123 return mEntries.count();
135 beginInsertRows( QModelIndex(), mEntries.count(), mEntries.count() );
136 mEntries.append( entry );
142 for (
int idx = 0; idx < mEntries.count(); idx++ )
144 if ( mEntries.at( idx ).key == entry.
key )
146 mEntries[ idx ] = entry;
147 emit dataChanged(
index( idx, 0 ),
index( idx, 0 ) );
156 const auto findIter = std::find_if( mEntries.begin(), mEntries.end(), [entry](
const QgsNewsFeedParser::Entry & candidate )
158 return candidate.key == entry.key;
160 if ( findIter == mEntries.end() )
163 const int entryIndex =
static_cast< int >( std::distance( mEntries.begin(), findIter ) );
164 beginRemoveRows( QModelIndex(), entryIndex, entryIndex );
165 mEntries.removeAt( entryIndex );
169void QgsNewsFeedModel::onImageFetched(
const int key,
const QPixmap &pixmap )
172 const auto findIter = std::find_if( mEntries.begin(), mEntries.end(), [key](
const QgsNewsFeedParser::Entry & candidate )
174 return candidate.key == key;
176 if ( findIter == mEntries.end() )
179 const int entryIndex =
static_cast< int >( std::distance( mEntries.begin(), findIter ) );
180 mEntries[ entryIndex ].image = pixmap;
181 emit dataChanged(
index( entryIndex, 0, QModelIndex() ),
index( entryIndex, 0, QModelIndex() ) );
190 : QSortFilterProxyModel( parent )
193 setSortCaseSensitivity( Qt::CaseInsensitive );
194 setSourceModel( mModel );
195 setDynamicSortFilter(
true );
205 if ( leftSticky && !rightSticky )
207 if ( rightSticky && !leftSticky )
213 return rightKey < leftKey;
A model for published QGIS news feeds.
@ ImageUrl
Optional entry image URL.
@ Link
Optional entry URL link.
@ Image
Optional entry image.
@ Sticky
Whether entry is sticky.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
QgsNewsFeedModel(QgsNewsFeedParser *parser, QObject *parent=nullptr)
Constructor for QgsNewsFeedModel, with the specified parent object.
QHash< int, QByteArray > roleNames() const override
QModelIndex parent(const QModelIndex &index) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Represents a single entry from a news feed.
QString content
HTML content of news entry.
bool sticky
true if entry is "sticky" and should always be shown at the top
QUrl link
Optional URL link for entry.
QString imageUrl
Optional URL for image associated with entry.
QPixmap image
Optional image data.
int key
Unique entry identifier.
QString title
Entry title.
Parser for published QGIS news feeds.
void entryDismissed(const QgsNewsFeedParser::Entry &entry)
Emitted whenever an entry is dismissed (as a result of a call to dismissEntry()).
void entryUpdated(const QgsNewsFeedParser::Entry &entry)
Emitted whenever an existing entry is available from the feed (as a result of a call to fetch()).
void entryAdded(const QgsNewsFeedParser::Entry &entry)
Emitted whenever a new entry is available from the feed (as a result of a call to fetch()).
void imageFetched(int key, const QPixmap &pixmap)
Emitted when the image attached to the entry with the specified key has been fetched and is now avail...
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
QgsNewsFeedProxyModel(QgsNewsFeedParser *parser, QObject *parent=nullptr)
Constructor for QgsNewsFeedProxyModel, with the specified parent object.