From bdfa412b14174e7e81b899ae8323fc78ddd7916e Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 14 Apr 2023 13:09:35 +0200 Subject: Examples: Automatically enable showing categories for Qt >= 6.5.1 Supposedly that is the version that will have a sensible amount of examples sorted into categories to not look weird. It is still possible to force showing the categories with QTC_USE_EXAMPLE_CATEGORIES. Fixes: QTCREATORBUG-28546 Change-Id: Ia1e6afa97d9b1b86763c29209fcf6f674d0844f5 Reviewed-by: Christian Stenger Reviewed-by: --- src/plugins/qtsupport/exampleslistmodel.cpp | 38 ++++++++++++++++++++--------- src/plugins/qtsupport/exampleslistmodel.h | 8 +++++- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/plugins/qtsupport/exampleslistmodel.cpp b/src/plugins/qtsupport/exampleslistmodel.cpp index c567f992e4..d3cf3535dd 100644 --- a/src/plugins/qtsupport/exampleslistmodel.cpp +++ b/src/plugins/qtsupport/exampleslistmodel.cpp @@ -44,6 +44,7 @@ static bool debugExamples() } static const char kSelectedExampleSetKey[] = "WelcomePage/SelectedExampleSet"; +Q_GLOBAL_STATIC_WITH_ARGS(QVersionNumber, minQtVersionForCategories, (6, 5, 1)); void ExampleSetModel::writeCurrentIdToSettings(int currentIndex) const { @@ -117,7 +118,7 @@ void ExampleSetModel::recreateModel(const QtVersions &qtVersions) beginResetModel(); clear(); - QSet extraManifestDirs; + QHash extraManifestDirs; for (int i = 0; i < m_extraExampleSets.size(); ++i) { const ExtraExampleSet &set = m_extraExampleSets.at(i); auto newItem = new QStandardItem(); @@ -127,14 +128,19 @@ void ExampleSetModel::recreateModel(const QtVersions &qtVersions) newItem->setData(i, Qt::UserRole + 3); appendRow(newItem); - extraManifestDirs.insert(set.manifestPath); + extraManifestDirs.insert(FilePath::fromUserInput(set.manifestPath), i); } for (QtVersion *version : qtVersions) { - // sanitize away qt versions that have already been added through extra sets - if (extraManifestDirs.contains(version->docsPath().toString())) { + // Sanitize away qt versions that have already been added through extra sets. + // This way we do not have entries for Qt/Android, Qt/Desktop, Qt/MinGW etc pp, + // but only the one "QtX X.Y.Z" entry that is registered as an example set by the installer. + if (extraManifestDirs.contains(version->docsPath())) { + m_extraExampleSets[extraManifestDirs.value(version->docsPath())].qtVersion + = version->qtVersion(); if (debugExamples()) { - qWarning() << "Not showing Qt version because manifest path is already added through InstalledExamples settings:" + qWarning() << "Not showing Qt version because manifest path is already added " + "through InstalledExamples settings:" << version->displayName(); } continue; @@ -330,10 +336,11 @@ static bool sortByHighlightedAndName(ExampleItem *first, ExampleItem *second) } static QList>> getCategories( - const QList &items) + const QList &items, bool sortIntoCategories) { static const QString otherDisplayName = Tr::tr("Other", "Category for all other examples"); - const bool useCategories = qtcEnvironmentVariableIsSet("QTC_USE_EXAMPLE_CATEGORIES"); + const bool useCategories = sortIntoCategories + || qtcEnvironmentVariableIsSet("QTC_USE_EXAMPLE_CATEGORIES"); QList other; QMap> categoryMap; if (useCategories) { @@ -374,10 +381,11 @@ void ExamplesViewController::updateExamples() { QString examplesInstallPath; QString demosInstallPath; + QVersionNumber qtVersion; const QStringList sources = m_exampleSetModel->exampleSources(&examplesInstallPath, - &demosInstallPath); - + &demosInstallPath, + &qtVersion); m_view->clear(); QList items; @@ -414,7 +422,9 @@ void ExamplesViewController::updateExamples() } } - const QList>> sections = getCategories(items); + const bool sortIntoCategories = qtVersion >= *minQtVersionForCategories; + const QList>> sections + = getCategories(items, sortIntoCategories); for (int i = 0; i < sections.size(); ++i) { m_view->addSection({sections.at(i).first, i}, static_container_cast(sections.at(i).second)); @@ -482,7 +492,9 @@ QtVersion *ExampleSetModel::findHighestQtVersion(const QtVersions &versions) con return newVersion; } -QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath, QString *demosInstallPath) +QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath, + QString *demosInstallPath, + QVersionNumber *qtVersion) { QStringList sources; @@ -500,6 +512,8 @@ QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath, QStrin manifestScanPath = exampleSet.manifestPath; examplesPath = exampleSet.examplesPath; demosPath = exampleSet.examplesPath; + if (qtVersion) + *qtVersion = exampleSet.qtVersion; } else if (currentType == ExampleSetModel::QtExampleSet) { const int qtId = getQtId(m_selectedExampleSetIndex); const QtVersions versions = QtVersionManager::versions(); @@ -508,6 +522,8 @@ QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath, QStrin manifestScanPath = version->docsPath().toString(); examplesPath = version->examplesPath().toString(); demosPath = version->demosPath().toString(); + if (qtVersion) + *qtVersion = version->qtVersion(); break; } } diff --git a/src/plugins/qtsupport/exampleslistmodel.h b/src/plugins/qtsupport/exampleslistmodel.h index 0047bf45e3..c444f9bc1e 100644 --- a/src/plugins/qtsupport/exampleslistmodel.h +++ b/src/plugins/qtsupport/exampleslistmodel.h @@ -28,6 +28,10 @@ public: QString displayName; QString manifestPath; QString examplesPath; + // qtVersion is set by recreateModel for extra sets that correspond to actual Qt versions. + // This is needed for the decision to show categories or not based on the Qt version + // (which is not ideal). + QVersionNumber qtVersion; }; static QVector pluginRegisteredExampleSets(); @@ -35,7 +39,9 @@ public: int selectedExampleSet() const { return m_selectedExampleSetIndex; } void selectExampleSet(int index); - QStringList exampleSources(QString *examplesInstallPath, QString *demosInstallPath); + QStringList exampleSources(QString *examplesInstallPath, + QString *demosInstallPath, + QVersionNumber *qtVersion); bool selectedQtSupports(const Utils::Id &target) const; signals: -- cgit v1.2.1