24 : QAbstractItemModel( parent )
28 const QList< QgsNewsFeedParser::Entry > initialEntries = mParser->
entries();
39 if ( index.row() < 0 || index.row() >=
rowCount( QModelIndex() ) )
69 case Qt::DecorationRole:
70 if ( entry.
image.isNull() )
79 Qt::ItemFlags
flags = QAbstractItemModel::flags( index );
85 if ( !hasIndex( row, column, parent ) )
88 if ( !parent.isValid() )
90 return createIndex( row, column );
104 if ( !parent.isValid() )
106 return mEntries.count();
118 beginInsertRows( QModelIndex(), mEntries.count(), mEntries.count() );
119 mEntries.append( entry );
126 auto findIter = std::find_if( mEntries.begin(), mEntries.end(), [entry](
const QgsNewsFeedParser::Entry & candidate )
128 return candidate.key == entry.
key;
130 if ( findIter == mEntries.end() )
133 const int entryIndex =
static_cast< int >( std::distance( mEntries.begin(), findIter ) );
134 beginRemoveRows( QModelIndex(), entryIndex, entryIndex );
135 mEntries.removeAt( entryIndex );
139 void QgsNewsFeedModel::onImageFetched(
const int key,
const QPixmap &pixmap )
144 return candidate.key == key;
146 if ( findIter == mEntries.end() )
149 const int entryIndex =
static_cast< int >( std::distance( mEntries.begin(), findIter ) );
150 mEntries[ entryIndex ].image = pixmap;
151 emit dataChanged(
index( entryIndex, 0, QModelIndex() ),
index( entryIndex, 0, QModelIndex() ) );
160 : QSortFilterProxyModel( parent )
163 setSortCaseSensitivity( Qt::CaseInsensitive );
164 setSourceModel( mModel );
165 setDynamicSortFilter(
true );
175 if ( leftSticky && !rightSticky )
177 if ( rightSticky && !leftSticky )
183 return rightKey < leftKey;
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QgsNewsFeedModel(QgsNewsFeedParser *parser, QObject *parent=nullptr)
Constructor for QgsNewsFeedModel, with the specified parent object.
void entryDismissed(const QgsNewsFeedParser::Entry &entry)
Emitted whenever an entry is dismissed (as a result of a call to dismissEntry()). ...
Represents a single entry from a news feed.
Qt::ItemFlags flags(const QModelIndex &index) const override
QModelIndex parent(const QModelIndex &index) const override
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
void entryAdded(const QgsNewsFeedParser::Entry &entry)
Emitted whenever a new entry is available from the feed (as a result of a call to fetch())...
Parser for published QGIS news feeds.
bool sticky
true if entry is "sticky" and should always be shown at the top
QString content
HTML content of news entry.
Optional entry image URL.
QString title
Entry title.
QString imageUrl
Optional URL for image associated with entry.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
int key
Unique entry identifier.
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...
QgsNewsFeedProxyModel(QgsNewsFeedParser *parser, QObject *parent=nullptr)
Constructor for QgsNewsFeedProxyModel, with the specified parent object.
A model for published QGIS news feeds.
QUrl link
Optional URL link for entry.
QList< QgsNewsFeedParser::Entry > entries() const
Returns a list of existing entries in the feed.
QVariant data(const QModelIndex &index, int role) const override
QPixmap image
Optional image data.