QtSupport: Replace foreach with range-based for loops

Change-Id: Ia941c8dec41a73ca126c91304223d1fe98bc2972
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-11-23 22:27:42 +01:00
parent 849c902971
commit 6a20c52cc9
4 changed files with 20 additions and 17 deletions

View File

@@ -875,7 +875,7 @@ QString QtVersion::toHtml(bool verbose) const
const QHash<ProKey, ProString> vInfo = d->versionInfo();
if (!vInfo.isEmpty()) {
const QList<ProKey> keys = Utils::sorted(vInfo.keys());
foreach (const ProKey &key, keys) {
for (const ProKey &key : keys) {
const QString &value = vInfo.value(key).toQString();
QString variableName = key.toQString();
if (variableName != "QMAKE_MKSPECS"
@@ -2281,7 +2281,7 @@ QtVersion *QtVersionFactory::createQtVersionFromQMakePath
setup.platforms = evaluator.values("QMAKE_PLATFORM"); // It's a list in general.
setup.isQnx = !evaluator.value("QNX_CPUDIR").isEmpty();
foreach (QtVersionFactory *factory, factories) {
for (QtVersionFactory *factory : factories) {
if (!factory->m_restrictionChecker || factory->m_restrictionChecker(setup)) {
QtVersion *ver = factory->create();
QTC_ASSERT(ver, continue);

View File

@@ -126,7 +126,7 @@ void ExampleSetModel::recreateModel(const QtVersions &qtVersions)
extraManifestDirs.insert(set.manifestPath);
}
foreach (QtVersion *version, qtVersions) {
for (QtVersion *version : qtVersions) {
// sanitize away qt versions that have already been added through extra sets
if (extraManifestDirs.contains(version->docsPath().toString())) {
if (debugExamples()) {
@@ -446,13 +446,13 @@ void ExamplesListModel::updateExamples()
QString examplesInstallPath;
QString demosInstallPath;
QStringList sources = m_exampleSetModel.exampleSources(&examplesInstallPath, &demosInstallPath);
const QStringList sources = m_exampleSetModel.exampleSources(&examplesInstallPath,
&demosInstallPath);
beginResetModel();
qDeleteAll(m_items);
m_items.clear();
foreach (const QString &exampleSource, sources) {
for (const QString &exampleSource : sources) {
QFile exampleFile(exampleSource);
if (!exampleFile.open(QIODevice::ReadOnly)) {
if (debugExamples())
@@ -604,8 +604,9 @@ QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath, QStrin
examplesPath = exampleSet.examplesPath;
demosPath = exampleSet.examplesPath;
} else if (currentType == ExampleSetModel::QtExampleSet) {
int qtId = getQtId(m_selectedExampleSetIndex);
foreach (QtVersion *version, QtVersionManager::versions()) {
const int qtId = getQtId(m_selectedExampleSetIndex);
const QtVersions versions = QtVersionManager::versions();
for (QtVersion *version : versions) {
if (version->uniqueId() == qtId) {
manifestScanPath = version->docsPath().toString();
examplesPath = version->examplesPath().toString();
@@ -620,11 +621,12 @@ QStringList ExampleSetModel::exampleSources(QString *examplesInstallPath, QStrin
const QStringList examplesPattern(QLatin1String("examples-manifest.xml"));
const QStringList demosPattern(QLatin1String("demos-manifest.xml"));
QFileInfoList fis;
foreach (QFileInfo subDir, dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
const QFileInfoList subDirs = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
for (QFileInfo subDir : subDirs) {
fis << QDir(subDir.absoluteFilePath()).entryInfoList(examplesPattern);
fis << QDir(subDir.absoluteFilePath()).entryInfoList(demosPattern);
}
foreach (const QFileInfo &fi, fis)
for (const QFileInfo &fi : std::as_const(fis))
sources.append(fi.filePath());
}
if (examplesInstallPath)

View File

@@ -414,7 +414,6 @@ void QtOptionsPageWidget::cleanUpQtVersions()
if (toRemove.isEmpty())
return;
if (QMessageBox::warning(nullptr, Tr::tr("Remove Invalid Qt Versions"),
Tr::tr("Do you want to remove all invalid Qt Versions?<br>"
"<ul><li>%1</li></ul><br>"
@@ -422,7 +421,7 @@ void QtOptionsPageWidget::cleanUpQtVersions()
QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
return;
foreach (QtVersionItem *item, toRemove)
for (QtVersionItem *item : std::as_const(toRemove))
m_model->destroyItem(item);
updateCleanUpButton();
@@ -531,8 +530,10 @@ QList<ToolChain*> QtOptionsPageWidget::toolChains(const QtVersion *version)
return toolChains;
QSet<QByteArray> ids;
foreach (const Abi &a, version->qtAbis()) {
foreach (ToolChain *tc, ToolChainManager::findToolChains(a)) {
const Abis abis = version->qtAbis();
for (const Abi &a : abis) {
const Toolchains tcList = ToolChainManager::findToolChains(a);
for (ToolChain *tc : tcList) {
if (ids.contains(tc->id()))
continue;
ids.insert(tc->id());
@@ -591,11 +592,11 @@ void QtOptionsPageWidget::updateQtVersions(const QList<int> &additions, const QL
});
// Remove changed/removed items:
foreach (QtVersionItem *item, toRemove)
for (QtVersionItem *item : std::as_const(toRemove))
m_model->destroyItem(item);
// Add changed/added items:
foreach (int a, toAdd) {
for (int a : std::as_const(toAdd)) {
QtVersion *version = QtVersionManager::version(a)->clone();
auto *item = new QtVersionItem(version);

View File

@@ -613,7 +613,7 @@ void QtSupportPlugin::testQtProjectImporter_oneProject()
qDeleteAll(testData);
foreach (Kit *k, toUnregisterLater)
for (Kit *k : std::as_const(toUnregisterLater))
KitManager::deregisterKit(k);
// Delete kit templates: