ProjectExplorer: Remove foreach / Q_FOREACH usage part 3

Task-number: QTCREATORBUG-27464
Change-Id: Iab4740dd2f475febf7532f0a02407b0088d54068
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Artem Sokolovskii
2022-05-04 11:50:41 +02:00
parent dcc93253c8
commit d73d5fe0b1
11 changed files with 44 additions and 40 deletions

View File

@@ -194,7 +194,7 @@ void ProjectTree::updateFromNode(Node *node)
project = SessionManager::startupProject();
setCurrent(node, project);
foreach (ProjectTreeWidget *widget, m_projectTreeWidgets)
for (ProjectTreeWidget *widget : qAsConst(m_projectTreeWidgets))
widget->sync(node);
}

View File

@@ -621,28 +621,28 @@ void Target::updateDefaultBuildConfigurations()
void Target::updateDefaultDeployConfigurations()
{
QList<DeployConfigurationFactory *> dcFactories = DeployConfigurationFactory::find(this);
const QList<DeployConfigurationFactory *> dcFactories = DeployConfigurationFactory::find(this);
if (dcFactories.isEmpty()) {
qWarning("No deployment configuration factory found for target id '%s'.", qPrintable(id().toString()));
return;
}
QList<Utils::Id> dcIds;
foreach (DeployConfigurationFactory *dcFactory, dcFactories)
for (const DeployConfigurationFactory *dcFactory : dcFactories)
dcIds.append(dcFactory->creationId());
QList<DeployConfiguration *> dcList = deployConfigurations();
const QList<DeployConfiguration *> dcList = deployConfigurations();
QList<Utils::Id> toCreate = dcIds;
foreach (DeployConfiguration *dc, dcList) {
for (DeployConfiguration *dc : dcList) {
if (dcIds.contains(dc->id()))
toCreate.removeOne(dc->id());
else
removeDeployConfiguration(dc);
}
foreach (Utils::Id id, toCreate) {
foreach (DeployConfigurationFactory *dcFactory, dcFactories) {
for (Utils::Id id : qAsConst(toCreate)) {
for (DeployConfigurationFactory *dcFactory : dcFactories) {
if (dcFactory->creationId() == id) {
DeployConfiguration *dc = dcFactory->create(this);
if (dc) {
@@ -680,7 +680,7 @@ void Target::updateDefaultRunConfigurations()
// that produce already existing RCs
QList<RunConfiguration *> toRemove;
QList<RunConfigurationCreationInfo> existing;
foreach (RunConfiguration *rc, existingConfigured) {
for (RunConfiguration *rc : qAsConst(existingConfigured)) {
bool present = false;
for (const RunConfigurationCreationInfo &item : creators) {
QString buildKey = rc->buildKey();
@@ -697,7 +697,7 @@ void Target::updateDefaultRunConfigurations()
bool removeExistingUnconfigured = false;
if (ProjectExplorerPlugin::projectExplorerSettings().automaticallyCreateRunConfigurations) {
// Create new "automatic" RCs and put them into newConfigured/newUnconfigured
foreach (const RunConfigurationCreationInfo &item, creators) {
for (const RunConfigurationCreationInfo &item : creators) {
if (item.creationMode == RunConfigurationCreationInfo::ManualCreationOnly)
continue;
bool exists = false;
@@ -735,14 +735,14 @@ void Target::updateDefaultRunConfigurations()
}
// Do actual changes:
foreach (RunConfiguration *rc, newConfigured)
for (RunConfiguration *rc : qAsConst(newConfigured))
addRunConfiguration(rc);
foreach (RunConfiguration *rc, newUnconfigured)
for (RunConfiguration *rc : qAsConst(newUnconfigured))
addRunConfiguration(rc);
// Generate complete list of RCs to remove later:
QList<RunConfiguration *> removalList;
foreach (RunConfiguration *rc, toRemove) {
for (RunConfiguration *rc : qAsConst(toRemove)) {
removalList << rc;
existingConfigured.removeOne(rc); // make sure to also remove them from existingConfigured!
}
@@ -778,7 +778,7 @@ void Target::updateDefaultRunConfigurations()
}
// Remove the RCs that are no longer needed:
foreach (RunConfiguration *rc, removalList)
for (RunConfiguration *rc : qAsConst(removalList))
removeRunConfiguration(rc);
}

View File

@@ -375,7 +375,7 @@ QPair<Task::TaskType, QString> TargetSetupWidget::findIssues(const BuildInfo &in
QString text;
Task::TaskType highestType = Task::Unknown;
foreach (const Task &t, issues) {
for (const Task &t : qAsConst(issues)) {
if (!text.isEmpty())
text.append(QLatin1String("<br>"));
// set severity:

View File

@@ -97,7 +97,7 @@ Tasks TaskModel::tasks(Utils::Id categoryId) const
return m_tasks;
Tasks taskList;
foreach (const Task &t, m_tasks) {
for (const Task &t : qAsConst(m_tasks)) {
if (t.category == categoryId)
taskList.append(t);
}

View File

@@ -641,7 +641,8 @@ void TaskWindow::updateCategoriesMenu()
const QList<Utils::Id> filteredCategories = d->m_filter->filteredCategories();
QMap<QString, Utils::Id> nameToIds;
foreach (Utils::Id categoryId, d->m_model->categoryIds())
const QList<Utils::Id> ids = d->m_model->categoryIds();
for (const Utils::Id categoryId : ids)
nameToIds.insert(d->m_model->categoryDisplayName(categoryId), categoryId);
const NameToIdsConstIt cend = nameToIds.constEnd();

View File

@@ -220,7 +220,7 @@ bool ToolChainManager::registerToolChain(ToolChain *tc)
if (d->m_toolChains.contains(tc))
return true;
foreach (ToolChain *current, d->m_toolChains) {
for (const ToolChain *current : qAsConst(d->m_toolChains)) {
if (*tc == *current && !tc->isAutoDetected())
return false;
QTC_ASSERT(current->id() != tc->id(), return false);

View File

@@ -170,7 +170,8 @@ public:
{ProjectExplorer::Constants::msgAutoDetectedToolTip()});
auto manualRoot = new StaticTreeItem(ProjectExplorer::Constants::msgManual());
foreach (const Utils::Id &l, ToolChainManager::allLanguages()) {
const QList<Utils::Id> languages = ToolChainManager::allLanguages();
for (const Utils::Id &l : languages) {
const QString dn = ToolChainManager::displayNameOfLanguageId(l);
auto autoNode = new StaticTreeItem(dn);
auto manualNode = new StaticTreeItem(dn);
@@ -196,7 +197,7 @@ public:
m_addButton = new QPushButton(ToolChainOptionsPage::tr("Add"), this);
auto addMenu = new QMenu;
foreach (ToolChainFactory *factory, m_factories) {
for (ToolChainFactory *factory : qAsConst(m_factories)) {
QList<Utils::Id> languages = factory->supportedLanguages();
if (languages.isEmpty())
continue;
@@ -208,7 +209,7 @@ public:
return ToolChainManager::displayNameOfLanguageId(l1) < ToolChainManager::displayNameOfLanguageId(l2);
});
auto subMenu = addMenu->addMenu(factory->displayName());
foreach (const Utils::Id &l, languages)
for (const Utils::Id &l : qAsConst(languages))
subMenu->addAction(createAction(ToolChainManager::displayNameOfLanguageId(l), factory, l));
}
}
@@ -362,10 +363,10 @@ ToolChainTreeItem *ToolChainOptionsWidget::insertToolChain(ToolChain *tc, bool c
void ToolChainOptionsWidget::addToolChain(ToolChain *tc)
{
foreach (ToolChainTreeItem *n, m_toAddList) {
if (n->toolChain == tc) {
// do not delete n: Still used elsewhere!
m_toAddList.removeOne(n);
for (int i = 0; i < m_toAddList.size(); ++i) {
if (m_toAddList.at(i)->toolChain == tc) {
// do not delete i element: Still used elsewhere!
m_toAddList.removeAt(i);
return;
}
}
@@ -377,10 +378,10 @@ void ToolChainOptionsWidget::addToolChain(ToolChain *tc)
void ToolChainOptionsWidget::removeToolChain(ToolChain *tc)
{
foreach (ToolChainTreeItem *n, m_toRemoveList) {
if (n->toolChain == tc) {
m_toRemoveList.removeOne(n);
delete n;
for (int i = 0; i < m_toRemoveList.size(); ++i) {
if (m_toRemoveList.at(i)->toolChain == tc) {
m_toRemoveList.removeAt(i);
delete m_toRemoveList.at(i);
return;
}
}
@@ -456,13 +457,14 @@ void ToolChainOptionsWidget::apply()
{
// Remove unused tool chains:
QList<ToolChainTreeItem *> nodes = m_toRemoveList;
foreach (ToolChainTreeItem *n, nodes)
for (const ToolChainTreeItem *n : qAsConst(nodes))
ToolChainManager::deregisterToolChain(n->toolChain);
Q_ASSERT(m_toRemoveList.isEmpty());
// Update tool chains:
foreach (const Utils::Id &l, m_languageMap.keys()) {
const QList<Utils::Id> languages = m_languageMap.keys();
for (const Utils::Id &l : languages) {
const QPair<StaticTreeItem *, StaticTreeItem *> autoAndManual = m_languageMap.value(l);
for (StaticTreeItem *parent : {autoAndManual.first, autoAndManual.second}) {
for (TreeItem *item : *parent) {
@@ -479,12 +481,13 @@ void ToolChainOptionsWidget::apply()
// Add new (and already updated) tool chains
QStringList removedTcs;
nodes = m_toAddList;
foreach (ToolChainTreeItem *n, nodes) {
for (const ToolChainTreeItem *n : qAsConst(nodes)) {
if (!ToolChainManager::registerToolChain(n->toolChain))
removedTcs << n->toolChain->displayName();
}
//
foreach (ToolChainTreeItem *n, m_toAddList)
const QList<ToolChainTreeItem *> toAddList = m_toAddList;
for (ToolChainTreeItem *n : toAddList)
markForRemoval(n);
qDeleteAll(m_toAddList);

View File

@@ -80,7 +80,7 @@ static Toolchains autoDetectToolChains(const ToolchainDetector &detector)
static Toolchains makeUniqueByEqual(const Toolchains &a)
{
Toolchains result;
foreach (ToolChain *tc, a) {
for (ToolChain *tc : a) {
if (!Utils::contains(result, [tc](ToolChain *rtc) { return *tc == *rtc; }))
result.append(tc);
}

View File

@@ -704,8 +704,8 @@ QVariantMap UserFileVersion16Upgrader::upgrade(const QVariantMap &data)
NamePolicy policy = oldSteps.size() > 1 ? RenameBuildConfiguration : KeepName;
foreach (const QVariantMap &oldBuildConfiguration, oldBuildConfigurations) {
foreach (const OldStepMaps &oldStep, oldSteps) {
for (const QVariantMap &oldBuildConfiguration : qAsConst(oldBuildConfigurations)) {
for (const OldStepMaps &oldStep : qAsConst(oldSteps)) {
QVariantMap newBuildConfiguration = insertSteps(oldBuildConfiguration, oldStep, policy);
if (!newBuildConfiguration.isEmpty())
newBuildConfigurations.append(newBuildConfiguration);
@@ -735,7 +735,7 @@ QVariant UserFileVersion17Upgrader::process(const QVariant &entry)
switch (entry.type()) {
case QVariant::List: {
QVariantList result;
foreach (const QVariant &item, entry.toList())
for (const QVariant &item : entry.toList())
result.append(process(item));
return result;
}

View File

@@ -35,8 +35,8 @@
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
WaitForStopDialog::WaitForStopDialog(QList<ProjectExplorer::RunControl *> runControls) :
m_runControls(runControls)
WaitForStopDialog::WaitForStopDialog(const QList<ProjectExplorer::RunControl *> &runControls)
: m_runControls(runControls)
{
setWindowTitle(tr("Waiting for Applications to Stop"));
@@ -53,7 +53,7 @@ WaitForStopDialog::WaitForStopDialog(QList<ProjectExplorer::RunControl *> runCon
updateProgressText();
foreach (RunControl *rc, runControls)
for (const RunControl *rc : runControls)
connect(rc, &RunControl::stopped, this, &WaitForStopDialog::runControlFinished);
m_timer.start();

View File

@@ -42,7 +42,7 @@ class WaitForStopDialog : public QDialog
{
Q_OBJECT
public:
explicit WaitForStopDialog(QList<ProjectExplorer::RunControl *> runControls);
explicit WaitForStopDialog(const QList<ProjectExplorer::RunControl *> &runControls);
bool canceled();
private: