QtSupport: Introduce a type alias for QList<BaseQtVersion *>

Change-Id: I96b0eccc04da2f4a1a4e5ea9bdceb91b3fa3d724
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-01-24 13:25:48 +01:00
parent 761e1fb13f
commit a48a96e05c
10 changed files with 44 additions and 43 deletions

View File

@@ -1003,7 +1003,7 @@ QVersionNumber AndroidConfig::ndkVersion(const FilePath &ndkPath) const
QStringList AndroidConfig::allEssentials() const QStringList AndroidConfig::allEssentials() const
{ {
QList<QtVersion *> installedVersions = QtVersionManager::versions( QtVersions installedVersions = QtVersionManager::versions(
[](const QtVersion *v) { [](const QtVersion *v) {
return v->targetDeviceTypes().contains(Android::Constants::ANDROID_DEVICE_TYPE); return v->targetDeviceTypes().contains(Android::Constants::ANDROID_DEVICE_TYPE);
}); });

View File

@@ -267,7 +267,7 @@ public:
void setSearchPaths(const FilePaths &searchPaths) { m_searchPaths = searchPaths; } void setSearchPaths(const FilePaths &searchPaths) { m_searchPaths = searchPaths; }
private: private:
QList<QtVersion *> autoDetectQtVersions() const; QtVersions autoDetectQtVersions() const;
QList<ToolChain *> autoDetectToolChains(); QList<ToolChain *> autoDetectToolChains();
void autoDetectCMake(); void autoDetectCMake();
void autoDetectDebugger(); void autoDetectDebugger();
@@ -704,9 +704,9 @@ void KitDetectorPrivate::listAutoDetected() const
emit q->logOutput('\n' + tr("Listing of previously auto-detected kit items finished.") + "\n\n"); emit q->logOutput('\n' + tr("Listing of previously auto-detected kit items finished.") + "\n\n");
} }
QList<QtVersion *> KitDetectorPrivate::autoDetectQtVersions() const QtVersions KitDetectorPrivate::autoDetectQtVersions() const
{ {
QList<QtVersion *> qtVersions; QtVersions qtVersions;
QString error; QString error;
const QStringList candidates = {"qmake-qt6", "qmake-qt5", "qmake"}; const QStringList candidates = {"qmake-qt6", "qmake-qt5", "qmake"};
@@ -794,7 +794,7 @@ void KitDetectorPrivate::autoDetect()
emit q->logOutput(tr("Starting auto-detection. This will take a while...")); emit q->logOutput(tr("Starting auto-detection. This will take a while..."));
QList<ToolChain *> toolChains = autoDetectToolChains(); QList<ToolChain *> toolChains = autoDetectToolChains();
QList<QtVersion *> qtVersions = autoDetectQtVersions(); QtVersions qtVersions = autoDetectQtVersions();
autoDetectCMake(); autoDetectCMake();
autoDetectDebugger(); autoDetectDebugger();

View File

@@ -750,7 +750,7 @@ Tasks QmakeProject::projectIssues(const Kit *k) const
// example shipped via the installer. // example shipped via the installer.
// Report a problem if and only if the project is considered to be part of *only* a Qt // Report a problem if and only if the project is considered to be part of *only* a Qt
// that is not the one from the current kit. // that is not the one from the current kit.
const QList<QtVersion *> qtsContainingThisProject const QtVersions qtsContainingThisProject
= QtVersionManager::versions([filePath = projectFilePath()](const QtVersion *qt) { = QtVersionManager::versions([filePath = projectFilePath()](const QtVersion *qt) {
return qt->isValid() && qt->isQtSubProject(filePath); return qt->isValid() && qt->isQtSubProject(filePath);
}); });

View File

@@ -270,6 +270,8 @@ private:
Internal::QtVersionPrivate *d = nullptr; Internal::QtVersionPrivate *d = nullptr;
}; };
using QtVersions = QList<QtVersion *>;
} // QtSupport } // QtSupport
Q_DECLARE_OPERATORS_FOR_FLAGS(QtSupport::QtVersion::QmakeBuildConfigs) Q_DECLARE_OPERATORS_FOR_FLAGS(QtSupport::QtVersion::QmakeBuildConfigs)

View File

