From a98c45f9ba75a4d9ed0a94d0d2619e511c9c312a Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 9 Mar 2023 15:22:24 +0100 Subject: [PATCH] Examples/Marketplace: Move ownership to the "all" products model To allow the same item to appear in multiple categories. Change-Id: Ib957b1fb0d98a28ceeb1d80e9fb497cc2a6b1f48 Reviewed-by: Qt CI Bot Reviewed-by: David Schulz --- src/plugins/coreplugin/welcomepagehelper.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/coreplugin/welcomepagehelper.cpp b/src/plugins/coreplugin/welcomepagehelper.cpp index 0c46ea98f30..d5f09a8c5c6 100644 --- a/src/plugins/coreplugin/welcomepagehelper.cpp +++ b/src/plugins/coreplugin/welcomepagehelper.cpp @@ -637,8 +637,6 @@ SectionedGridView::SectionedGridView(QWidget *parent) { auto allItemsModel = new ListModel(this); allItemsModel->setPixmapFunction(m_pixmapFunction); - // it just "borrows" the items from the section models: - allItemsModel->setOwnsItems(false); m_filteredAllItemsModel = new Core::ListModelFilter(allItemsModel, this); auto area = new QScrollArea(this); @@ -690,6 +688,10 @@ ListModel *SectionedGridView::addSection(const Section §ion, const QListsetPixmapFunction(m_pixmapFunction); + // the sections only keep a weak reference to the items, + // they are owned by the allProducts model, since multiple sections can contain duplicates + // of the same item + model->setOwnsItems(false); model->appendItems(items); auto gridView = new SectionGridView(this); @@ -716,7 +718,11 @@ ListModel *SectionedGridView::addSection(const Section §ion, const QList(m_filteredAllItemsModel->sourceModel()); - allProducts->appendItems(items); + const QSet allItems = toSet(allProducts->items()); + const QList newItems = filtered(items, [&allItems](ListItem *item) { + return !allItems.contains(item); + }); + allProducts->appendItems(newItems); // only show section label(s) if there is more than one section m_sectionLabels.at(0)->setVisible(m_sectionLabels.size() > 1);