CorePlugin: Remove foreach / Q_FOREACH usage mostly in dialogs

Task-number: QTCREATORBUG-27464
Change-Id: Iad47e9cb0b2fa7590dba2d26d0a33a83d2909bb7
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Artem Sokolovskii
2022-05-02 17:25:11 +02:00
parent 33a385c4d6
commit f4e943bda3
15 changed files with 73 additions and 57 deletions

View File

@@ -160,8 +160,8 @@ void DesignMode::currentEditorChanged(IEditor *editor)
if (editor) { if (editor) {
const QString mimeType = editor->document()->mimeType(); const QString mimeType = editor->document()->mimeType();
if (!mimeType.isEmpty()) { if (!mimeType.isEmpty()) {
foreach (DesignEditorInfo *editorInfo, d->m_editors) { for (const DesignEditorInfo *editorInfo : qAsConst(d->m_editors)) {
foreach (const QString &mime, editorInfo->mimeTypes) { for (const QString &mime : editorInfo->mimeTypes) {
if (mime == mimeType) { if (mime == mimeType) {
d->m_stackWidget->setCurrentIndex(editorInfo->widgetIndex); d->m_stackWidget->setCurrentIndex(editorInfo->widgetIndex);
setActiveContext(editorInfo->context); setActiveContext(editorInfo->context);
@@ -169,10 +169,10 @@ void DesignMode::currentEditorChanged(IEditor *editor)
setEnabled(true); setEnabled(true);
break; break;
} }
} // foreach mime }
if (mimeEditorAvailable) if (mimeEditorAvailable)
break; break;
} // foreach editorInfo }
} }
} }
if (d->m_currentEditor) if (d->m_currentEditor)

View File

@@ -673,7 +673,8 @@ static QString findUnusedId(const QString &proposal, const QMap<QString, QList<E
++number; ++number;
found = false; found = false;
for (auto it = tools.cbegin(), end = tools.cend(); it != end; ++it) { for (auto it = tools.cbegin(), end = tools.cend(); it != end; ++it) {
foreach (ExternalTool *tool, it.value()) { const QList<ExternalTool *> tools = it.value();
for (const ExternalTool *tool : tools) {
if (tool->id() == result) { if (tool->id() == result) {
found = true; found = true;
break; break;
@@ -695,7 +696,8 @@ void ExternalToolConfig::apply()
QMap<QString, QList<ExternalTool *> > resultMap; QMap<QString, QList<ExternalTool *> > resultMap;
for (auto it = newToolsMap.cbegin(), end = newToolsMap.cend(); it != end; ++it) { for (auto it = newToolsMap.cbegin(), end = newToolsMap.cend(); it != end; ++it) {
QList<ExternalTool *> items; QList<ExternalTool *> items;
foreach (ExternalTool *tool, it.value()) { const QList<ExternalTool *> tools = it.value();
for (ExternalTool *tool : tools) {
ExternalTool *toolToAdd = nullptr; ExternalTool *toolToAdd = nullptr;
if (ExternalTool *originalTool = originalTools.take(tool->id())) { if (ExternalTool *originalTool = originalTools.take(tool->id())) {
// check if it has different category and is custom tool // check if it has different category and is custom tool
@@ -752,7 +754,7 @@ void ExternalToolConfig::apply()
resultMap.insert(it.key(), items); resultMap.insert(it.key(), items);
} }
// Remove tools that have been deleted from the settings (and are no preset) // Remove tools that have been deleted from the settings (and are no preset)
foreach (ExternalTool *tool, originalTools) { for (const ExternalTool *tool : qAsConst(originalTools)) {
QTC_ASSERT(!tool->preset(), continue); QTC_ASSERT(!tool->preset(), continue);
// TODO error handling // TODO error handling
tool->fileName().removeFile(); tool->fileName().removeFile();

View File

@@ -270,18 +270,18 @@ bool IOptionsPage::matches(const QRegularExpression &regexp) const
if (!widget) if (!widget)
return false; return false;
// find common subwidgets // find common subwidgets
foreach (const QLabel *label, widget->findChildren<QLabel *>()) for (const QLabel *label : widget->findChildren<QLabel *>())
m_keywords << Utils::stripAccelerator(label->text()); m_keywords << Utils::stripAccelerator(label->text());
foreach (const QCheckBox *checkbox, widget->findChildren<QCheckBox *>()) for (const QCheckBox *checkbox : widget->findChildren<QCheckBox *>())
m_keywords << Utils::stripAccelerator(checkbox->text()); m_keywords << Utils::stripAccelerator(checkbox->text());
foreach (const QPushButton *pushButton, widget->findChildren<QPushButton *>()) for (const QPushButton *pushButton : widget->findChildren<QPushButton *>())
m_keywords << Utils::stripAccelerator(pushButton->text()); m_keywords << Utils::stripAccelerator(pushButton->text());
foreach (const QGroupBox *groupBox, widget->findChildren<QGroupBox *>()) for (const QGroupBox *groupBox : widget->findChildren<QGroupBox *>())
m_keywords << Utils::stripAccelerator(groupBox->title()); m_keywords << Utils::stripAccelerator(groupBox->title());
m_keywordsInitialized = true; m_keywordsInitialized = true;
} }
foreach (const QString &keyword, m_keywords) for (const QString &keyword : qAsConst(m_keywords))
if (keyword.contains(regexp)) if (keyword.contains(regexp))
return true; return true;
return false; return false;

View File

@@ -401,7 +401,8 @@ void NewDialogWidget::currentItemChanged(const QModelIndex &index)
if (const IWizardFactory *wizard = factoryOfItem(cat)) { if (const IWizardFactory *wizard = factoryOfItem(cat)) {
QString desciption = wizard->description(); QString desciption = wizard->description();
QStringList displayNamesForSupportedPlatforms; QStringList displayNamesForSupportedPlatforms;
foreach (Id platform, wizard->supportedPlatforms()) const QSet<Id> platforms = wizard->supportedPlatforms();
for (const Id platform : platforms)
displayNamesForSupportedPlatforms << IWizardFactory::displayNameForPlatform(platform); displayNamesForSupportedPlatforms << IWizardFactory::displayNameForPlatform(platform);
Utils::sort(displayNamesForSupportedPlatforms); Utils::sort(displayNamesForSupportedPlatforms);
if (!Qt::mightBeRichText(desciption)) if (!Qt::mightBeRichText(desciption))

View File

@@ -58,7 +58,7 @@ void OpenWithDialog::setOkButtonEnabled(bool v)
void OpenWithDialog::setEditors(const QStringList &editors) void OpenWithDialog::setEditors(const QStringList &editors)
{ {
foreach (const QString &e, editors) for (const QString &e : editors)
editorListWidget->addItem(e); editorListWidget->addItem(e);
} }

View File

@@ -82,7 +82,7 @@ void PromptOverwriteDialog::setFiles(const QStringList &l)
{ {
// Format checkable list excluding common path // Format checkable list excluding common path
const QString nativeCommonPath = QDir::toNativeSeparators(Utils::commonPath(l)); const QString nativeCommonPath = QDir::toNativeSeparators(Utils::commonPath(l));
foreach (const QString &fileName, l) { for (const QString &fileName : l) {
const QString nativeFileName = QDir::toNativeSeparators(fileName); const QString nativeFileName = QDir::toNativeSeparators(fileName);
const int length = nativeFileName.size() - nativeCommonPath.size() - 1; const int length = nativeFileName.size() - nativeCommonPath.size() - 1;
QStandardItem *item = new QStandardItem(nativeFileName.right(length)); QStandardItem *item = new QStandardItem(nativeFileName.right(length));

View File

@@ -124,7 +124,7 @@ ReadOnlyFilesDialogPrivate::ReadOnlyFilesDialogPrivate(ReadOnlyFilesDialog *pare
ReadOnlyFilesDialogPrivate::~ReadOnlyFilesDialogPrivate() ReadOnlyFilesDialogPrivate::~ReadOnlyFilesDialogPrivate()
{ {
foreach (const ButtonGroupForFile &groupForFile, buttonGroups) for (const ButtonGroupForFile &groupForFile : qAsConst(buttonGroups))
delete groupForFile.group; delete groupForFile.group;
} }
@@ -371,8 +371,9 @@ void ReadOnlyFilesDialogPrivate::setAll(int index)
type = SaveAs; type = SaveAs;
// Check for every file if the selected operation is available and change it to the operation. // Check for every file if the selected operation is available and change it to the operation.
foreach (ReadOnlyFilesDialogPrivate::ButtonGroupForFile groupForFile, buttonGroups) { for (const ReadOnlyFilesDialogPrivate::ButtonGroupForFile &groupForFile :
auto radioButton = qobject_cast<QRadioButton*> (groupForFile.group->button(type)); qAsConst(buttonGroups)) {
auto radioButton = qobject_cast<QRadioButton *>(groupForFile.group->button(type));
if (radioButton) if (radioButton)
radioButton->setChecked(true); radioButton->setChecked(true);
} }
@@ -386,7 +387,8 @@ void ReadOnlyFilesDialogPrivate::setAll(int index)
void ReadOnlyFilesDialogPrivate::updateSelectAll() void ReadOnlyFilesDialogPrivate::updateSelectAll()
{ {
int selectedOperation = -1; int selectedOperation = -1;
foreach (ReadOnlyFilesDialogPrivate::ButtonGroupForFile groupForFile, buttonGroups) { for (const ReadOnlyFilesDialogPrivate::ButtonGroupForFile &groupForFile :
qAsConst(buttonGroups)) {
if (selectedOperation == -1) { if (selectedOperation == -1) {
selectedOperation = groupForFile.group->checkedId(); selectedOperation = groupForFile.group->checkedId();
} else if (selectedOperation != groupForFile.group->checkedId()) { } else if (selectedOperation != groupForFile.group->checkedId()) {

View File

@@ -65,7 +65,7 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent,
m_ui.saveBeforeBuildCheckBox->setVisible(false); m_ui.saveBeforeBuildCheckBox->setVisible(false);
foreach (IDocument *document, items) { for (IDocument *document : qAsConst(items)) {
QString visibleName; QString visibleName;
QString directory; QString directory;
Utils::FilePath filePath = document->filePath(); Utils::FilePath filePath = document->filePath();
@@ -135,7 +135,7 @@ void SaveItemsDialog::adjustButtonWidths()
possibleTexts << tr("Save Selected"); possibleTexts << tr("Save Selected");
int maxTextWidth = 0; int maxTextWidth = 0;
QPushButton *saveButton = m_ui.buttonBox->button(QDialogButtonBox::Save); QPushButton *saveButton = m_ui.buttonBox->button(QDialogButtonBox::Save);
foreach (const QString &text, possibleTexts) { for (const QString &text : qAsConst(possibleTexts)) {
saveButton->setText(text); saveButton->setText(text);
int hint = saveButton->sizeHint().width(); int hint = saveButton->sizeHint().width();
if (hint > maxTextWidth) if (hint > maxTextWidth)
@@ -154,7 +154,8 @@ void SaveItemsDialog::adjustButtonWidths()
void SaveItemsDialog::collectItemsToSave() void SaveItemsDialog::collectItemsToSave()
{ {
m_itemsToSave.clear(); m_itemsToSave.clear();
foreach (QTreeWidgetItem *item, m_ui.treeWidget->selectedItems()) { const QList<QTreeWidgetItem *> items = m_ui.treeWidget->selectedItems();
for (const QTreeWidgetItem *item : items) {
m_itemsToSave.append(item->data(0, Qt::UserRole).value<IDocument*>()); m_itemsToSave.append(item->data(0, Qt::UserRole).value<IDocument*>());
} }
accept(); accept();
@@ -163,7 +164,8 @@ void SaveItemsDialog::collectItemsToSave()
void SaveItemsDialog::collectFilesToDiff() void SaveItemsDialog::collectFilesToDiff()
{ {
m_filesToDiff.clear(); m_filesToDiff.clear();
foreach (QTreeWidgetItem *item, m_ui.treeWidget->selectedItems()) { const QList<QTreeWidgetItem *> items = m_ui.treeWidget->selectedItems();
for (const QTreeWidgetItem *item : items) {
if (auto doc = item->data(0, Qt::UserRole).value<IDocument*>()) if (auto doc = item->data(0, Qt::UserRole).value<IDocument*>())
m_filesToDiff.append(doc->filePath().toString()); m_filesToDiff.append(doc->filePath().toString());
} }

View File

@@ -170,7 +170,7 @@ void CategoryModel::setPages(const QList<IOptionsPage*> &pages,
m_pageIds.clear(); m_pageIds.clear();
// Put the pages in categories // Put the pages in categories
foreach (IOptionsPage *page, pages) { for (IOptionsPage *page : pages) {
QTC_ASSERT(!m_pageIds.contains(page->id()), QTC_ASSERT(!m_pageIds.contains(page->id()),
qWarning("duplicate options page id '%s'", qPrintable(page->id().toString()))); qWarning("duplicate options page id '%s'", qPrintable(page->id().toString())));
m_pageIds.insert(page->id()); m_pageIds.insert(page->id());
@@ -190,7 +190,7 @@ void CategoryModel::setPages(const QList<IOptionsPage*> &pages,
category->pages.append(page); category->pages.append(page);
} }
foreach (IOptionsPageProvider *provider, providers) { for (IOptionsPageProvider *provider : providers) {
const Id categoryId = provider->category(); const Id categoryId = provider->category();
Category *category = findCategoryById(categoryId); Category *category = findCategoryById(categoryId);
if (!category) { if (!category) {
@@ -217,11 +217,11 @@ void CategoryModel::ensurePages(Category *category)
{ {
if (!category->providerPagesCreated) { if (!category->providerPagesCreated) {
QList<IOptionsPage *> createdPages; QList<IOptionsPage *> createdPages;
foreach (const IOptionsPageProvider *provider, category->providers) for (const IOptionsPageProvider *provider : qAsConst(category->providers))
createdPages += provider->pages(); createdPages += provider->pages();
// check for duplicate ids // check for duplicate ids
foreach (IOptionsPage *page, createdPages) { for (const IOptionsPage *page : qAsConst(createdPages)) {
QTC_ASSERT(!m_pageIds.contains(page->id()), QTC_ASSERT(!m_pageIds.contains(page->id()),
qWarning("duplicate options page id '%s'", qPrintable(page->id().toString()))); qWarning("duplicate options page id '%s'", qPrintable(page->id().toString())));
} }
@@ -702,9 +702,9 @@ void SettingsDialog::accept()
m_finished = true; m_finished = true;
disconnectTabWidgets(); disconnectTabWidgets();
m_applied = true; m_applied = true;
foreach (IOptionsPage *page, m_visitedPages) for (IOptionsPage *page : qAsConst(m_visitedPages))
page->apply(); page->apply();
foreach (IOptionsPage *page, m_pages) for (IOptionsPage *page : qAsConst(m_pages))
page->finish(); page->finish();
done(QDialog::Accepted); done(QDialog::Accepted);
} }
@@ -715,14 +715,14 @@ void SettingsDialog::reject()
return; return;
m_finished = true; m_finished = true;
disconnectTabWidgets(); disconnectTabWidgets();
foreach (IOptionsPage *page, m_pages) for (IOptionsPage *page : qAsConst(m_pages))
page->finish(); page->finish();
done(QDialog::Rejected); done(QDialog::Rejected);
} }
void SettingsDialog::apply() void SettingsDialog::apply()
{ {
foreach (IOptionsPage *page, m_visitedPages) for (IOptionsPage *page : qAsConst(m_visitedPages))
page->apply(); page->apply();
m_applied = true; m_applied = true;
} }

View File

@@ -332,7 +332,7 @@ QWidget *ShortcutSettings::widget()
void ShortcutSettingsWidget::apply() void ShortcutSettingsWidget::apply()
{ {
foreach (ShortcutItem *item, m_scitems) for (const ShortcutItem *item : qAsConst(m_scitems))
item->m_cmd->setKeySequences(item->m_keys); item->m_cmd->setKeySequences(item->m_keys);
} }
@@ -520,7 +520,7 @@ void ShortcutSettingsWidget::importAction()
void ShortcutSettingsWidget::defaultAction() void ShortcutSettingsWidget::defaultAction()
{ {
foreach (ShortcutItem *item, m_scitems) { for (ShortcutItem *item : qAsConst(m_scitems)) {
item->m_keys = item->m_cmd->defaultKeySequences(); item->m_keys = item->m_cmd->defaultKeySequences();
item->m_item->setText(2, keySequencesToNativeString(item->m_keys)); item->m_item->setText(2, keySequencesToNativeString(item->m_keys));
setModified(item->m_item, false); setModified(item->m_item, false);
@@ -557,7 +557,8 @@ void ShortcutSettingsWidget::initialize()
clear(); clear();
QMap<QString, QTreeWidgetItem *> sections; QMap<QString, QTreeWidgetItem *> sections;
foreach (Command *c, ActionManager::commands()) { const QList<Command *> commands = ActionManager::commands();
for (Command *c : commands) {
if (c->hasAttribute(Command::CA_NonConfigurable)) if (c->hasAttribute(Command::CA_NonConfigurable))
continue; continue;
if (c->action() && c->action()->isSeparator()) if (c->action() && c->action()->isSeparator())

View File

@@ -370,7 +370,7 @@ void DocumentManager::addDocuments(const QList<IDocument *> &documents, bool add
if (!addWatcher) { if (!addWatcher) {
// We keep those in a separate list // We keep those in a separate list
foreach (IDocument *document, documents) { for (IDocument *document : documents) {
if (document && !d->m_documentsWithoutWatch.contains(document)) { if (document && !d->m_documentsWithoutWatch.contains(document)) {
connect(document, &QObject::destroyed, connect(document, &QObject::destroyed,
m_instance, &DocumentManager::documentDestroyed); m_instance, &DocumentManager::documentDestroyed);
@@ -406,7 +406,8 @@ static void removeFileInfo(IDocument *document)
QTC_ASSERT(isMainThread(), return); QTC_ASSERT(isMainThread(), return);
if (!d->m_documentsWithWatch.contains(document)) if (!d->m_documentsWithWatch.contains(document))
return; return;
foreach (const FilePath &filePath, d->m_documentsWithWatch.value(document)) { const FilePaths filePaths = d->m_documentsWithWatch.value(document);
for (const FilePath &filePath : filePaths) {
if (!d->m_states.contains(filePath)) if (!d->m_states.contains(filePath))
continue; continue;
qCDebug(log) << "removing document (" << filePath << ")"; qCDebug(log) << "removing document (" << filePath << ")";
@@ -599,7 +600,7 @@ QList<IDocument *> DocumentManager::modifiedDocuments()
modified << document; modified << document;
} }
foreach (IDocument *document, d->m_documentsWithoutWatch) { for (IDocument *document : qAsConst(d->m_documentsWithoutWatch)) {
if (document->isModified()) if (document->isModified())
modified << document; modified << document;
} }
@@ -665,7 +666,7 @@ static bool saveModifiedFilesHelper(const QList<IDocument *> &documents,
QHash<IDocument *, QString> modifiedDocumentsMap; QHash<IDocument *, QString> modifiedDocumentsMap;
QList<IDocument *> modifiedDocuments; QList<IDocument *> modifiedDocuments;
foreach (IDocument *document, documents) { for (IDocument *document : documents) {
if (document && document->isModified() && !document->isTemporary()) { if (document && document->isModified() && !document->isTemporary()) {
QString name = document->filePath().toString(); QString name = document->filePath().toString();
if (name.isEmpty()) if (name.isEmpty())
@@ -709,7 +710,7 @@ static bool saveModifiedFilesHelper(const QList<IDocument *> &documents,
} }
// Check for files without write permissions. // Check for files without write permissions.
QList<IDocument *> roDocuments; QList<IDocument *> roDocuments;
foreach (IDocument *document, documentsToSave) { for (IDocument *document : qAsConst(documentsToSave)) {
if (document->isFileReadOnly()) if (document->isFileReadOnly())
roDocuments << document; roDocuments << document;
} }
@@ -726,7 +727,7 @@ static bool saveModifiedFilesHelper(const QList<IDocument *> &documents,
return false; return false;
} }
} }
foreach (IDocument *document, documentsToSave) { for (IDocument *document : qAsConst(documentsToSave)) {
if (!EditorManagerPrivate::saveDocument(document)) { if (!EditorManagerPrivate::saveDocument(document)) {
if (cancelled) if (cancelled)
*cancelled = true; *cancelled = true;
@@ -1114,7 +1115,7 @@ void DocumentManager::checkForReload()
QMap<FilePath, FileStateItem> currentStates; QMap<FilePath, FileStateItem> currentStates;
QMap<FilePath, IDocument::ChangeType> changeTypes; QMap<FilePath, IDocument::ChangeType> changeTypes;
QSet<IDocument *> changedIDocuments; QSet<IDocument *> changedIDocuments;
foreach (const FilePath &filePath, d->m_changedFiles) { for (const FilePath &filePath : qAsConst(d->m_changedFiles)) {
const FilePath fileKey = filePathKey(filePath, KeepLinks); const FilePath fileKey = filePathKey(filePath, KeepLinks);
qCDebug(log) << "handling file change for" << filePath << "(" << fileKey << ")"; qCDebug(log) << "handling file change for" << filePath << "(" << fileKey << ")";
IDocument::ChangeType type = IDocument::TypeContents; IDocument::ChangeType type = IDocument::TypeContents;
@@ -1130,7 +1131,8 @@ void DocumentManager::checkForReload()
} }
currentStates.insert(fileKey, state); currentStates.insert(fileKey, state);
changeTypes.insert(fileKey, type); changeTypes.insert(fileKey, type);
foreach (IDocument *document, d->m_states.value(fileKey).lastUpdatedState.keys()) QList<IDocument *> documents = d->m_states.value(fileKey).lastUpdatedState.keys();
for (IDocument *document : documents)
changedIDocuments.insert(document); changedIDocuments.insert(document);
} }
@@ -1144,7 +1146,7 @@ void DocumentManager::checkForReload()
// if the resolved names are different when unexpectFileChange is called // if the resolved names are different when unexpectFileChange is called
// we would end up with never-unexpected file names // we would end up with never-unexpected file names
QSet<FilePath> expectedFileKeys; QSet<FilePath> expectedFileKeys;
foreach (const FilePath &filePath, d->m_expectedFileNames) { for (const FilePath &filePath : qAsConst(d->m_expectedFileNames)) {
const FilePath cleanAbsFilePath = filePathKey(filePath, KeepLinks); const FilePath cleanAbsFilePath = filePathKey(filePath, KeepLinks);
expectedFileKeys.insert(filePathKey(filePath, KeepLinks)); expectedFileKeys.insert(filePathKey(filePath, KeepLinks));
const FilePath resolvedCleanAbsFilePath = cleanAbsFilePath.canonicalPath(); const FilePath resolvedCleanAbsFilePath = cleanAbsFilePath.canonicalPath();
@@ -1155,14 +1157,15 @@ void DocumentManager::checkForReload()
// handle the IDocuments // handle the IDocuments
QStringList errorStrings; QStringList errorStrings;
QStringList filesToDiff; QStringList filesToDiff;
foreach (IDocument *document, changedIDocuments) { for (IDocument *document : qAsConst(changedIDocuments)) {
IDocument::ChangeTrigger trigger = IDocument::TriggerInternal; IDocument::ChangeTrigger trigger = IDocument::TriggerInternal;
optional<IDocument::ChangeType> type; optional<IDocument::ChangeType> type;
bool changed = false; bool changed = false;
// find out the type & behavior from the two possible files // find out the type & behavior from the two possible files
// behavior is internal if all changes are expected (and none removed) // behavior is internal if all changes are expected (and none removed)
// type is "max" of both types (remove > contents > permissions) // type is "max" of both types (remove > contents > permissions)
foreach (const FilePath &fileKey, d->m_documentsWithWatch.value(document)) { const FilePaths files = d->m_documentsWithWatch.value(document);
for (const FilePath &fileKey : files) {
// was the file reported? // was the file reported?
if (!currentStates.contains(fileKey)) if (!currentStates.contains(fileKey))
continue; continue;
@@ -1379,7 +1382,7 @@ void DocumentManager::saveSettings()
{ {
QVariantList recentFiles; QVariantList recentFiles;
QStringList recentEditorIds; QStringList recentEditorIds;
foreach (const RecentFile &file, d->m_recentFiles) { for (const RecentFile &file : qAsConst(d->m_recentFiles)) {
recentFiles.append(file.first.toVariant()); recentFiles.append(file.first.toVariant());
recentEditorIds.append(file.second.toString()); recentEditorIds.append(file.second.toString());
} }

View File

@@ -90,7 +90,7 @@ SideBarWidget::SideBarWidget(SideBar *sideBar, const QString &id)
Utils::sort(titleList); Utils::sort(titleList);
QString t = id; QString t = id;
if (!titleList.isEmpty()) { if (!titleList.isEmpty()) {
foreach (const QString &itemTitle, titleList) for (const QString &itemTitle : qAsConst(titleList))
m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle)); m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle));
m_comboBox->setCurrentIndex(0); m_comboBox->setCurrentIndex(0);
@@ -139,7 +139,8 @@ void SideBarWidget::setCurrentItem(const QString &id)
m_currentItem->widget()->show(); m_currentItem->widget()->show();
// Add buttons and remember their actions for later removal // Add buttons and remember their actions for later removal
foreach (QToolButton *b, m_currentItem->createToolBarWidgets()) QList<QToolButton *> buttons = m_currentItem->createToolBarWidgets();
for (QToolButton *b : buttons)
m_addedToolBarActions.append(m_toolbar->insertWidget(m_splitAction, b)); m_addedToolBarActions.append(m_toolbar->insertWidget(m_splitAction, b));
} }
@@ -153,7 +154,7 @@ void SideBarWidget::updateAvailableItems()
titleList.append(currentTitle); titleList.append(currentTitle);
Utils::sort(titleList); Utils::sort(titleList);
foreach (const QString &itemTitle, titleList) for (const QString &itemTitle : qAsConst(titleList))
m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle)); m_comboBox->addItem(itemTitle, m_sideBar->idForTitle(itemTitle));
int idx = m_comboBox->findText(currentTitle); int idx = m_comboBox->findText(currentTitle);

View File

@@ -164,7 +164,8 @@ void StatusBarManager::restoreSettings()
leftSplitWidth = m_splitter->widget(0)->sizeHint().width(); leftSplitWidth = m_splitter->widget(0)->sizeHint().width();
} }
int sum = 0; int sum = 0;
foreach (int w, m_splitter->sizes()) const QList<int> sizes = m_splitter->sizes();
for (const int w : sizes)
sum += w; sum += w;
m_splitter->setSizes(QList<int>() << leftSplitWidth << (sum - leftSplitWidth)); m_splitter->setSizes(QList<int>() << leftSplitWidth << (sum - leftSplitWidth));
} }

View File

@@ -201,7 +201,7 @@ static void addThemesFromPath(const QString &path, QList<ThemeEntry> *themes)
themeDir.setNameFilters({extension}); themeDir.setNameFilters({extension});
themeDir.setFilter(QDir::Files); themeDir.setFilter(QDir::Files);
const QStringList themeList = themeDir.entryList(); const QStringList themeList = themeDir.entryList();
foreach (const QString &fileName, themeList) { for (const QString &fileName : qAsConst(themeList)) {
QString id = QFileInfo(fileName).completeBaseName(); QString id = QFileInfo(fileName).completeBaseName();
themes->append(ThemeEntry(Id::fromString(id), themeDir.absoluteFilePath(fileName))); themes->append(ThemeEntry(Id::fromString(id), themeDir.absoluteFilePath(fileName)));
} }

View File

@@ -101,7 +101,8 @@ public:
QTC_ASSERT(QDir::fromNativeSeparators(dir) == dir, return); QTC_ASSERT(QDir::fromNativeSeparators(dir) == dir, return);
const QString dirSlash = dir + QLatin1Char('/'); const QString dirSlash = dir + QLatin1Char('/');
foreach (const QString &key, m_cachedMatches.keys()) { const QList<QString> keys = m_cachedMatches.keys();
for (const QString &key : keys) {
if (key == dir || key.startsWith(dirSlash)) if (key == dir || key.startsWith(dirSlash))
m_cachedMatches.remove(key); m_cachedMatches.remove(key);
} }
@@ -172,7 +173,8 @@ VcsManager *VcsManager::instance()
void VcsManager::extensionsInitialized() void VcsManager::extensionsInitialized()
{ {
// Change signal connections // Change signal connections
foreach (IVersionControl *versionControl, versionControls()) { const QList<IVersionControl *> versionControlList = versionControls();
for (const IVersionControl *versionControl : versionControlList) {
connect(versionControl, &IVersionControl::filesChanged, DocumentManager::instance(), connect(versionControl, &IVersionControl::filesChanged, DocumentManager::instance(),
[](const QStringList fileNames) { [](const QStringList fileNames) {
DocumentManager::notifyFilesChangedInternally( DocumentManager::notifyFilesChangedInternally(
@@ -240,7 +242,8 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const FilePath &inpu
// Nothing: ask the IVersionControls directly. // Nothing: ask the IVersionControls directly.
StringVersionControlPairs allThatCanManage; StringVersionControlPairs allThatCanManage;
foreach (IVersionControl * versionControl, versionControls()) { const QList<IVersionControl *> versionControlList = versionControls();
for (IVersionControl *versionControl : versionControlList) {
FilePath topLevel; FilePath topLevel;
if (versionControl->managesDirectory(FilePath::fromString(directory), &topLevel)) if (versionControl->managesDirectory(FilePath::fromString(directory), &topLevel))
allThatCanManage.push_back(StringVersionControlPair(topLevel.toString(), versionControl)); allThatCanManage.push_back(StringVersionControlPair(topLevel.toString(), versionControl));
@@ -465,9 +468,9 @@ void VcsManager::emitRepositoryChanged(const FilePath &repository)
void VcsManager::clearVersionControlCache() void VcsManager::clearVersionControlCache()
{ {
QStringList repoList = d->m_cachedMatches.keys(); const QStringList repoList = d->m_cachedMatches.keys();
d->clearCache(); d->clearCache();
foreach (const QString &repo, repoList) for (const QString &repo : repoList)
emit m_instance->repositoryChanged(FilePath::fromString(repo)); emit m_instance->repositoryChanged(FilePath::fromString(repo));
} }
@@ -589,7 +592,7 @@ void CorePlugin::testVcsManager()
// From VCSes: // From VCSes:
int expectedCount = 0; int expectedCount = 0;
foreach (const QString &result, results) { for (const QString &result : qAsConst(results)) {
// qDebug() << "Expecting:" << result; // qDebug() << "Expecting:" << result;
QStringList split = result.split(QLatin1Char(':')); QStringList split = result.split(QLatin1Char(':'));