@@ -119,7 +119,7 @@ ExampleSetModel::ExampleSetModel()
&ExampleSetModel::helpManagerInitialized); &ExampleSetModel::helpManagerInitialized);
} }
void ExampleSetModel::recreateModel(const QList<QtVersion *> &qtVersions) void ExampleSetModel::recreateModel(const QtVersions &qtVersions)
{ {
beginResetModel(); beginResetModel();
clear(); clear();
@@ -525,7 +525,7 @@ QPixmap ExamplesListModel::fetchPixmapAndUpdatePixmapCache(const QString &url) c
void ExampleSetModel::updateQtVersionList() void ExampleSetModel::updateQtVersionList()
{ {
QList<QtVersion *> versions = QtVersionManager::sortVersions(QtVersionManager::versions( QtVersions versions = QtVersionManager::sortVersions(QtVersionManager::versions(
[](const QtVersion *v) { return v->hasExamples() || v->hasDemos(); })); [](const QtVersion *v) { return v->hasExamples() || v->hasDemos(); }));
// prioritize default qt version // prioritize default qt version
@@ -559,7 +559,7 @@ void ExampleSetModel::updateQtVersionList()
emit selectedExampleSetChanged(currentIndex); emit selectedExampleSetChanged(currentIndex);
} }
QtVersion *ExampleSetModel::findHighestQtVersion(const QList<QtVersion *> &versions) const QtVersion *ExampleSetModel::findHighestQtVersion(const QtVersions &versions) const
{ {
QtVersion *newVersion = nullptr; QtVersion *newVersion = nullptr;
for (QtVersion *version : versions) { for (QtVersion *version : versions) {

View File

@@ -80,10 +80,10 @@ private:
int getQtId(int index) const; int getQtId(int index) const;
int getExtraExampleSetIndex(int index) const; int getExtraExampleSetIndex(int index) const;
QtVersion *findHighestQtVersion(const QList<QtVersion *> &versions) const; QtVersion *findHighestQtVersion(const QtVersions &versions) const;
int indexForQtVersion(QtVersion *qtVersion) const; int indexForQtVersion(QtVersion *qtVersion) const;
void recreateModel(const QList<QtVersion *> &qtVersions); void recreateModel(const QtVersions &qtVersions);
void updateQtVersionList(); void updateQtVersionList();
void qtVersionManagerLoaded(); void qtVersionManagerLoaded();

View File

@@ -166,7 +166,7 @@ void QtKitAspect::setup(Kit *k)
const Abi tcAbi = ToolChainKitAspect::targetAbi(k); const Abi tcAbi = ToolChainKitAspect::targetAbi(k);
const Id deviceType = DeviceTypeKitAspect::deviceTypeId(k); const Id deviceType = DeviceTypeKitAspect::deviceTypeId(k);
const QList<QtVersion *> matches const QtVersions matches
= QtVersionManager::versions([&tcAbi, &deviceType](const QtVersion *qt) { = QtVersionManager::versions([&tcAbi, &deviceType](const QtVersion *qt) {
return qt->targetDeviceTypes().contains(deviceType) return qt->targetDeviceTypes().contains(deviceType)
&& Utils::contains(qt->qtAbis(), [&tcAbi](const Abi &qtAbi) { && Utils::contains(qt->qtAbis(), [&tcAbi](const Abi &qtAbi) {
@@ -177,14 +177,13 @@ void QtKitAspect::setup(Kit *k)
// An MSVC 2015 toolchain is compatible with an MSVC 2017 Qt, but we prefer an // An MSVC 2015 toolchain is compatible with an MSVC 2017 Qt, but we prefer an
// MSVC 2015 Qt if we find one. // MSVC 2015 Qt if we find one.
const QList<QtVersion *> exactMatches = Utils::filtered(matches, const QtVersions exactMatches = Utils::filtered(matches, [&tcAbi](const QtVersion *qt) {
[&tcAbi](const QtVersion *qt) {
return qt->qtAbis().contains(tcAbi); return qt->qtAbis().contains(tcAbi);
}); });
const QList<QtVersion *> &candidates = !exactMatches.empty() ? exactMatches : matches; const QtVersions &candidates = !exactMatches.empty() ? exactMatches : matches;
QtVersion * const qtFromPath = QtVersionManager::version( QtVersion * const qtFromPath = QtVersionManager::version(
equal(&QtVersion::detectionSource, QString::fromLatin1("PATH"))); equal(&QtVersion::detectionSource, QString("PATH")));
if (qtFromPath && candidates.contains(qtFromPath)) if (qtFromPath && candidates.contains(qtFromPath))
k->setValue(id(), qtFromPath->uniqueId()); k->setValue(id(), qtFromPath->uniqueId());
else else
@@ -193,10 +192,10 @@ void QtKitAspect::setup(Kit *k)
Tasks QtKitAspect::validate(const Kit *k) const Tasks QtKitAspect::validate(const Kit *k) const
{ {
QTC_ASSERT(QtVersionManager::isLoaded(), return { }); QTC_ASSERT(QtVersionManager::isLoaded(), return {});
QtVersion *version = qtVersion(k); QtVersion *version = qtVersion(k);
if (!version) if (!version)
return { }; return {};
return version->validateKit(k); return version->validateKit(k);
} }

View File

@@ -883,7 +883,7 @@ void QtOptionsPageWidget::apply()
QtVersionManager::setDocumentationSetting( QtVersionManager::setDocumentationSetting(
QtVersionManager::DocumentationSetting(m_ui.documentationSetting->currentData().toInt())); QtVersionManager::DocumentationSetting(m_ui.documentationSetting->currentData().toInt()));
QList<QtVersion *> versions; QtVersions versions;
m_model->forItemsAtLevel<2>([&versions](QtVersionItem *item) { m_model->forItemsAtLevel<2>([&versions](QtVersionItem *item) {
item->setChanged(false); item->setChanged(false);
versions.append(item->version()->clone()); versions.append(item->version()->clone());

View File

@@ -153,7 +153,7 @@ void QtVersionManager::triggerQtVersionRestore()
FileSystemWatcher::WatchModifiedDate); FileSystemWatcher::WatchModifiedDate);
} // exists } // exists
const QList<QtVersion *> vs = versions(); const QtVersions vs = versions();
updateDocumentation(vs, {}, vs); updateDocumentation(vs, {}, vs);
} }
@@ -501,13 +501,13 @@ static QList<std::pair<Path, FileName>> documentationFiles(QtVersion *v)
return files; return files;
} }
static QStringList documentationFiles(const QList<QtVersion *> &vs, bool highestOnly = false) static QStringList documentationFiles(const QtVersions &vs, bool highestOnly = false)
{ {
// if highestOnly is true, register each file only once per major Qt version, even if // if highestOnly is true, register each file only once per major Qt version, even if
// multiple minor or patch releases of that major version are installed // multiple minor or patch releases of that major version are installed
QHash<int, QSet<QString>> includedFileNames; // major Qt version -> names QHash<int, QSet<QString>> includedFileNames; // major Qt version -> names
QSet<QString> filePaths; QSet<QString> filePaths;
const QList<QtVersion *> versions = highestOnly ? QtVersionManager::sortVersions(vs) : vs; const QtVersions versions = highestOnly ? QtVersionManager::sortVersions(vs) : vs;
for (QtVersion *v : versions) { for (QtVersion *v : versions) {
const int majorVersion = v->qtVersion().majorVersion; const int majorVersion = v->qtVersion().majorVersion;
QSet<QString> &majorVersionFileNames = includedFileNames[majorVersion]; QSet<QString> &majorVersionFileNames = includedFileNames[majorVersion];
@@ -521,9 +521,9 @@ static QStringList documentationFiles(const QList<QtVersion *> &vs, bool highest
return filePaths.values(); return filePaths.values();
} }
void QtVersionManager::updateDocumentation(const QList<QtVersion *> &added, void QtVersionManager::updateDocumentation(const QtVersions &added,
const QList<QtVersion *> &removed, const QtVersions &removed,
const QList<QtVersion *> &allNew) const QtVersions &allNew)
{ {
const DocumentationSetting setting = documentationSetting(); const DocumentationSetting setting = documentationSetting();
const QStringList docsOfAll = setting == DocumentationSetting::None const QStringList docsOfAll = setting == DocumentationSetting::None
@@ -548,18 +548,18 @@ int QtVersionManager::getUniqueId()
return m_idcount++; return m_idcount++;
} }
QList<QtVersion *> QtVersionManager::versions(const QtVersion::Predicate &predicate) QtVersions QtVersionManager::versions(const QtVersion::Predicate &predicate)
{ {
QList<QtVersion *> versions; QtVersions versions;
QTC_ASSERT(isLoaded(), return versions); QTC_ASSERT(isLoaded(), return versions);
if (predicate) if (predicate)
return Utils::filtered(m_versions.values(), predicate); return Utils::filtered(m_versions.values(), predicate);
return m_versions.values(); return m_versions.values();
} }
QList<QtVersion *> QtVersionManager::sortVersions(const QList<QtVersion *> &input) QtVersions QtVersionManager::sortVersions(const QtVersions &input)
{ {
QList<QtVersion *> result = input; QtVersions result = input;
Utils::sort(result, qtVersionNumberCompare); Utils::sort(result, qtVersionNumberCompare);
return result; return result;
} }
@@ -584,21 +584,21 @@ static bool equals(QtVersion *a, QtVersion *b)
return a->equals(b); return a->equals(b);
} }
void QtVersionManager::setNewQtVersions(const QList<QtVersion *> &newVersions) void QtVersionManager::setNewQtVersions(const QtVersions &newVersions)
{ {
// We want to preserve the same order as in the settings dialog // We want to preserve the same order as in the settings dialog
// so we sort a copy // so we sort a copy
QList<QtVersion *> sortedNewVersions = newVersions; QtVersions sortedNewVersions = newVersions;
Utils::sort(sortedNewVersions, &QtVersion::uniqueId); Utils::sort(sortedNewVersions, &QtVersion::uniqueId);
QList<QtVersion *> addedVersions; QtVersions addedVersions;
QList<QtVersion *> removedVersions; QtVersions removedVersions;
QList<std::pair<QtVersion *, QtVersion *>> changedVersions; QList<std::pair<QtVersion *, QtVersion *>> changedVersions;
// So we trying to find the minimal set of changed versions, // So we trying to find the minimal set of changed versions,
// iterate over both sorted list // iterate over both sorted list
// newVersions and oldVersions iterator // newVersions and oldVersions iterator
QList<QtVersion *>::const_iterator nit, nend; QtVersions::const_iterator nit, nend;
VersionMap::const_iterator oit, oend; VersionMap::const_iterator oit, oend;
nit = sortedNewVersions.constBegin(); nit = sortedNewVersions.constBegin();
nend = sortedNewVersions.constEnd(); nend = sortedNewVersions.constEnd();
@@ -633,9 +633,9 @@ void QtVersionManager::setNewQtVersions(const QList<QtVersion *> &newVersions)
} }
if (!changedVersions.isEmpty() || !addedVersions.isEmpty() || !removedVersions.isEmpty()) { if (!changedVersions.isEmpty() || !addedVersions.isEmpty() || !removedVersions.isEmpty()) {
const QList<QtVersion *> changedOldVersions const QtVersions changedOldVersions
= Utils::transform(changedVersions, &std::pair<QtVersion *, QtVersion *>::first); = Utils::transform(changedVersions, &std::pair<QtVersion *, QtVersion *>::first);
const QList<QtVersion *> changedNewVersions const QtVersions changedNewVersions
= Utils::transform(changedVersions, = Utils::transform(changedVersions,
&std::pair<QtVersion *, QtVersion *>::second); &std::pair<QtVersion *, QtVersion *>::second);
updateDocumentation(addedVersions + changedNewVersions, updateDocumentation(addedVersions + changedNewVersions,
@@ -666,7 +666,7 @@ void QtVersionManager::setDocumentationSetting(const QtVersionManager::Documenta
Core::ICore::settings()->setValueWithDefault(DOCUMENTATION_SETTING_KEY, int(setting), 0); Core::ICore::settings()->setValueWithDefault(DOCUMENTATION_SETTING_KEY, int(setting), 0);
// force re-evaluating which documentation should be registered // force re-evaluating which documentation should be registered
// by claiming that all are removed and re-added // by claiming that all are removed and re-added
const QList<QtVersion *> vs = versions(); const QtVersions vs = versions();
updateDocumentation(vs, vs, vs); updateDocumentation(vs, vs, vs);
} }

View File

@@ -53,12 +53,12 @@ public:
// Note: DO NOT STORE THESE POINTERS! // Note: DO NOT STORE THESE POINTERS!
// The QtVersionManager may delete them at random times and you will // The QtVersionManager may delete them at random times and you will
// need to get a new pointer by calling this function again! // need to get a new pointer by calling this function again!
static QList<QtVersion *> versions(const QtVersion::Predicate &predicate = QtVersion::Predicate()); static QtVersions versions(const QtVersion::Predicate &predicate = {});
static QtVersion *version(int id); static QtVersion *version(int id);
static QtVersion *version(const QtVersion::Predicate &predicate); static QtVersion *version(const QtVersion::Predicate &predicate);
// Sorting is potentially expensive since it might require qmake --query to run for each version! // Sorting is potentially expensive since it might require qmake --query to run for each version!
static QList<QtVersion *> sortVersions(const QList<QtVersion *> &input); static QtVersions sortVersions(const QtVersions &input);
static void addVersion(QtVersion *version); static void addVersion(QtVersion *version);
static void removeVersion(QtVersion *version); static void removeVersion(QtVersion *version);
@@ -76,14 +76,14 @@ signals:
private: private:
enum class DocumentationSetting { HighestOnly, All, None }; enum class DocumentationSetting { HighestOnly, All, None };
static void updateDocumentation(const QList<QtVersion *> &added, static void updateDocumentation(const QtVersions &added,
const QList<QtVersion *> &removed, const QtVersions &removed,
const QList<QtVersion *> &allNew); const QtVersions &allNew);
void updateFromInstaller(bool emitSignal = true); void updateFromInstaller(bool emitSignal = true);
void triggerQtVersionRestore(); void triggerQtVersionRestore();
// Used by QtOptionsPage // Used by QtOptionsPage
static void setNewQtVersions(const QList<QtVersion *> &newVersions); static void setNewQtVersions(const QtVersions &newVersions);
static void setDocumentationSetting(const DocumentationSetting &setting); static void setDocumentationSetting(const DocumentationSetting &setting);
static DocumentationSetting documentationSetting(); static DocumentationSetting documentationSetting();
// Used by QtVersion // Used by QtVersion