summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2023-04-14 13:09:35 +0200
committerEike Ziller <eike.ziller@qt.io>2023-04-17 09:13:56 +0000
commitbdfa412b14174e7e81b899ae8323fc78ddd7916e (patch)
tree8b54bcd9ad3a80f33ca002455f1b161513ce9b85
parent81b294d1b1ff572aec309edd9e02f7da615315b3 (diff)
downloadqt-creator-bdfa412b14174e7e81b899ae8323fc78ddd7916e.tar.gz
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 <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
-rw-r--r--src/plugins/qtsupport/exampleslistmodel.cpp38
-rw-r--r--src/plugins/qtsupport/exampleslistmodel.h8
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<QString> extraManifestDirs;
+ QHash<FilePath, int> 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<std::pair<QString, QList<ExampleItem *>>> getCategories(
- const QList<ExampleItem *> &items)
+ const QList<ExampleItem *> &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<ExampleItem *> other;
QMap<QString, QList<ExampleItem *>> 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<ExampleItem *> items;
@@ -414,7 +422,9 @@ void ExamplesViewController::updateExamples()
}
}
- const QList<std::pair<QString, QList<ExampleItem *>>> sections = getCategories(items);
+ const bool sortIntoCategories = qtVersion >= *minQtVersionForCategories;
+ const QList<std::pair<QString, QList<ExampleItem *>>> sections
+ = getCategories(items, sortIntoCategories);
for (int i = 0; i < sections.size(); ++i) {
m_view->addSection({sections.at(i).first, i},
static_container_cast<ListItem *>(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<ExtraExampleSet> 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: