diff --git a/src/plugins/qmljseditor/qmljscompletionassist.cpp b/src/plugins/qmljseditor/qmljscompletionassist.cpp index 21c23274e2e..d3e262bb9e1 100644 --- a/src/plugins/qmljseditor/qmljscompletionassist.cpp +++ b/src/plugins/qmljseditor/qmljscompletionassist.cpp @@ -101,7 +101,7 @@ static void addCompletions(QList *completions, const QIcon &icon, int order) { - foreach (const QString &text, newCompletions) + for (const QString &text : newCompletions) addCompletion(completions, text, icon, order); } @@ -226,7 +226,8 @@ public: _processed.clear(); _propertyProcessor = processor; - foreach (const ObjectValue *scope, _scopeChain->all()) + const QList scopes = _scopeChain->all(); + for (const ObjectValue *scope : scopes) processProperties(scope); } @@ -302,7 +303,7 @@ const Value *getPropertyValue(const ObjectValue *object, return nullptr; const Value *value = object; - foreach (const QString &name, propertyNames) { + for (const QString &name : propertyNames) { if (const ObjectValue *objectValue = value->asObjectValue()) { value = objectValue->lookupMember(name, context); if (!value) @@ -687,7 +688,7 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const AssistInterface * QStringList nCompletions; QString prefix(libVersion.left(toSkip)); nCompletions.reserve(completions.size()); - foreach (const QString &completion, completions) + for (const QString &completion : qAsConst(completions)) if (completion.startsWith(prefix)) nCompletions.append(completion.right(completion.size()-toSkip)); completions = nCompletions; @@ -800,7 +801,8 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const AssistInterface * if (const QmlEnumValue *enumValue = value_cast(value)) { const QString &name = context->imports(document.data())->nameForImportedObject(enumValue->owner(), context.data()); - foreach (const QString &key, enumValue->keys()) { + const QStringList keys = enumValue->keys(); + for (const QString &key : keys) { QString completion; if (name.isEmpty()) completion = QString::fromLatin1("\"%1\"").arg(key); @@ -910,7 +912,7 @@ bool QmlJSCompletionAssistProcessor::acceptsIdleEditor() const Scanner scanner; const QList tokens = scanner(blockText, blockState); const int column = block.position() - m_interface->position(); - foreach (const Token &tk, tokens) { + for (const Token &tk : tokens) { if (column >= tk.begin() && column <= tk.end()) { if (charBeforeCursor == QLatin1Char('/') && tk.is(Token::String)) return true; // path completion inside string literals @@ -1051,7 +1053,7 @@ void QmlJSAssistProposalModel::filter(const QString &prefix) return; QList newCurrentItems; newCurrentItems.reserve(m_currentItems.size()); - foreach (AssistProposalItemInterface *item, m_currentItems) + for (AssistProposalItemInterface *item : qAsConst(m_currentItems)) if (!item->text().startsWith(QLatin1String("__"))) newCurrentItems << item; m_currentItems = newCurrentItems; diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp index 248107e966f..290565051ca 100644 --- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp +++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp @@ -123,13 +123,14 @@ public: QStringList sortedPropertiesWithoutId; - foreach (const QString &property, propertyReader.properties()) + const QStringList properties = propertyReader.properties(); + for (const QString &property : properties) if (property != QLatin1String("id")) sortedPropertiesWithoutId.append(property); sortedPropertiesWithoutId.sort(); - foreach (const QString &property, sortedPropertiesWithoutId) + for (const QString &property : qAsConst(sortedPropertiesWithoutId)) sourcePreview.append(QLatin1String(" ") + property + QLatin1String(": ") + propertyReader.readAstValue(property)); const bool confirm = ComponentNameDialog::go(&componentName, &path, &suffix, @@ -178,7 +179,7 @@ public: if (program->members) astRootNode = program->members->member; - foreach (const QString &property, result) + for (const QString &property : qAsConst(result)) rewriter.removeBindingByName(initializerOfObject(astRootNode), property); } else { qWarning() << Q_FUNC_INFO << "parsing failed:" << newComponentSource; @@ -208,7 +209,7 @@ public: if (!m_idName.isEmpty()) replacement += QLatin1String("id: ") + m_idName + QLatin1Char('\n'); - foreach (const QString &property, result) + for (const QString &property : qAsConst(result)) replacement += property + QLatin1String(": ") + propertyReader.readAstValue(property) + QLatin1Char('\n'); Utils::ChangeSet changes; diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 32ff7895600..1e7534330d4 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -189,7 +189,7 @@ static void appendExtraSelectionsForMessages( const QList &messages, const QTextDocument *document) { - foreach (const DiagnosticMessage &d, messages) { + for (const DiagnosticMessage &d : messages) { const int line = d.loc.startLine; const int column = qMax(1U, d.loc.startColumn); @@ -511,10 +511,10 @@ void QmlJSEditorWidget::setSelectedElements() if (m_qmlJsEditorDocument->semanticInfo().isValid()) { SelectedElement selectedMembers; - QList members - = selectedMembers(m_qmlJsEditorDocument->semanticInfo().document, startPos, endPos); + const QList members + = selectedMembers(m_qmlJsEditorDocument->semanticInfo().document, startPos, endPos); if (!members.isEmpty()) { - foreach (UiObjectMember *m, members) { + for (UiObjectMember *m : members) { offsets << m; } } @@ -768,7 +768,8 @@ void QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor, if (auto importAst = cast(node)) { // if it's a file import, link to the file - foreach (const ImportInfo &import, semanticInfo.document->bind()->imports()) { + const QList imports = semanticInfo.document->bind()->imports(); + for (const ImportInfo &import : imports) { if (import.ast() == importAst && import.type() == ImportType::File) { Utils::Link link(Utils::FilePath::fromString(import.path())); link.linkTextStart = importAst->firstSourceLocation().begin(); @@ -896,7 +897,8 @@ void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e) if (ActionContainer *mcontext = ActionManager::actionContainer(Constants::M_CONTEXT)) { QMenu *contextMenu = mcontext->menu(); - foreach (QAction *action, contextMenu->actions()) { + const QList actions = contextMenu->actions(); + for (QAction *action : actions) { menu->addAction(action); if (action->objectName() == QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT)) menu->addMenu(refactoringMenu); diff --git a/src/plugins/qmljseditor/qmljsfindreferences.cpp b/src/plugins/qmljseditor/qmljsfindreferences.cpp index 7c02a5da291..e0a0f3269aa 100644 --- a/src/plugins/qmljseditor/qmljsfindreferences.cpp +++ b/src/plugins/qmljseditor/qmljsfindreferences.cpp @@ -260,7 +260,8 @@ private: if (root && root->lookupMember(_name, _scopeChain.context())) return check(root); - foreach (const QmlComponentChain *parent, chain->instantiatingComponents()) { + const QList parents = chain->instantiatingComponents(); + for (const QmlComponentChain *parent : parents) { if (contains(parent)) return true; } @@ -278,7 +279,8 @@ private: bool checkQmlScope() { - foreach (const ObjectValue *s, _scopeChain.qmlScopeObjects()) { + const QList scopes = _scopeChain.qmlScopeObjects(); + for (const ObjectValue *s : scopes) { if (check(s)) return true; } @@ -749,8 +751,8 @@ public: // find all idenfifier expressions, try to resolve them and check if the result is in scope FindUsages findUsages(doc, context); - FindUsages::Result results = findUsages(name, scope); - foreach (const SourceLocation &loc, results) + const FindUsages::Result results = findUsages(name, scope); + for (const SourceLocation &loc : results) usages.append(Usage(fileName, matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length)); if (future->isPaused()) future->waitForResume(); @@ -791,8 +793,8 @@ public: // find all idenfifier expressions, try to resolve them and check if the result is in scope FindTypeUsages findUsages(doc, context); - FindTypeUsages::Result results = findUsages(name, scope); - foreach (const SourceLocation &loc, results) + const FindTypeUsages::Result results = findUsages(name, scope); + for (const SourceLocation &loc : results) usages.append(Usage(fileName, matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length)); if (future->isPaused()) future->waitForResume(); @@ -815,7 +817,7 @@ public: void operator()(QList &, const QList &usages) { - foreach (const Usage &u, usages) + for (const Usage &u : usages) future->reportResult(u); future->setProgressValue(future->progressValue() + 1); @@ -892,7 +894,7 @@ static void find_helper(QFutureInterface &future, replacement = name; QStringList files; - foreach (const Document::Ptr &doc, snapshot) { + for (const Document::Ptr &doc : qAsConst(snapshot)) { // ### skip files that don't contain the name token files.append(doc->fileName()); } @@ -974,10 +976,10 @@ QList FindReferences::findUsageOfType(const QString &file QmlJS::Snapshot snapshot = modelManager->snapshot(); - foreach (const QmlJS::Document::Ptr &doc, snapshot) { + for (const QmlJS::Document::Ptr &doc : qAsConst(snapshot)) { FindTypeUsages findUsages(doc, context); - FindTypeUsages::Result results = findUsages(typeName, targetValue); - foreach (const SourceLocation &loc, results) { + const FindTypeUsages::Result results = findUsages(typeName, targetValue); + for (const SourceLocation &loc : results) { usages.append(Usage(doc->fileName(), matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length)); } } diff --git a/src/plugins/qmljseditor/qmljshoverhandler.cpp b/src/plugins/qmljseditor/qmljshoverhandler.cpp index d761c3e4cd7..085b6ce157b 100644 --- a/src/plugins/qmljseditor/qmljshoverhandler.cpp +++ b/src/plugins/qmljseditor/qmljshoverhandler.cpp @@ -268,15 +268,17 @@ void QmlJSHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos, R bool QmlJSHoverHandler::matchDiagnosticMessage(QmlJSEditorWidget *qmlEditor, int pos) { - foreach (const QTextEdit::ExtraSelection &sel, - qmlEditor->extraSelections(TextEditorWidget::CodeWarningsSelection)) { + const QList selections = + qmlEditor->extraSelections(TextEditorWidget::CodeWarningsSelection); + for (const QTextEdit::ExtraSelection &sel : selections) { if (pos >= sel.cursor.selectionStart() && pos <= sel.cursor.selectionEnd()) { setToolTip(sel.format.toolTip()); return true; } } - foreach (const QTextLayout::FormatRange &range, - qmlEditor->qmlJsEditorDocument()->diagnosticRanges()) { + const QVector ranges = + qmlEditor->qmlJsEditorDocument()->diagnosticRanges(); + for (const QTextLayout::FormatRange &range : ranges) { if (pos >= range.start && pos < range.start+range.length) { setToolTip(range.format.toolTip()); return true; @@ -357,7 +359,8 @@ void QmlJSHoverHandler::handleImport(const ScopeChain &scopeChain, AST::UiImport if (!imports) return; - foreach (const Import &import, imports->all()) { + const QList importList = imports->all(); + for (const Import &import : importList) { if (import.info.ast() == node) { if (import.info.type() == ImportType::Library && !import.libraryPath.isEmpty()) { diff --git a/src/plugins/qmljseditor/qmljsquickfixes.cpp b/src/plugins/qmljseditor/qmljsquickfixes.cpp index d0f63d74ae0..9536738ac3e 100644 --- a/src/plugins/qmljseditor/qmljsquickfixes.cpp +++ b/src/plugins/qmljseditor/qmljsquickfixes.cpp @@ -154,7 +154,7 @@ void matchAddAnalysisMessageSuppressionCommentQuickFix(const QmlJSQuickFixInterf { const QList &messages = interface->semanticInfo().staticAnalysisMessages; - foreach (const StaticAnalysis::Message &message, messages) { + for (const StaticAnalysis::Message &message : messages) { if (interface->currentFile()->isCursorOn(message.location)) { result << new AnalysizeMessageSuppressionOperation(interface, message); return; diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp index 8909c471e0e..bf0454a3d9c 100644 --- a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp +++ b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp @@ -59,7 +59,7 @@ namespace { static bool isIdScope(const ObjectValue *scope, const QList &chain) { - foreach (const QmlComponentChain *c, chain) { + for (const QmlComponentChain *c : chain) { if (c->idScope() == scope) return true; if (isIdScope(scope, c->instantiatingComponents())) @@ -391,7 +391,7 @@ protected: void addMessages(QList messages, const Document::Ptr &doc) { - foreach (const DiagnosticMessage &d, messages) { + for (const DiagnosticMessage &d : messages) { int line = d.loc.startLine; int column = qMax(1U, d.loc.startColumn); int length = d.loc.length; @@ -426,7 +426,7 @@ protected: void addMessages(const QList &messages, const Document::Ptr &doc) { - foreach (const StaticAnalysis::Message &d, messages) { + for (const StaticAnalysis::Message &d : messages) { int line = d.location.startLine; int column = qMax(1U, d.location.startColumn); int length = d.location.length; diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp index a62696b8abe..08d5a4d4c3c 100644 --- a/src/plugins/qmljseditor/qmloutlinemodel.cpp +++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp @@ -400,7 +400,7 @@ bool QmlOutlineModel::dropMimeData(const QMimeData *data, Qt::DropAction action, stream >> rowPath; QModelIndex index; - foreach (int row, rowPath) { + for (int row : qAsConst(rowPath)) { index = this->index(row, 0, index); if (!index.isValid()) continue; @@ -883,7 +883,7 @@ void QmlOutlineModel::reparentNodes(QmlOutlineItem *targetItem, int row, QListfileName())); file->setChangeSet(changeSet); - foreach (const Utils::ChangeSet::Range &range, changedRanges) { + for (const Utils::ChangeSet::Range &range : qAsConst(changedRanges)) { file->appendIndentRange(range); } file->apply(); diff --git a/src/plugins/qmljseditor/qmltaskmanager.cpp b/src/plugins/qmljseditor/qmltaskmanager.cpp index 366702f8016..1e84d8a671e 100644 --- a/src/plugins/qmljseditor/qmltaskmanager.cpp +++ b/src/plugins/qmljseditor/qmltaskmanager.cpp @@ -63,7 +63,7 @@ QmlTaskManager::QmlTaskManager() static Tasks convertToTasks(const QList &messages, const FilePath &fileName, Utils::Id category) { Tasks result; - foreach (const DiagnosticMessage &msg, messages) { + for (const DiagnosticMessage &msg : messages) { Task::TaskType type = msg.isError() ? Task::Error : Task::Warning; Task task(type, msg.message, fileName, msg.loc.startLine, category); result += task; @@ -74,17 +74,18 @@ static Tasks convertToTasks(const QList &messages, const File static Tasks convertToTasks(const QList &messages, const FilePath &fileName, Utils::Id category) { QList diagnostics; - foreach (const StaticAnalysis::Message &msg, messages) + for (const StaticAnalysis::Message &msg : messages) diagnostics += msg.toDiagnosticMessage(); return convertToTasks(diagnostics, fileName, category); } -void QmlTaskManager::collectMessages( - QFutureInterface &future, - Snapshot snapshot, QList projectInfos, - ViewerContext vContext, bool updateSemantic) +void QmlTaskManager::collectMessages(QFutureInterface &future, + Snapshot snapshot, + const QList &projectInfos, + ViewerContext vContext, + bool updateSemantic) { - foreach (const ModelManagerInterface::ProjectInfo &info, projectInfos) { + for (const ModelManagerInterface::ProjectInfo &info : projectInfos) { QHash > linkMessages; ContextPtr context; if (updateSemantic) { @@ -92,7 +93,7 @@ void QmlTaskManager::collectMessages( context = link(&linkMessages); } - foreach (const QString &fileName, info.sourceFiles) { + for (const QString &fileName : qAsConst(info.sourceFiles)) { Document::Ptr document = snapshot.document(fileName); if (!document) continue; @@ -157,15 +158,15 @@ void QmlTaskManager::updateMessagesNow(bool updateSemantic) void QmlTaskManager::documentsRemoved(const QStringList &path) { - foreach (const QString &item, path) + for (const QString &item : path) removeTasksForFile(item); } void QmlTaskManager::displayResults(int begin, int end) { for (int i = begin; i < end; ++i) { - FileErrorMessages result = m_messageCollector.resultAt(i); - foreach (const Task &task, result.tasks) { + const ProjectExplorer::Tasks tasks = m_messageCollector.resultAt(i).tasks; + for (const Task &task : tasks) { insertTask(task); } } @@ -189,7 +190,7 @@ void QmlTaskManager::removeTasksForFile(const QString &fileName) { if (m_docsWithTasks.contains(fileName)) { const Tasks tasks = m_docsWithTasks.value(fileName); - foreach (const Task &task, tasks) + for (const Task &task : tasks) TaskHub::removeTask(task); m_docsWithTasks.remove(fileName); } diff --git a/src/plugins/qmljseditor/qmltaskmanager.h b/src/plugins/qmljseditor/qmltaskmanager.h index dfc8174ba12..692f74f3c41 100644 --- a/src/plugins/qmljseditor/qmltaskmanager.h +++ b/src/plugins/qmljseditor/qmltaskmanager.h @@ -69,7 +69,7 @@ private: }; static void collectMessages(QFutureInterface &future, QmlJS::Snapshot snapshot, - QList projectInfos, + const QList &projectInfos, QmlJS::ViewerContext vContext, bool updateSemantic); diff --git a/src/plugins/qmljseditor/quicktoolbar.cpp b/src/plugins/qmljseditor/quicktoolbar.cpp index 15dec5a80c5..5318c8d51ac 100644 --- a/src/plugins/qmljseditor/quicktoolbar.cpp +++ b/src/plugins/qmljseditor/quicktoolbar.cpp @@ -129,20 +129,20 @@ void QuickToolBar::apply(TextEditor::TextEditorWidget *editorWidget, Document::P if (scopeChain && scopeObject) { m_prototypes.clear(); - foreach (const ObjectValue *object, - PrototypeIterator(scopeObject, scopeChain->context()).all()) { + const QList objects + = PrototypeIterator(scopeObject, scopeChain->context()).all(); + for (const ObjectValue *object : objects) m_prototypes.append(object->className()); - } if (m_prototypes.contains(QLatin1String("PropertyChanges"))) { isPropertyChanges = true; const ObjectValue *targetObject = getPropertyChangesTarget(node, *scopeChain); m_prototypes.clear(); if (targetObject) { - foreach (const ObjectValue *object, - PrototypeIterator(targetObject, scopeChain->context()).all()) { + const QList objects + = PrototypeIterator(targetObject, scopeChain->context()).all(); + for (const ObjectValue *object : objects) m_prototypes.append(object->className()); - } } } }