forked from qt-creator/qt-creator
Welcome: Avoid duplicate examples when searching
When adding examples for a category/section we also add them to the list of all examples. To avoid ownership issues we duplicate examples when they appear in multiple categories, but that means that the existing mechanism of filtering duplicates based on item pointer does no longer work. Filter duplicates based on name+description. It would possibly be nicer to give the examples IDs (serial numbers) when reading them and just using that for filtering duplicates, but that isn't possible in a binary compatible manner atm. Fixes: QTCREATORBUG-30069 Change-Id: I0ee9ef7b86955af5ee8ccdb9c5683ced81097671 Reviewed-by: Kai Köhne <kai.koehne@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -811,10 +811,24 @@ ListModel *SectionedGridView::addSection(const Section §ion, const QList<Lis
|
||||
vbox->insertWidget(position, sectionLabel);
|
||||
vbox->insertWidget(position + 1, gridView);
|
||||
|
||||
struct ItemHash
|
||||
{
|
||||
std::size_t operator()(ListItem *item) const { return std::hash<QString>{}(item->name); }
|
||||
};
|
||||
struct ItemEqual
|
||||
{
|
||||
bool operator()(ListItem *lhs, ListItem *rhs) const
|
||||
{
|
||||
return lhs->name == rhs->name && lhs->description == rhs->description;
|
||||
}
|
||||
};
|
||||
|
||||
// add the items also to the all products model to be able to search correctly
|
||||
const QSet<ListItem *> allItems = toSet(m_allItemsModel->items());
|
||||
const QList<ListItem *> newItems = filtered(items, [&allItems](ListItem *item) {
|
||||
return !allItems.contains(item);
|
||||
const QList<ListItem *> allItems = m_allItemsModel->items();
|
||||
const std::unordered_set<ListItem *, ItemHash, ItemEqual> uniqueItems{allItems.constBegin(),
|
||||
allItems.constEnd()};
|
||||
const QList<ListItem *> newItems = filtered(items, [&uniqueItems](ListItem *item) {
|
||||
return uniqueItems.find(item) == uniqueItems.end();
|
||||
});
|
||||
m_allItemsModel->appendItems(newItems);
|
||||
|
||||
|
Reference in New Issue
Block a user