simplified the addIfUnique mechanism in NewsFeed by using a data-based identifier for items

This commit is contained in:
csoler 2019-12-03 22:30:13 +01:00
parent fcbecbaa16
commit b85be7cc8e
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
21 changed files with 62 additions and 165 deletions

View file

@ -476,14 +476,13 @@ void RSFeedWidget::withAll(RSFeedWidgetCallbackFunction callback, void *data)
}
}
FeedItem *RSFeedWidget::findFeedItem(RSFeedWidgetFindCallbackFunction callback, void *data)
FeedItem *RSFeedWidget::findFeedItem(const QString& identifier)
{
if (!callback) {
return NULL;
}
QTreeWidgetItemIterator it(ui->treeWidget);
QTreeWidgetItem *treeItem;
// this search could probably be automatised by giving the tree items the identifier as data for some specific role, then calling QTreeWidget::findItems()
#warning TODO
while ((treeItem = *it) != NULL) {
++it;
@ -492,9 +491,8 @@ FeedItem *RSFeedWidget::findFeedItem(RSFeedWidgetFindCallbackFunction callback,
continue;
}
if (callback(feedItem, data)) {
if (feedItem->uniqueIdentifier() == identifier)
return feedItem;
}
}
return NULL;

View file

@ -71,7 +71,7 @@ public:
bool scrollTo(FeedItem *feedItem, bool focus);
void withAll(RSFeedWidgetCallbackFunction callback, void *data);
FeedItem *findFeedItem(RSFeedWidgetFindCallbackFunction callback, void *data);
FeedItem *findFeedItem(const QString &identifier);
void selectedFeedItems(QList<FeedItem*> &feedItems);