From 542ae405fcf8775d68218fd03f153b867f63ba18 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Wed, 20 Dec 2023 09:34:59 +0100 Subject: [PATCH] Welcome: Avoid duplicate examples when searching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Christian Stenger Reviewed-by: --- src/plugins/coreplugin/welcomepagehelper.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/plugins/coreplugin/welcomepagehelper.cpp b/src/plugins/coreplugin/welcomepagehelper.cpp index d80942f13d4..d12e427b2fc 100644 --- a/src/plugins/coreplugin/welcomepagehelper.cpp +++ b/src/plugins/coreplugin/welcomepagehelper.cpp @@ -811,10 +811,24 @@ ListModel *SectionedGridView::addSection(const Section §ion, const QListinsertWidget(position, sectionLabel); vbox->insertWidget(position + 1, gridView); + struct ItemHash + { + std::size_t operator()(ListItem *item) const { return std::hash{}(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 allItems = toSet(m_allItemsModel->items()); - const QList newItems = filtered(items, [&allItems](ListItem *item) { - return !allItems.contains(item); + const QList allItems = m_allItemsModel->items(); + const std::unordered_set uniqueItems{allItems.constBegin(), + allItems.constEnd()}; + const QList newItems = filtered(items, [&uniqueItems](ListItem *item) { + return uniqueItems.find(item) == uniqueItems.end(); }); m_allItemsModel->appendItems(newItems);