forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -44,6 +44,7 @@ static bool debugExamples()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char kSelectedExampleSetKey[] = "WelcomePage/SelectedExampleSet";
|
static const char kSelectedExampleSetKey[] = "WelcomePage/SelectedExampleSet";
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(QVersionNumber, minQtVersionForCategories, (6, 5, 1));
|
||||||
|
|
||||||
void ExampleSetModel::writeCurrentIdToSettings(int currentIndex) const
|
void ExampleSetModel::writeCurrentIdToSettings(int currentIndex) const
|
||||||
{
|
{
|
||||||
@@ -117,7 +118,7 @@ void ExampleSetModel::recreateModel(const QtVersions &qtVersions)
|
|||||||
beginResetModel();
|
beginResetModel();
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
QSet<QString> extraManifestDirs;
|
QHash<FilePath, int> extraManifestDirs;
|
||||||
for (int i = 0; i < m_extraExampleSets.size(); ++i) {
|
for (int i = 0; i < m_extraExampleSets.size(); ++i) {
|
||||||
const ExtraExampleSet &set = m_extraExampleSets.at(i);
|
const ExtraExampleSet &set = m_extraExampleSets.at(i);
|
||||||
auto newItem = new QStandardItem();
|
auto newItem = new QStandardItem();
|
||||||
@@ -127,14 +128,19 @@ void ExampleSetModel::recreateModel(const QtVersions &qtVersions)
|
|||||||
newItem->setData(i, Qt::UserRole + 3);
|
newItem->setData(i, Qt::UserRole + 3);
|
||||||
appendRow(newItem);
|
appendRow(newItem);
|
||||||
|
|
||||||
extraManifestDirs.insert(set.manifestPath);
|
extraManifestDirs.insert(FilePath::fromUserInput(set.manifestPath), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (QtVersion *version : qtVersions) {
|
for (QtVersion *version : qtVersions) {
|
||||||
// sanitize away qt versions that have already been added through extra sets
|
// Sanitize away qt versions that have already been added through extra sets.
|
||||||
if (extraManifestDirs.contains(version->docsPath().toString())) {
|
// 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()) {
|
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();
|
<< version->displayName();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -330,10 +336,11 @@ static bool sortByHighlightedAndName(ExampleItem *first, ExampleItem *second)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static QList<std::pair<QString, QList<ExampleItem *>>> getCategories(
|
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");
|
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;
|
QList<ExampleItem *> other;
|
||||||
QMap<QString, QList<ExampleItem *>> categoryMap;
|
QMap<QString, QList<ExampleItem *>> categoryMap;
|
||||||
if (useCategories) {
|
if (useCategories) {
|
||||||
@@ -374,10 +381,11 @@ void ExamplesViewController::updateExamples()
|
|||||||
{
|
{
|
||||||
QString examplesInstallPath;
|
QString examplesInstallPath;
|
||||||
QString demosInstallPath;
|
QString demosInstallPath;
|
||||||
|
QVersionNumber qtVersion;
|
||||||
|
|
||||||
const QStringList sources = m_exampleSetModel->exampleSources(&examplesInstallPath,
|
const QStringList sources = m_exampleSetModel->exampleSources(&examplesInstallPath,
|
||||||
&demosInstallPath);
|
&demosInstallPath,
|
||||||
|
&qtVersion);
|
||||||
m_view->clear();
|
m_view->clear();
|
||||||
|
|
||||||
QList<ExampleItem *> items;
|
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) {
|
for (int i = 0; i < sections.size(); ++i) {
|
||||||
m_view->addSection({sections.at(i).first, i},
|
m_view->addSection({sections.at(i).first, i},
|
||||||
static_container_cast<ListItem *>(sections.at(i).second));
|
static_container_cast<ListItem *>(sections.at(i).second));
|
||||||
@@ -482,7 +492,9 @@ QtVersion *ExampleSetModel::findHighestQtVersion(const QtVersions &versions) con
|
|||||||
return newVersion;
|
return newVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath, QString *demosInstallPath)
|
QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath,
|
||||||
|
QString *demosInstallPath,
|
||||||
|
QVersionNumber *qtVersion)
|
||||||
{
|
{
|
||||||
QStringList sources;
|
QStringList sources;
|
||||||
|
|
||||||
@@ -500,6 +512,8 @@ QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath, QStrin
|
|||||||
manifestScanPath = exampleSet.manifestPath;
|
manifestScanPath = exampleSet.manifestPath;
|
||||||
examplesPath = exampleSet.examplesPath;
|
examplesPath = exampleSet.examplesPath;
|
||||||
demosPath = exampleSet.examplesPath;
|
demosPath = exampleSet.examplesPath;
|
||||||
|
if (qtVersion)
|
||||||
|
*qtVersion = exampleSet.qtVersion;
|
||||||
} else if (currentType == ExampleSetModel::QtExampleSet) {
|
} else if (currentType == ExampleSetModel::QtExampleSet) {
|
||||||
const int qtId = getQtId(m_selectedExampleSetIndex);
|
const int qtId = getQtId(m_selectedExampleSetIndex);
|
||||||
const QtVersions versions = QtVersionManager::versions();
|
const QtVersions versions = QtVersionManager::versions();
|
||||||
@@ -508,6 +522,8 @@ QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath, QStrin
|
|||||||
manifestScanPath = version->docsPath().toString();
|
manifestScanPath = version->docsPath().toString();
|
||||||
examplesPath = version->examplesPath().toString();
|
examplesPath = version->examplesPath().toString();
|
||||||
demosPath = version->demosPath().toString();
|
demosPath = version->demosPath().toString();
|
||||||
|
if (qtVersion)
|
||||||
|
*qtVersion = version->qtVersion();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,10 @@ public:
|
|||||||
QString displayName;
|
QString displayName;
|
||||||
QString manifestPath;
|
QString manifestPath;
|
||||||
QString examplesPath;
|
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();
|
static QVector<ExtraExampleSet> pluginRegisteredExampleSets();
|
||||||
|
|
||||||
@@ -35,7 +39,9 @@ public:
|
|||||||
|
|
||||||
int selectedExampleSet() const { return m_selectedExampleSetIndex; }
|
int selectedExampleSet() const { return m_selectedExampleSetIndex; }
|
||||||
void selectExampleSet(int index);
|
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;
|
bool selectedQtSupports(const Utils::Id &target) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
Reference in New Issue
Block a user