diff --git a/src/plugins/coreplugin/welcomepagehelper.cpp b/src/plugins/coreplugin/welcomepagehelper.cpp index 534888e5439..2da25822643 100644 --- a/src/plugins/coreplugin/welcomepagehelper.cpp +++ b/src/plugins/coreplugin/welcomepagehelper.cpp @@ -144,9 +144,7 @@ ListModel::ListModel(QObject *parent) ListModel::~ListModel() { - if (m_ownsItems) - qDeleteAll(m_items); - m_items.clear(); + clear(); } void ListModel::appendItems(const QList &items) @@ -161,6 +159,15 @@ const QList ListModel::items() const return m_items; } +void ListModel::clear() +{ + beginResetModel(); + if (m_ownsItems) + qDeleteAll(m_items); + m_items.clear(); + endResetModel(); +} + int ListModel::rowCount(const QModelIndex &) const { return m_items.size(); @@ -695,6 +702,7 @@ ListModel *SectionedGridView::addSection(const Section §ion, const QListsetContentsMargins(0, Core::WelcomePageHelpers::ItemGap, 0, 0); sectionLabel->setFont(Core::WelcomePageHelpers::brandFont()); auto scrollArea = qobject_cast(widget(0)); @@ -713,4 +721,16 @@ ListModel *SectionedGridView::addSection(const Section §ion, const QList(m_filteredAllItemsModel->sourceModel()); + allProducts->clear(); + qDeleteAll(m_sectionModels); + qDeleteAll(m_sectionLabels); + qDeleteAll(m_gridViews); + m_sectionModels.clear(); + m_sectionLabels.clear(); + m_gridViews.clear(); +} + } // namespace Core diff --git a/src/plugins/coreplugin/welcomepagehelper.h b/src/plugins/coreplugin/welcomepagehelper.h index 353c5a6d3c8..77760000e9e 100644 --- a/src/plugins/coreplugin/welcomepagehelper.h +++ b/src/plugins/coreplugin/welcomepagehelper.h @@ -79,6 +79,7 @@ public: void appendItems(const QList &items); const QList items() const; + void clear(); int rowCount(const QModelIndex &parent = QModelIndex()) const final; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; @@ -88,7 +89,7 @@ public: void setOwnsItems(bool owns); -protected: +private: QList m_items; PixmapFunction m_fetchPixmapAndUpdatePixmapCache; bool m_ownsItems = true; @@ -192,8 +193,11 @@ public: Core::ListModel *addSection(const Section §ion, const QList &items); + void clear(); + private: QMap m_sectionModels; + QList m_sectionLabels; QMap m_gridViews; Core::GridView *m_allItemsView = nullptr; Core::ListModelFilter *m_filteredAllItemsModel = nullptr; diff --git a/src/plugins/qtsupport/exampleslistmodel.cpp b/src/plugins/qtsupport/exampleslistmodel.cpp index d0c85ef241b..cdfc6c872db 100644 --- a/src/plugins/qtsupport/exampleslistmodel.cpp +++ b/src/plugins/qtsupport/exampleslistmodel.cpp @@ -29,6 +29,7 @@ #include #include +using namespace Core; using namespace Utils; namespace QtSupport { @@ -331,9 +332,11 @@ static bool isValidExampleOrDemo(ExampleItem *item) return ok || debugExamples(); } -void ExamplesListModel::parseExamples(QXmlStreamReader *reader, - const QString &projectsOffset, const QString &examplesInstallPath) +static QList parseExamples(QXmlStreamReader *reader, + const QString &projectsOffset, + const QString &examplesInstallPath) { + QList result; std::unique_ptr item; const QChar slash = QLatin1Char('/'); while (!reader->atEnd()) { @@ -374,20 +377,23 @@ void ExamplesListModel::parseExamples(QXmlStreamReader *reader, case QXmlStreamReader::EndElement: if (reader->name() == QLatin1String("example")) { if (isValidExampleOrDemo(item.get())) - m_items.push_back(item.release()); + result.push_back(item.release()); } else if (reader->name() == QLatin1String("examples")) { - return; + return result; } break; default: // nothing break; } } + return result; } -void ExamplesListModel::parseDemos(QXmlStreamReader *reader, - const QString &projectsOffset, const QString &demosInstallPath) +static QList parseDemos(QXmlStreamReader *reader, + const QString &projectsOffset, + const QString &demosInstallPath) { + QList result; std::unique_ptr item; const QChar slash = QLatin1Char('/'); while (!reader->atEnd()) { @@ -419,19 +425,21 @@ void ExamplesListModel::parseDemos(QXmlStreamReader *reader, case QXmlStreamReader::EndElement: if (reader->name() == QLatin1String("demo")) { if (isValidExampleOrDemo(item.get())) - m_items.push_back(item.release()); + result.push_back(item.release()); } else if (reader->name() == QLatin1String("demos")) { - return; + return result; } break; default: // nothing break; } } + return result; } -void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset) +static QList parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset) { + QList result; std::unique_ptr item; const QChar slash = QLatin1Char('/'); while (!reader->atEnd()) { @@ -465,14 +473,15 @@ void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString & break; case QXmlStreamReader::EndElement: if (reader->name() == QLatin1String("tutorial")) - m_items.push_back(item.release()); + result.push_back(item.release()); else if (reader->name() == QLatin1String("tutorials")) - return; + return result; break; default: // nothing break; } } + return result; } void ExamplesListModel::updateExamples() @@ -482,10 +491,10 @@ void ExamplesListModel::updateExamples() const QStringList sources = m_exampleSetModel.exampleSources(&examplesInstallPath, &demosInstallPath); - beginResetModel(); - qDeleteAll(m_items); - m_items.clear(); + clear(); + + QList items; for (const QString &exampleSource : sources) { QFile exampleFile(exampleSource); if (!exampleFile.open(QIODevice::ReadOnly)) { @@ -506,11 +515,11 @@ void ExamplesListModel::updateExamples() switch (reader.readNext()) { case QXmlStreamReader::StartElement: if (reader.name() == QLatin1String("examples")) - parseExamples(&reader, examplesDir.path(), examplesInstallPath); + items += parseExamples(&reader, examplesDir.path(), examplesInstallPath); else if (reader.name() == QLatin1String("demos")) - parseDemos(&reader, demosDir.path(), demosInstallPath); + items += parseDemos(&reader, demosDir.path(), demosInstallPath); else if (reader.name() == QLatin1String("tutorials")) - parseTutorials(&reader, examplesDir.path()); + items += parseTutorials(&reader, examplesDir.path()); break; default: // nothing break; @@ -522,7 +531,7 @@ void ExamplesListModel::updateExamples() << ": " << reader.errorString(); } } - endResetModel(); + appendItems(items); } void ExampleSetModel::updateQtVersionList() diff --git a/src/plugins/qtsupport/exampleslistmodel.h b/src/plugins/qtsupport/exampleslistmodel.h index 5e5535ea550..c64fa9416d3 100644 --- a/src/plugins/qtsupport/exampleslistmodel.h +++ b/src/plugins/qtsupport/exampleslistmodel.h @@ -117,12 +117,6 @@ signals: private: void updateSelectedQtVersion(); - void parseExamples(QXmlStreamReader *reader, const QString &projectsOffset, - const QString &examplesInstallPath); - void parseDemos(QXmlStreamReader *reader, const QString &projectsOffset, - const QString &demosInstallPath); - void parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset); - ExampleSetModel m_exampleSetModel; };