aboutsummaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2017-11-19 13:43:58 +0300
committerJake Petroules <jake.petroules@qt.io>2017-11-24 19:04:25 +0000
commit9757970c477fbd5c81a603b0a5d2106e6db7ca34 (patch)
tree4452a5160a65e61d36e2440b3d9f8c8a9d59329d /src/app
parentb0b50c510024f201ec9fed233659ad1f0cfda684 (diff)
Replace 'foreach' macro with range-based 'for'
Change-Id: I34479bc9673d0202363aeba5c7919efc8f0d7287 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/app')
-rw-r--r--src/app/config/configcommandexecutor.cpp16
-rw-r--r--src/app/qbs-setup-qt/main.cpp4
-rw-r--r--src/app/qbs-setup-qt/setupqt.cpp21
-rw-r--r--src/app/qbs-setup-toolchains/msvcprobe.cpp30
-rw-r--r--src/app/qbs-setup-toolchains/probe.cpp15
-rw-r--r--src/app/qbs/commandlinefrontend.cpp29
-rw-r--r--src/app/qbs/parser/commandlineoption.cpp5
-rw-r--r--src/app/qbs/parser/commandlineparser.cpp18
-rw-r--r--src/app/qbs/parser/parsercommand.cpp9
-rw-r--r--src/app/qbs/qbstool.cpp4
-rw-r--r--src/app/qbs/status.cpp25
11 files changed, 107 insertions, 69 deletions
diff --git a/src/app/config/configcommandexecutor.cpp b/src/app/config/configcommandexecutor.cpp
index c95b43f18..3169a6f24 100644
--- a/src/app/config/configcommandexecutor.cpp
+++ b/src/app/config/configcommandexecutor.cpp
@@ -66,7 +66,7 @@ void ConfigCommandExecutor::execute(const ConfigCommand &command)
setValue(command.varNames.front(), command.varValue);
break;
case ConfigCommand::CfgUnset:
- foreach (const QString &varName, command.varNames)
+ for (const QString &varName : command.varNames)
m_settings->remove(varName);
break;
case ConfigCommand::CfgExport:
@@ -94,14 +94,16 @@ void ConfigCommandExecutor::setValue(const QString &key, const QString &rawInput
void ConfigCommandExecutor::printSettings(const ConfigCommand &command)
{
if (command.varNames.empty()) {
- foreach (const QString &key, m_settings->allKeys())
+ const auto keys = m_settings->allKeys();
+ for (const QString &key : keys)
printOneSetting(key);
} else {
- foreach (const QString &parentKey, command.varNames) {
+ for (const QString &parentKey : command.varNames) {
if (m_settings->value(parentKey).isValid()) { // Key is a leaf.
printOneSetting(parentKey);
} else { // Key is a node.
- foreach (const QString &key, m_settings->allKeysWithPrefix(parentKey))
+ const auto keys = m_settings->allKeysWithPrefix(parentKey);
+ for (const QString &key : keys)
printOneSetting(parentKey + QLatin1Char('.') + key);
}
}
@@ -123,7 +125,8 @@ void ConfigCommandExecutor::exportSettings(const QString &filename)
}
QTextStream stream(&file);
stream.setCodec("UTF-8");
- foreach (const QString &key, m_settings->allKeys())
+ const auto keys = m_settings->allKeys();
+ for (const QString &key : keys)
stream << key << ": " << qbs::settingsValueToRepresentation(m_settings->value(key)) << endl;
}
@@ -135,7 +138,8 @@ void ConfigCommandExecutor::importSettings(const QString &filename)
.arg(QDir::toNativeSeparators(filename), file.errorString()));
}
// Remove all current settings
- foreach (const QString &key, m_settings->allKeys())
+ const auto keys = m_settings->allKeys();
+ for (const QString &key : keys)
m_settings->remove(key);
QTextStream stream(&file);
diff --git a/src/app/qbs-setup-qt/main.cpp b/src/app/qbs-setup-qt/main.cpp
index 92405ab07..d0f78cce6 100644
--- a/src/app/qbs-setup-qt/main.cpp
+++ b/src/app/qbs-setup-qt/main.cpp
@@ -71,13 +71,13 @@ int main(int argc, char *argv[])
if (clParser.autoDetectionMode()) {
// search all Qt's in path and dump their settings
- QList<QtEnvironment> qtEnvironments = SetupQt::fetchEnvironments();
+ const QList<QtEnvironment> qtEnvironments = SetupQt::fetchEnvironments();
if (qtEnvironments.empty()) {
std::cout << qPrintable(Tr::tr("No Qt installations detected. "
"No profiles created."))
<< std::endl;
}
- foreach (const QtEnvironment &qtEnvironment, qtEnvironments) {
+ for (const QtEnvironment &qtEnvironment : qtEnvironments) {
QString profileName = QLatin1String("qt-") + qtEnvironment.qtVersion;
if (SetupQt::checkIfMoreThanOneQtWithTheSameVersion(qtEnvironment.qtVersion, qtEnvironments)) {
QStringList prefixPathParts = qtEnvironment.installPrefixPath
diff --git a/src/app/qbs-setup-qt/setupqt.cpp b/src/app/qbs-setup-qt/setupqt.cpp
index 7c2b4e394..b8cb416dd 100644
--- a/src/app/qbs-setup-qt/setupqt.cpp
+++ b/src/app/qbs-setup-qt/setupqt.cpp
@@ -82,10 +82,10 @@ static QStringList collectQmakePaths()
const QStringList qmakeExeNames = qmakeExecutableNames();
QStringList qmakePaths;
QByteArray environmentPath = qgetenv("PATH");
- QList<QByteArray> environmentPaths
+ const QList<QByteArray> environmentPaths
= environmentPath.split(HostOsInfo::pathListSeparator().toLatin1());
- foreach (const QByteArray &path, environmentPaths) {
- foreach (const QString &qmakeExecutableName, qmakeExeNames) {
+ for (const QByteArray &path : environmentPaths) {
+ for (const QString &qmakeExecutableName : qmakeExeNames) {
QFileInfo pathFileInfo(QDir(QLatin1String(path)), qmakeExecutableName);
if (pathFileInfo.exists()) {
QString qmakePath = pathFileInfo.absoluteFilePath();
@@ -108,7 +108,8 @@ QList<QtEnvironment> SetupQt::fetchEnvironments()
{
QList<QtEnvironment> qtEnvironments;
- foreach (const QString &qmakePath, collectQmakePaths()) {
+ const auto qmakePaths = collectQmakePaths();
+ for (const QString &qmakePath : qmakePaths) {
const QtEnvironment env = fetchEnvironment(qmakePath);
if (std::find_if(qtEnvironments.cbegin(), qtEnvironments.cend(),
[&env](const QtEnvironment &otherEnv) {
@@ -137,7 +138,8 @@ static QMap<QByteArray, QByteArray> qmakeQueryOutput(const QString &qmakePath)
const QByteArray output = qmakeProcess.readAllStandardOutput();
QMap<QByteArray, QByteArray> ret;
- foreach (const QByteArray &line, output.split('\n')) {
+ const auto lines = output.split('\n');
+ for (const QByteArray &line : lines) {
int idx = line.indexOf(':');
if (idx >= 0)
ret[line.left(idx)] = line.mid(idx + 1).trimmed();
@@ -159,11 +161,11 @@ static QString configVariable(const QByteArray &configContent, const QString &ke
QRegExp regexp(QLatin1String("\\s*") + key + QLatin1String("\\s*\\+{0,1}=(.*)"),
Qt::CaseSensitive);
- QList<QByteArray> configContentLines = configContent.split('\n');
+ const QList<QByteArray> configContentLines = configContent.split('\n');
bool success = false;
- foreach (const QByteArray &configContentLine, configContentLines) {
+ for (const QByteArray &configContentLine : configContentLines) {
success = regexp.exactMatch(QString::fromLocal8Bit(configContentLine));
if (success)
break;
@@ -532,7 +534,8 @@ void SetupQt::saveToQbsSettings(const QString &qtVersionName, const QtEnvironmen
QStringList fullMatches;
QStringList partialMatches;
- foreach (const QString &profileName, settings->profiles()) {
+ const auto profileNames = settings->profiles();
+ for (const QString &profileName : profileNames) {
const Profile otherProfile(profileName, settings);
if (profileName == profile.name()
|| !isToolchainProfile(otherProfile)
@@ -584,7 +587,7 @@ bool SetupQt::checkIfMoreThanOneQtWithTheSameVersion(const QString &qtVersion,
const QList<QtEnvironment> &qtEnvironments)
{
bool foundOneVersion = false;
- foreach (const QtEnvironment &qtEnvironment, qtEnvironments) {
+ for (const QtEnvironment &qtEnvironment : qtEnvironments) {
if (qtEnvironment.qtVersion == qtVersion) {
if (foundOneVersion)
return true;
diff --git a/src/app/qbs-setup-toolchains/msvcprobe.cpp b/src/app/qbs-setup-toolchains/msvcprobe.cpp
index 556f127f5..0b3f460b5 100644
--- a/src/app/qbs-setup-toolchains/msvcprobe.cpp
+++ b/src/app/qbs-setup-toolchains/msvcprobe.cpp
@@ -47,6 +47,7 @@
#include <tools/error.h>
#include <tools/msvcinfo.h>
#include <tools/profile.h>
+#include <tools/qttools.h>
#include <tools/settings.h>
#include <tools/version.h>
#include <tools/visualstudioversioninfo.h>
@@ -121,12 +122,14 @@ static std::vector<MSVCArchInfo> findSupportedArchitectures(const MSVC &msvc)
}
} else {
QDir vcInstallDir(msvc.vcInstallPath);
- foreach (QString hostArch, vcInstallDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
+ const auto hostArchs = vcInstallDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+ for (const QString &hostArch : hostArchs) {
QDir subdir = vcInstallDir;
if (!subdir.cd(hostArch))
continue;
const QString shortHostArch = hostArch.mid(4).toLower();
- foreach (const QString &arch, subdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
+ const auto archs = subdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+ for (const QString &arch : archs) {
MSVCArchInfo ai;
ai.binPath = subdir.absoluteFilePath(arch);
if (shortHostArch == arch)
@@ -164,7 +167,8 @@ static std::vector<MSVCRegistryEntry> installedMSVCsFromRegistry()
QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE") + wow6432Key()
+ QStringLiteral("\\Microsoft\\VisualStudio\\SxS\\VS7"),
QSettings::NativeFormat);
- foreach (const QString &vsName, vsRegistry.childKeys()) {
+ const auto vsNames = vsRegistry.childKeys();
+ for (const QString &vsName : vsNames) {
MSVCRegistryEntry entry;
entry.version = vsName;
entry.installDir = vsRegistry.value(vsName).toString();
@@ -231,8 +235,8 @@ static std::vector<MSVC> installedMSVCs()
} else {
QDir vcInstallDir = vsInstallDir;
vcInstallDir.cd(QStringLiteral("Tools/MSVC"));
- foreach (const QString &vcVersionStr,
- vcInstallDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
+ const auto vcVersionStrs = vcInstallDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+ for (const QString &vcVersionStr : vcVersionStrs) {
const Version vcVersion = Version::fromString(vcVersionStr);
if (!vcVersion.isValid())
continue;
@@ -262,7 +266,8 @@ void msvcProbe(Settings *settings, QList<Profile> &profiles)
QSettings::NativeFormat);
const QString defaultSdkPath = sdkRegistry.value(QLatin1String("CurrentInstallFolder")).toString();
if (!defaultSdkPath.isEmpty()) {
- foreach (const QString &sdkKey, sdkRegistry.childGroups()) {
+ const auto sdkKeys = sdkRegistry.childGroups();
+ for (const QString &sdkKey : sdkKeys) {
WinSDK sdk;
sdk.version = sdkKey;
sdk.vcInstallPath = sdkRegistry.value(sdkKey + QLatin1String("/InstallationFolder")).toString();
@@ -273,7 +278,8 @@ void msvcProbe(Settings *settings, QList<Profile> &profiles)
sdk.vcInstallPath.chop(1);
if (sdk.isDefault)
defaultWinSDK = sdk;
- foreach (const MSVCArchInfo &ai, findSupportedArchitectures(sdk)) {
+ const auto ais = findSupportedArchitectures(sdk);
+ for (const MSVCArchInfo &ai : ais) {
WinSDK specificSDK = sdk;
specificSDK.architecture = ai.arch;
specificSDK.binPath = ai.binPath;
@@ -282,7 +288,7 @@ void msvcProbe(Settings *settings, QList<Profile> &profiles)
}
}
- foreach (const WinSDK &sdk, winSDKs) {
+ for (const WinSDK &sdk : qAsConst(winSDKs)) {
qbsInfo() << Tr::tr(" Windows SDK %1 detected:\n"
" installed in %2").arg(sdk.version, sdk.vcInstallPath);
if (sdk.isDefault)
@@ -291,7 +297,8 @@ void msvcProbe(Settings *settings, QList<Profile> &profiles)
// 2) Installed MSVCs
std::vector<MSVC> msvcs;
- foreach (MSVC msvc, installedMSVCs()) {
+ const auto instMsvcs = installedMSVCs();
+ for (const MSVC &msvc : instMsvcs) {
if (msvc.internalVsVersion.majorVersion() < 15) {
// Check existence of various install scripts
const QString vcvars32bat = msvc.vcInstallPath + QLatin1String("/vcvars32.bat");
@@ -299,7 +306,8 @@ void msvcProbe(Settings *settings, QList<Profile> &profiles)
continue;
}
- foreach (const MSVCArchInfo &ai, findSupportedArchitectures(msvc)) {
+ const auto ais = findSupportedArchitectures(msvc);
+ for (const MSVCArchInfo &ai : ais) {
MSVC specificMSVC = msvc;
specificMSVC.architecture = ai.arch;
specificMSVC.binPath = ai.binPath;
@@ -307,7 +315,7 @@ void msvcProbe(Settings *settings, QList<Profile> &profiles)
}
}
- foreach (const MSVC &msvc, msvcs) {
+ for (const MSVC &msvc : qAsConst(msvcs)) {
qbsInfo() << Tr::tr(" MSVC %1 (%2) detected in\n"
" %3").arg(msvc.version, msvc.architecture,
QDir::toNativeSeparators(msvc.binPath));
diff --git a/src/app/qbs-setup-toolchains/probe.cpp b/src/app/qbs-setup-toolchains/probe.cpp
index 94c729d0a..11dee9ad6 100644
--- a/src/app/qbs-setup-toolchains/probe.cpp
+++ b/src/app/qbs-setup-toolchains/probe.cpp
@@ -46,6 +46,7 @@
#include <tools/error.h>
#include <tools/hostosinfo.h>
#include <tools/profile.h>
+#include <tools/qttools.h>
#include <tools/settings.h>
#include <tools/toolchains.h>
#include <tools/stlutils.h>
@@ -73,7 +74,8 @@ static QString findExecutable(const QString &fileName)
fullFileName += QLatin1String(".exe");
}
const QString path = QString::fromLocal8Bit(qgetenv("PATH"));
- foreach (const QString &ppath, path.split(HostOsInfo::pathListSeparator())) {
+ const auto ppaths = path.split(HostOsInfo::pathListSeparator());
+ for (const QString &ppath : ppaths) {
const QString fullPath = ppath + QLatin1Char('/') + fullFileName;
if (QFileInfo::exists(fullPath))
return QDir::cleanPath(fullPath);
@@ -110,10 +112,12 @@ static QStringList toolchainTypeFromCompilerName(const QString &compilerName)
{
if (compilerName == QLatin1String("cl.exe"))
return canonicalToolchain(QLatin1String("msvc"));
- foreach (const QString &type, (QStringList() << QLatin1String("clang") << QLatin1String("llvm")
- << QLatin1String("mingw") << QLatin1String("gcc")))
+ const auto types = { QLatin1String("clang"), QLatin1String("llvm"),
+ QLatin1String("mingw"), QLatin1String("gcc") };
+ for (const QString &type : types) {
if (compilerName.contains(type))
return canonicalToolchain(type);
+ }
if (compilerName == QLatin1String("g++"))
return canonicalToolchain(QLatin1String("gcc"));
return QStringList();
@@ -256,12 +260,13 @@ static void mingwProbe(Settings *settings, QList<Profile> &profiles)
if (HostOsInfo::isWindowsHost()) {
compilerNames << QLatin1String("gcc");
} else {
- foreach (const QString &machineName, validMinGWMachines()) {
+ const auto machineNames = validMinGWMachines();
+ for (const QString &machineName : machineNames) {
compilerNames << machineName + QLatin1String("-gcc");
}
}
- foreach (const QString &compilerName, compilerNames) {
+ for (const QString &compilerName : qAsConst(compilerNames)) {
const QString gccPath
= findExecutable(HostOsInfo::appendExecutableSuffix(compilerName));
if (!gccPath.isEmpty())
diff --git a/src/app/qbs/commandlinefrontend.cpp b/src/app/qbs/commandlinefrontend.cpp
index ac73c9e21..d80b952e7 100644
--- a/src/app/qbs/commandlinefrontend.cpp
+++ b/src/app/qbs/commandlinefrontend.cpp
@@ -95,9 +95,9 @@ void CommandLineFrontend::checkCancelStatus()
m_cancelTimer->stop();
if (m_resolveJobs.empty() && m_buildJobs.empty())
std::exit(EXIT_FAILURE);
- foreach (AbstractJob * const job, m_resolveJobs)
+ for (AbstractJob * const job : qAsConst(m_resolveJobs))
job->cancel();
- foreach (AbstractJob * const job, m_buildJobs)
+ for (AbstractJob * const job : qAsConst(m_buildJobs))
job->cancel();
break;
case CancelStatusCanceling:
@@ -152,7 +152,8 @@ void CommandLineFrontend::start()
params.setPropertyCheckingMode(ErrorHandlingMode::Strict);
if (!m_parser.buildBeforeInstalling() || !m_parser.commandCanResolve())
params.setRestoreBehavior(SetupProjectParameters::RestoreOnly);
- foreach (const QVariantMap &buildConfig, m_parser.buildConfigurations()) {
+ const auto buildConfigs = m_parser.buildConfigurations();
+ for (const QVariantMap &buildConfig : buildConfigs) {
QVariantMap userConfig = buildConfig;
const QString configurationKey = QLatin1String("qbs.configurationName");
const QString profileKey = QLatin1String("qbs.profile");
@@ -340,10 +341,11 @@ CommandLineFrontend::ProductMap CommandLineFrontend::productsToUse() const
ProductMap products;
QStringList productNames;
const bool useAll = m_parser.products().empty();
- foreach (const Project &project, m_projects) {
+ for (const Project &project : qAsConst(m_projects)) {
QList<ProductData> &productList = products[project];
const ProjectData projectData = project.projectData();
- foreach (const ProductData &product, projectData.allProducts()) {
+ const auto products = projectData.allProducts();
+ for (const ProductData &product : products) {
if (useAll || m_parser.products().contains(product.name())) {
productList.push_back(product);
productNames << product.name();
@@ -351,7 +353,8 @@ CommandLineFrontend::ProductMap CommandLineFrontend::productsToUse() const
}
}
- foreach (const QString &productName, m_parser.products()) {
+ const auto parsedProductNames = m_parser.products();
+ for (const QString &productName : parsedProductNames) {
if (!productNames.contains(productName))
throw ErrorInfo(Tr::tr("No such product '%1'.").arg(productName));
}
@@ -410,7 +413,7 @@ void CommandLineFrontend::handleProjectsResolved()
void CommandLineFrontend::makeClean()
{
if (m_parser.products().empty()) {
- foreach (const Project &project, m_projects) {
+ for (const Project &project : qAsConst(m_projects)) {
m_buildJobs << project.cleanAllProducts(m_parser.cleanOptions(project.profile()), this);
}
} else {
@@ -482,7 +485,7 @@ void CommandLineFrontend::build()
if (m_parser.products().empty()) {
const Project::ProductSelection productSelection = m_parser.withNonDefaultProducts()
? Project::ProductSelectionWithNonDefault : Project::ProductSelectionDefaultOnly;
- foreach (const Project &project, m_projects)
+ for (const Project &project : qAsConst(m_projects))
m_buildJobs << project.buildAllProducts(buildOptions(project), productSelection, this);
} else {
const ProductMap &products = productsToUse();
@@ -580,7 +583,7 @@ void CommandLineFrontend::listProducts()
void CommandLineFrontend::connectBuildJobs()
{
- foreach (AbstractJob * const job, m_buildJobs)
+ for (AbstractJob * const job : qAsConst(m_buildJobs))
connectBuildJob(job);
}
@@ -617,7 +620,8 @@ ProductData CommandLineFrontend::getTheOneRunnableProduct()
QBS_CHECK(m_projects.size() == 1); // Has been checked earlier.
if (m_parser.products().size() == 1) {
- foreach (const ProductData &p, m_projects.front().projectData().allProducts()) {
+ const auto products = m_projects.front().projectData().allProducts();
+ for (const ProductData &p : products) {
if (p.name() == m_parser.products().front())
return p;
}
@@ -626,7 +630,8 @@ ProductData CommandLineFrontend::getTheOneRunnableProduct()
QBS_CHECK(m_parser.products().size() == 0);
QList<ProductData> runnableProducts;
- foreach (const ProductData &p, m_projects.front().projectData().allProducts()) {
+ const auto products = m_projects.front().projectData().allProducts();
+ for (const ProductData &p : products) {
if (p.isRunnable())
runnableProducts.push_back(p);
}
@@ -642,7 +647,7 @@ ProductData CommandLineFrontend::getTheOneRunnableProduct()
ErrorInfo error(Tr::tr("Ambiguous use of command '%1': No product given, but project "
"has more than one runnable product.").arg(m_parser.commandName()));
error.append(Tr::tr("Use the '--products' option with one of the following products:"));
- foreach (const ProductData &p, runnableProducts) {
+ for (const ProductData &p : qAsConst(runnableProducts)) {
QString productRepr = QLatin1String("\t") + p.name();
if (p.profile() != m_projects.front().profile()) {
productRepr.append(QLatin1String(" [")).append(p.profile())
diff --git a/src/app/qbs/parser/commandlineoption.cpp b/src/app/qbs/parser/commandlineoption.cpp
index 875256516..c2eea340a 100644
--- a/src/app/qbs/parser/commandlineoption.cpp
+++ b/src/app/qbs/parser/commandlineoption.cpp
@@ -42,6 +42,7 @@
#include <logging/translator.h>
#include <tools/error.h>
#include <tools/installoptions.h>
+#include <tools/qttools.h>
namespace qbs {
using namespace Internal;
@@ -335,7 +336,7 @@ void StringListOption::doParse(const QString &representation, QStringList &input
throw ErrorInfo(Tr::tr("Invalid use of option '%1': Argument list must not be empty.\n"
"Usage: %2").arg(representation, description(command())));
}
- foreach (const QString &element, m_arguments) {
+ for (const QString &element : qAsConst(m_arguments)) {
if (element.isEmpty()) {
throw ErrorInfo(Tr::tr("Invalid use of option '%1': Argument list must not contain "
"empty elements.\nUsage: %2")
@@ -412,7 +413,7 @@ void LogLevelOption::doParse(const QString &representation, QStringList &input)
const QString levelString = getArgument(representation, input);
const QList<LoggerLevel> levels = QList<LoggerLevel>() << LoggerError << LoggerWarning
<< LoggerInfo << LoggerDebug << LoggerTrace;
- foreach (LoggerLevel l, levels) {
+ for (const LoggerLevel &l : levels) {
if (logLevelName(l) == levelString) {
m_logLevel = l;
return;
diff --git a/src/app/qbs/parser/commandlineparser.cpp b/src/app/qbs/parser/commandlineparser.cpp
index 5e9910c15..1f62e716c 100644
--- a/src/app/qbs/parser/commandlineparser.cpp
+++ b/src/app/qbs/parser/commandlineparser.cpp
@@ -55,6 +55,7 @@
#include <tools/installoptions.h>
#include <tools/preferences.h>
#include <tools/qbsassert.h>
+#include <tools/qttools.h>
#include <tools/settings.h>
#include <tools/settingsmodel.h>
@@ -358,7 +359,8 @@ void CommandLineParser::CommandLineParserPrivate::doParse()
Command *CommandLineParser::CommandLineParserPrivate::commandFromString(const QString &commandString) const
{
- foreach (Command * const command, allCommands()) {
+ const auto commands = allCommands();
+ for (Command * const command : commands) {
if (command->representation() == commandString)
return command;
}
@@ -402,10 +404,11 @@ QString CommandLineParser::CommandLineParserPrivate::generalHelp() const
// Sorting the commands by name is nicer for the user.
QMap<QString, const Command *> commandMap;
- foreach (const Command * command, allCommands())
+ const auto commands = allCommands();
+ for (const Command * command : commands)
commandMap.insert(command->representation(), command);
- foreach (const Command * command, commandMap) {
+ for (const Command * command : qAsConst(commandMap)) {
help.append(QLatin1String(" ")).append(command->representation());
const QString whitespace
= QString(rhsIndentation - 2 - command->representation().size(), QLatin1Char(' '));
@@ -416,7 +419,7 @@ QString CommandLineParser::CommandLineParserPrivate::generalHelp() const
toolNames.sort();
if (!toolNames.empty()) {
help.append(QLatin1Char('\n')).append(Tr::tr("Auxiliary commands:\n"));
- foreach (const QString &toolName, toolNames) {
+ for (const QString &toolName : qAsConst(toolNames)) {
help.append(QLatin1String(" ")).append(toolName);
const QString whitespace = QString(rhsIndentation - 2 - toolName.size(),
QLatin1Char(' '));
@@ -473,7 +476,8 @@ void CommandLineParser::CommandLineParserPrivate::setupBuildConfigurations()
const QString configurationNameKey = QLatin1String("qbs.configurationName");
QString currentConfigurationName;
QVariantMap currentProperties;
- foreach (const QString &arg, command->additionalArguments()) {
+ const auto args = command->additionalArguments();
+ for (const QString &arg : args) {
const int sepPos = arg.indexOf(QLatin1Char(':'));
QBS_CHECK(sepPos > 0);
const QString key = arg.left(sepPos);
@@ -496,7 +500,7 @@ void CommandLineParser::CommandLineParserPrivate::setupBuildConfigurations()
const QVariantMap globalProperties = propertiesPerConfiguration.takeFirst().second;
QList<QVariantMap> buildConfigs;
- foreach (const PropertyListItem &item, propertiesPerConfiguration) {
+ for (const PropertyListItem &item : qAsConst(propertiesPerConfiguration)) {
QVariantMap properties = item.second;
for (QVariantMap::ConstIterator globalPropIt = globalProperties.constBegin();
globalPropIt != globalProperties.constEnd(); ++globalPropIt) {
@@ -584,7 +588,7 @@ QString CommandLineParser::CommandLineParserPrivate::propertyName(const QString
bool CommandLineParser::CommandLineParserPrivate::checkForExistingBuildConfiguration(
const QList<QVariantMap> &buildConfigs, const QString &configurationName)
{
- foreach (const QVariantMap &buildConfig, buildConfigs) {
+ for (const QVariantMap &buildConfig : buildConfigs) {
if (configurationName == getBuildConfigurationName(buildConfig))
return true;
}
diff --git a/src/app/qbs/parser/parsercommand.cpp b/src/app/qbs/parser/parsercommand.cpp
index 74bc36829..3649b6cf1 100644
--- a/src/app/qbs/parser/parsercommand.cpp
+++ b/src/app/qbs/parser/parsercommand.cpp
@@ -45,6 +45,7 @@
#include <tools/error.h>
#include <tools/hostosinfo.h>
#include <tools/qbsassert.h>
+#include <tools/qttools.h>
#include <QtCore/qmap.h>
@@ -128,7 +129,8 @@ void Command::parseOption(QStringList &input)
}
bool matchFound = false;
- foreach (const CommandLineOption::Type optionType, actualSupportedOptions()) {
+ const auto optionTypes = actualSupportedOptions();
+ for (const CommandLineOption::Type optionType : optionTypes) {
CommandLineOption * const option = optionPool().getOption(optionType);
if (option->shortRepresentation() != optionString
&& option->longRepresentation() != optionString) {
@@ -158,13 +160,14 @@ QString Command::supportedOptionsDescription() const
{
// Sorting the options by name is nicer for the user.
QMap<QString, const CommandLineOption *> optionMap;
- foreach (const CommandLineOption::Type opType, actualSupportedOptions()) {
+ const auto opTypes = actualSupportedOptions();
+ for (const CommandLineOption::Type opType : opTypes) {
const CommandLineOption * const option = optionPool().getOption(opType);
optionMap.insert(option->longRepresentation(), option);
}
QString s = Tr::tr("The possible options are:\n");
- foreach (const CommandLineOption *option, optionMap)
+ for (const CommandLineOption *option : qAsConst(optionMap))
s += option->description(type());
return s;
}
diff --git a/src/app/qbs/qbstool.cpp b/src/app/qbs/qbstool.cpp
index d01c39591..eb70557b6 100644
--- a/src/app/qbs/qbstool.cpp
+++ b/src/app/qbs/qbstool.cpp
@@ -92,11 +92,11 @@ bool QbsTool::tryToRunTool(const QString &toolName, const QStringList &arguments
QStringList QbsTool::allToolNames()
{
const QString suffix = QLatin1String(QBS_HOST_EXE_SUFFIX);
- QStringList toolFileNames = QDir(qbsBinDir()).entryList(QStringList(toolPrefix()
+ const QStringList toolFileNames = QDir(qbsBinDir()).entryList(QStringList(toolPrefix()
+ QString::fromLatin1("*%1").arg(suffix)), QDir::Files, QDir::Name);
QStringList toolNames;
const int prefixLength = toolPrefix().size();
- foreach (const QString &toolFileName, toolFileNames) {
+ for (const QString &toolFileName : toolFileNames) {
toolNames << toolFileName.mid(prefixLength,
toolFileName.size() - prefixLength - suffix.size());
}
diff --git a/src/app/qbs/status.cpp b/src/app/qbs/status.cpp
index f88196094..8c235010d 100644
--- a/src/app/qbs/status.cpp
+++ b/src/app/qbs/status.cpp
@@ -42,6 +42,7 @@
#include "../shared/logging/consolelogger.h"
#include <qbs.h>
+#include <tools/qttools.h>
#include <QtCore/qdir.h>
#include <QtCore/qfile.h>
@@ -66,8 +67,8 @@ static QList<QRegExp> createIgnoreList(const QString &projectRootPath)
QFile ignoreFile(ignoreFilePath);
if (ignoreFile.open(QFile::ReadOnly)) {
- QList<QByteArray> ignoreTokenList = ignoreFile.readAll().split('\n');
- foreach (const QByteArray &btoken, ignoreTokenList) {
+ const QList<QByteArray> ignoreTokenList = ignoreFile.readAll().split('\n');
+ for (const QByteArray &btoken : ignoreTokenList) {
const QString token = QString::fromLatin1(btoken);
if (token.left(1) == QLatin1String("/"))
ignoreRegularExpressionList.push_back(QRegExp(projectRootPath
@@ -86,10 +87,11 @@ static QStringList allFilesInDirectoryRecursive(const QDir &rootDirecory, const
{
QStringList fileList;
- foreach (const QFileInfo &fileInfo, rootDirecory.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name)) {
+ const auto fileInfos = rootDirecory.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name);
+ for (const QFileInfo &fileInfo : fileInfos) {
QString absoluteFilePath = fileInfo.absoluteFilePath();
bool inIgnoreList = false;
- foreach (const QRegExp &ignoreRegularExpression, ignoreRegularExpressionList) {
+ for (const QRegExp &ignoreRegularExpression : ignoreRegularExpressionList) {
if (ignoreRegularExpression.exactMatch(absoluteFilePath)) {
inIgnoreList = true;
break;
@@ -118,7 +120,8 @@ static QStringList allFilesInProject(const QString &projectRootPath)
QStringList allFiles(const ProductData &product)
{
QStringList files;
- foreach (const GroupData &group, product.groups())
+ const auto groups = product.groups();
+ for (const GroupData &group : groups)
files += group.allFilePaths();
return files;
}
@@ -131,17 +134,19 @@ int printStatus(const ProjectData &project)
QStringList untrackedFilesInProject = allFilesInProject(projectDirectory);
QStringList missingFiles;
- foreach (const ProductData &product, project.allProducts()) {
+ const auto products = project.allProducts();
+ for (const ProductData &product : products) {
qbsInfo() << "\nProduct: " << product.name()
<< " (" << product.location().filePath() << ":"
<< product.location().line() << ")";
- foreach (const GroupData &group, product.groups()) {
+ const auto groups = product.groups();
+ for (const GroupData &group : groups) {
qbsInfo() << " Group: " << group.name()
<< " (" << group.location().filePath() << ":"
<< group.location().line() << ")";
QStringList sourceFiles = group.allFilePaths();
qSort(sourceFiles);
- foreach (const QString &sourceFile, sourceFiles) {
+ for (const QString &sourceFile : qAsConst(sourceFiles)) {
if (!QFileInfo(sourceFile).exists())
missingFiles.push_back(sourceFile);
qbsInfo() << " " << sourceFile.mid(projectDirectoryPathLength + 1);
@@ -151,11 +156,11 @@ int printStatus(const ProjectData &project)
}
qbsInfo() << "\nMissing files:";
- foreach (const QString &untrackedFile, missingFiles)
+ for (const QString &untrackedFile : qAsConst(missingFiles))
qbsInfo() << " " << untrackedFile.mid(projectDirectoryPathLength + 1);
qbsInfo() << "\nUntracked files:";
- foreach (const QString &missingFile, untrackedFilesInProject)
+ for (const QString &missingFile : qAsConst(untrackedFilesInProject))
qbsInfo() << " " << missingFile.mid(projectDirectoryPathLength + 1);
return 0;