From a4d6956c737b365eefd95a5b2434c90c2c0d38f3 Mon Sep 17 00:00:00 2001 From: Artem Sokolovskii Date: Mon, 16 May 2022 12:49:04 +0200 Subject: [PATCH] QmlDesigner: Remove foreach / Q_FOREACH usage mostly in components Task-number: QTCREATORBUG-27464 Change-Id: Id7c1ebdc83ef355fe7a978ce57757f63005de0ab Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: Thomas Hartmann --- .../components/pathtool/pathitem.cpp | 37 ++++++++++--------- .../pathtool/pathselectionmanipulator.cpp | 15 ++++---- .../components/pathtool/pathtool.cpp | 2 +- .../components/pathtool/pathtoolview.cpp | 2 +- .../propertyeditorqmlbackend.cpp | 11 ++++-- .../propertyeditor/propertyeditorvalue.cpp | 15 ++++---- .../propertyeditor/propertyeditorview.cpp | 11 +++--- .../propertyeditor/qmlanchorbindingproxy.cpp | 4 +- .../richtexteditor/richtexteditor.cpp | 2 +- .../stateseditor/stateseditorview.cpp | 10 ++--- .../components/texttool/texttool.cpp | 2 +- .../entertabdesigneraction.cpp | 3 +- .../componentsplugin/tabviewindexmodel.cpp | 7 ++-- src/plugins/qmldesigner/documentmanager.cpp | 10 +++-- .../qmldesigner/openuiqmlfiledialog.cpp | 2 +- src/plugins/qmldesigner/qmldesignerplugin.cpp | 3 +- 16 files changed, 74 insertions(+), 62 deletions(-) diff --git a/src/plugins/qmldesigner/components/pathtool/pathitem.cpp b/src/plugins/qmldesigner/components/pathtool/pathitem.cpp index 47df2b3e9fd..6a43508bde8 100644 --- a/src/plugins/qmldesigner/components/pathtool/pathitem.cpp +++ b/src/plugins/qmldesigner/components/pathtool/pathitem.cpp @@ -134,17 +134,17 @@ void PathItem::writePathToProperty() ModelNode pathNode = pathModelNode(formEditorItem()); - pathNode.view()->executeInTransaction("PathItem::writePathToProperty", [this, &pathNode](){ + pathNode.view()->executeInTransaction("PathItem::writePathToProperty", [this, &pathNode]() { QList pathSegmentNodes = pathNode.nodeListProperty("pathElements").toModelNodeList(); - foreach (ModelNode pathSegment, pathSegmentNodes) + for (ModelNode pathSegment : pathSegmentNodes) pathSegment.destroy(); if (!m_cubicSegments.isEmpty()) { pathNode.variantProperty("startX").setValue(m_cubicSegments.constFirst().firstControlPoint().coordinate().x()); pathNode.variantProperty("startY").setValue(m_cubicSegments.constFirst().firstControlPoint().coordinate().y()); - foreach (const CubicSegment &cubicSegment, m_cubicSegments) { + for (const CubicSegment &cubicSegment : qAsConst(m_cubicSegments)) { writePathAttributes(pathNode, cubicSegment.attributes()); writePathPercent(pathNode, cubicSegment.percent()); @@ -171,7 +171,7 @@ void PathItem::writePathAsCubicSegmentsOnly() QList pathSegmentNodes = pathNode.nodeListProperty("pathElements").toModelNodeList(); - foreach (ModelNode pathSegment, pathSegmentNodes) + for (ModelNode pathSegment : pathSegmentNodes) pathSegment.destroy(); if (!m_cubicSegments.isEmpty()) { @@ -179,7 +179,7 @@ void PathItem::writePathAsCubicSegmentsOnly() pathNode.variantProperty("startY").setValue(m_cubicSegments.constFirst().firstControlPoint().coordinate().y()); - foreach (const CubicSegment &cubicSegment, m_cubicSegments) { + for (const CubicSegment &cubicSegment : qAsConst(m_cubicSegments)) { writePathAttributes(pathNode, cubicSegment.attributes()); writePathPercent(pathNode, cubicSegment.percent()); writeCubicPath(pathNode, cubicSegment); @@ -234,7 +234,7 @@ static void drawCubicSegments(const QList &cubicSegments, QPainter QPainterPath curvePainterPath(cubicSegments.constFirst().firstControlPoint().coordinate()); - foreach (const CubicSegment &cubicSegment, cubicSegments) + for (const CubicSegment &cubicSegment : cubicSegments) addCubicSegmentToPainterPath(cubicSegment, curvePainterPath); painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); @@ -269,7 +269,7 @@ static void drawControlLines(const QList &cubicSegments, QPainter painter->save(); painter->setRenderHint(QPainter::Antialiasing, false); - foreach (const CubicSegment &cubicSegment, cubicSegments) + for (const CubicSegment &cubicSegment : cubicSegments) drawControlLine(cubicSegment, painter); painter->restore(); @@ -313,7 +313,7 @@ static void drawControlPoints(const QList &controlPoints, const QL { painter->save(); - foreach (const ControlPoint &controlPoint, controlPoints) + for (const ControlPoint &controlPoint : controlPoints) drawControlPoint(controlPoint, selectionPoints, painter); painter->restore(); @@ -337,7 +337,7 @@ static void drawPostionOverlays(const QList &selectedPoints, QPa painter->setFont(font); painter->setPen(QColor(0, 0, 0)); - foreach (const SelectionPoint &selectedPoint, selectedPoints) + for (const SelectionPoint &selectedPoint : selectedPoints) drawPositionOverlay(selectedPoint.controlPoint, painter); painter->restore(); @@ -465,7 +465,7 @@ static QRectF boundingRectForPath(const QList &controlPoints) double yMinimum = 0.; double yMaximum = 0.; - foreach (const ControlPoint & controlPoint, controlPoints) { + for (const ControlPoint & controlPoint : controlPoints) { xMinimum = qMin(xMinimum, controlPoint.coordinate().x()); xMaximum = qMax(xMaximum, controlPoint.coordinate().x()); yMinimum = qMin(yMinimum, controlPoint.coordinate().y()); @@ -507,7 +507,8 @@ void PathItem::readControlPoints() QMap actualAttributes; double percent = -1.0; - foreach (const ModelNode &childNode, pathNode.nodeListProperty("pathElements").toModelNodeList()) { + const QList childNodes = pathNode.nodeListProperty("pathElements").toModelNodeList(); + for (const ModelNode &childNode : childNodes) { if (childNode.type() == "QtQuick.PathAttribute") { actualAttributes.insert(childNode.variantProperty("name").value().toString(), childNode.variantProperty("value").value()); @@ -554,7 +555,7 @@ static CubicSegment getMinimumDistanceSegment(const QPointF &pickPoint, const QL CubicSegment minimumDistanceSegment; double actualMinimumDistance = maximumDistance; - foreach (const CubicSegment &cubicSegment, cubicSegments) { + for (const CubicSegment &cubicSegment : cubicSegments) { double tSegment = 0.; double cubicSegmentMinimumDistance = cubicSegment.minimumDistance(pickPoint, tSegment); if (cubicSegmentMinimumDistance < actualMinimumDistance) { @@ -689,7 +690,7 @@ const QList PathItem::controlPoints() const if (!m_cubicSegments.isEmpty()) controlPointList.append(m_cubicSegments.constFirst().firstControlPoint()); - foreach (const CubicSegment &cubicSegment, m_cubicSegments) { + for (const CubicSegment &cubicSegment : qAsConst(m_cubicSegments)) { controlPointList.append(cubicSegment.secondControlPoint()); controlPointList.append(cubicSegment.thirdControlPoint()); controlPointList.append(cubicSegment.fourthControlPoint()); @@ -703,7 +704,7 @@ const QList PathItem::controlPoints() const bool hasLineOrQuadPathElements(const QList &modelNodes) { - foreach (const ModelNode &modelNode, modelNodes) { + for (const ModelNode &modelNode : modelNodes) { if (modelNode.type() == "QtQuick.PathLine" || modelNode.type() == "QtQuick.PathQuad") return true; @@ -752,7 +753,7 @@ static bool controlPointIsNearMousePosition(const ControlPoint &controlPoint, co static bool controlPointsAreNearMousePosition(const QList &controlPoints, const QPointF &mousePosition) { - foreach (const ControlPoint &controlPoint, controlPoints) { + for (const ControlPoint &controlPoint : controlPoints) { if (controlPointIsNearMousePosition(controlPoint, mousePosition)) return true; } @@ -762,7 +763,7 @@ static bool controlPointsAreNearMousePosition(const QList &control static ControlPoint pickControlPoint(const QList &controlPoints, const QPointF &mousePosition) { - foreach (const ControlPoint &controlPoint, controlPoints) { + for (const ControlPoint &controlPoint : controlPoints) { if (controlPointIsNearMousePosition(controlPoint, mousePosition)) return controlPoint; } @@ -837,7 +838,7 @@ void PathItem::updatePathModelNodes(const QList &changedPoints) RewriterTransaction rewriterTransaction = formEditorItem()->qmlItemNode().view()->beginRewriterTransaction(QByteArrayLiteral("PathItem::createCubicSegmentContextMenu")); - foreach (SelectionPoint changedPoint, changedPoints) + for (SelectionPoint changedPoint : changedPoints) changedPoint.controlPoint.updateModelNode(); rewriterTransaction.commit(); @@ -923,7 +924,7 @@ QList cubicSegmentsContainingControlPoint(const ControlPoint &cont { QList cubicSegmentsHasControlPoint; - foreach (const CubicSegment &cubicSegment, allCubicSegments) { + for (const CubicSegment &cubicSegment : allCubicSegments) { if (cubicSegment.controlPoints().contains(controlPoint)) cubicSegmentsHasControlPoint.append(cubicSegment); } diff --git a/src/plugins/qmldesigner/components/pathtool/pathselectionmanipulator.cpp b/src/plugins/qmldesigner/components/pathtool/pathselectionmanipulator.cpp index 6df69762334..7d09958bd3c 100644 --- a/src/plugins/qmldesigner/components/pathtool/pathselectionmanipulator.cpp +++ b/src/plugins/qmldesigner/components/pathtool/pathselectionmanipulator.cpp @@ -119,13 +119,13 @@ QList PathSelectionManipulator::allControlPoints() { QList controlPoints; - foreach (const SelectionPoint &selectionPoint, m_singleSelectedPoints) + for (const SelectionPoint &selectionPoint : qAsConst(m_singleSelectedPoints)) controlPoints.append(selectionPoint.controlPoint); - foreach (const SelectionPoint &selectionPoint, m_automaticallyAddedSinglePoints) + for (const SelectionPoint &selectionPoint : qAsConst(m_automaticallyAddedSinglePoints)) controlPoints.append(selectionPoint.controlPoint); - foreach (const SelectionPoint &selectionPoint, m_multiSelectedPoints) + for (const SelectionPoint &selectionPoint : qAsConst(m_multiSelectedPoints)) controlPoints.append(selectionPoint.controlPoint); return controlPoints; @@ -155,7 +155,8 @@ void PathSelectionManipulator::updateMultiSelection(const QPointF &updatePoint) QRectF selectionRect(m_startPoint, updatePoint); - foreach (const ControlPoint &controlPoint, m_pathItem->controlPoints()) { + const QList controlPoints = m_pathItem->controlPoints(); + for (const ControlPoint &controlPoint : controlPoints) { if (selectionRect.contains(controlPoint.coordinate())) addMultiSelectionControlPoint(controlPoint); } @@ -236,7 +237,7 @@ QPointF manipulatedVector(const QPointF &vector, Qt::KeyboardModifiers keyboardM static void moveControlPoints(const QList &movePoints, const QPointF &offsetVector) { - foreach (SelectionPoint movePoint, movePoints) + for (SelectionPoint movePoint : movePoints) movePoint.controlPoint.setCoordinate(movePoint.startPosition + offsetVector); } @@ -266,11 +267,11 @@ bool PathSelectionManipulator::isMoving() const void PathSelectionManipulator::updateMultiSelectedStartPoint() { - QList oldSelectionPoints = m_multiSelectedPoints; + const QList oldSelectionPoints = m_multiSelectedPoints; m_multiSelectedPoints.clear(); - foreach (SelectionPoint selectionPoint, oldSelectionPoints) { + for (SelectionPoint selectionPoint : oldSelectionPoints) { selectionPoint.startPosition = selectionPoint.controlPoint.coordinate(); m_multiSelectedPoints.append(selectionPoint); } diff --git a/src/plugins/qmldesigner/components/pathtool/pathtool.cpp b/src/plugins/qmldesigner/components/pathtool/pathtool.cpp index 88fdd70f5f3..52976bc0e9c 100644 --- a/src/plugins/qmldesigner/components/pathtool/pathtool.cpp +++ b/src/plugins/qmldesigner/components/pathtool/pathtool.cpp @@ -277,7 +277,7 @@ void PathTool::instancesParentChanged(const QList & /*itemLis void PathTool::instancePropertyChange(const QList > &propertyList) { using ModelNodePropertyNamePair = QPair; - foreach (const ModelNodePropertyNamePair &propertyPair, propertyList) { + for (const ModelNodePropertyNamePair &propertyPair : propertyList) { if (propertyPair.first == m_pathItem->formEditorItem()->qmlItemNode().modelNode() && propertyPair.second == "path") m_pathItem->updatePath(); diff --git a/src/plugins/qmldesigner/components/pathtool/pathtoolview.cpp b/src/plugins/qmldesigner/components/pathtool/pathtoolview.cpp index ea1e28832ad..063b2f7f19f 100644 --- a/src/plugins/qmldesigner/components/pathtool/pathtoolview.cpp +++ b/src/plugins/qmldesigner/components/pathtool/pathtoolview.cpp @@ -78,7 +78,7 @@ bool variantPropertyInEditedPath(const VariantProperty &variantProperty, const M bool changesEditedPath(const QList &propertyList, const ModelNode &editingPathViewModelNode) { - foreach (const VariantProperty variantProperty, propertyList) { + for (const VariantProperty &variantProperty : propertyList) { if (variantPropertyInEditedPath(variantProperty, editingPathViewModelNode)) return true; } diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index c73290bf76a..8026fc7d6f1 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -79,7 +79,7 @@ QmlJS::SimpleReaderNode::Ptr templateConfiguration() QStringList variantToStringList(const QVariant &variant) { QStringList stringList; - foreach (const QVariant &singleValue, variant.toList()) + for (const QVariant &singleValue : variant.toList()) stringList << singleValue.toString(); return stringList; @@ -410,7 +410,8 @@ void PropertyEditorQmlBackend::setup(const QmlObjectNode &qmlObjectNode, const Q if (propertyEditorBenchmark().isInfoEnabled()) time.start(); - foreach (const PropertyName &propertyName, qmlObjectNode.modelNode().metaInfo().propertyNames()) + const QList propertyNames = qmlObjectNode.modelNode().metaInfo().propertyNames(); + for (const PropertyName &propertyName : propertyNames) createPropertyEditorValue(qmlObjectNode, propertyName, qmlObjectNode.instanceValue(propertyName), propertyEditor); setupLayoutAttachedProperties(qmlObjectNode, propertyEditor); @@ -508,7 +509,8 @@ void PropertyEditorQmlBackend::initialSetup(const TypeName &typeName, const QUrl { NodeMetaInfo metaInfo = propertyEditor->model()->metaInfo(typeName); - foreach (const PropertyName &propertyName, metaInfo.propertyNames()) + const QList propertyNames = metaInfo.propertyNames(); + for (const PropertyName &propertyName : propertyNames) setupPropertyEditorValue(propertyName, propertyEditor, QString::fromUtf8(metaInfo.propertyTypeName(propertyName))); auto valueObject = qobject_cast(variantToQObject( @@ -898,7 +900,8 @@ void PropertyEditorQmlBackend::setValueforAuxiliaryProperties(const QmlObjectNod QUrl PropertyEditorQmlBackend::getQmlUrlForMetaInfo(const NodeMetaInfo &metaInfo, TypeName &className) { if (metaInfo.isValid()) { - foreach (const NodeMetaInfo &info, metaInfo.classHierarchy()) { + const QList hierarchy = metaInfo.classHierarchy(); + for (const NodeMetaInfo &info : hierarchy) { QUrl fileUrl = fileToUrl(locateQmlFile(info, QString::fromUtf8(qmlFileName(info)))); if (fileUrl.isValid()) { className = info.typeName(); diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp index c447d6c4a96..b378a92c6bc 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp @@ -600,10 +600,10 @@ void PropertyEditorNodeWrapper::remove() } m_modelNode = QmlDesigner::ModelNode(); - foreach (const QString &propertyName, m_valuesPropertyMap.keys()) + const QStringList propertyNames = m_valuesPropertyMap.keys(); + for (const QString &propertyName : propertyNames) m_valuesPropertyMap.clear(propertyName); - foreach (QObject *object, m_valuesPropertyMap.children()) - delete object; + qDeleteAll(m_valuesPropertyMap.children()); emit propertiesChanged(); emit existsChanged(); } @@ -633,12 +633,13 @@ void PropertyEditorNodeWrapper::setup() Q_ASSERT(m_editorValue->modelNode().isValid()); if ((m_editorValue->modelNode().isValid() && m_modelNode.isValid())) { QmlDesigner::QmlObjectNode qmlObjectNode(m_modelNode); - foreach ( const QString &propertyName, m_valuesPropertyMap.keys()) + const QStringList propertyNames = m_valuesPropertyMap.keys(); + for (const QString &propertyName : propertyNames) m_valuesPropertyMap.clear(propertyName); - foreach (QObject *object, m_valuesPropertyMap.children()) - delete object; + qDeleteAll(m_valuesPropertyMap.children()); - foreach (const QmlDesigner::PropertyName &propertyName, m_modelNode.metaInfo().propertyNames()) { + const QList propertyNameList = m_modelNode.metaInfo().propertyNames(); + for (const QmlDesigner::PropertyName &propertyName : propertyNameList) { if (qmlObjectNode.isValid()) { auto valueObject = new PropertyEditorValue(&m_valuesPropertyMap); valueObject->setName(propertyName); diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp index 6cf8a4a7a30..126dd67c2e7 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp @@ -463,7 +463,8 @@ void PropertyEditorView::setupQmlBackend() TypeName diffClassName; if (commonAncestor.isValid()) { diffClassName = commonAncestor.typeName(); - foreach (const NodeMetaInfo &metaInfo, commonAncestor.classHierarchy()) { + const QList hierarchy = commonAncestor.classHierarchy(); + for (const NodeMetaInfo &metaInfo : hierarchy) { if (PropertyEditorQmlBackend::checkIfUrlExists(qmlSpecificsFile)) break; qmlSpecificsFile = PropertyEditorQmlBackend::getQmlFileUrl(metaInfo.typeName() + "Specifics", metaInfo); @@ -640,7 +641,7 @@ void PropertyEditorView::propertiesRemoved(const QList& proper if (noValidSelection()) return; - foreach (const AbstractProperty &property, propertyList) { + for (const AbstractProperty &property : propertyList) { ModelNode node(property.parentModelNode()); if (node.isRootNode() && !m_selectedNode.isRootNode()) @@ -678,7 +679,7 @@ void PropertyEditorView::variantPropertiesChanged(const QList& if (noValidSelection()) return; - foreach (const VariantProperty &property, propertyList) { + for (const VariantProperty &property : propertyList) { ModelNode node(property.parentModelNode()); if (propertyIsAttachedLayoutProperty(property.name())) @@ -701,7 +702,7 @@ void PropertyEditorView::bindingPropertiesChanged(const QList& if (noValidSelection()) return; - foreach (const BindingProperty &property, propertyList) { + for (const BindingProperty &property : propertyList) { ModelNode node(property.parentModelNode()); if (property.isAliasExport()) @@ -809,7 +810,7 @@ void PropertyEditorView::instancePropertyChanged(const QList; - foreach (const ModelNodePropertyPair &propertyPair, propertyList) { + for (const ModelNodePropertyPair &propertyPair : propertyList) { const ModelNode modelNode = propertyPair.first; const QmlObjectNode qmlObjectNode(modelNode); const PropertyName propertyName = propertyPair.second; diff --git a/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.cpp b/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.cpp index 2664f2c7a90..fd16a282920 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.cpp @@ -592,11 +592,11 @@ QStringList QmlAnchorBindingProxy::possibleTargetItems() const itemList.removeOne(m_qmlItemNode); //We currently have no instanceChildren(). //So we double check here if the instanceParents are equal. - foreach (const QmlItemNode &node, itemList) + for (const QmlItemNode &node : qAsConst(itemList)) if (node.isValid() && (node.instanceParent().modelNode() != m_qmlItemNode.instanceParent().modelNode())) itemList.removeAll(node); - foreach (const QmlItemNode &itemNode, itemList) { + for (const QmlItemNode &itemNode : qAsConst(itemList)) { if (itemNode.isValid() && !itemNode.id().isEmpty()) stringList.append(itemNode.id()); } diff --git a/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp b/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp index 5121de76853..2841d566164 100644 --- a/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp +++ b/src/plugins/qmldesigner/components/richtexteditor/richtexteditor.cpp @@ -546,7 +546,7 @@ void RichTextEditor::setupFontActions() w->setEditable(true); const QList standardSizes = QFontDatabase::standardSizes(); - foreach (int size, standardSizes) + for (const int size : standardSizes) w->addItem(QString::number(size)); w->setCurrentText(QString::number(ui->textEdit->currentCharFormat().font().pointSize())); connect(w, &QComboBox::textActivated, [this](const QString &p) { diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp index 001d356516b..e9de5defb29 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp @@ -286,8 +286,8 @@ bool StatesEditorView::validStateName(const QString &name) const { if (name == tr("base state")) return false; - QList modelStates = rootStateGroup().allStates(); - foreach (const QmlModelState &state, modelStates) { + const QList modelStates = rootStateGroup().allStates(); + for (const QmlModelState &state : modelStates) { if (state.name() == name) return false; } @@ -491,7 +491,7 @@ void StatesEditorView::modelAboutToBeDetached(Model *model) void StatesEditorView::propertiesRemoved(const QList& propertyList) { - foreach (const AbstractProperty &property, propertyList) { + for (const AbstractProperty &property : propertyList) { if (property.name() == "states" && property.parentModelNode().isRootNode()) resetModel(); if (property.name() == "when" && QmlModelState::isValidQmlModelState(property.parentModelNode())) @@ -548,7 +548,7 @@ void StatesEditorView::bindingPropertiesChanged(const QList &pr { Q_UNUSED(propertyChange) - foreach (const BindingProperty &property, propertyList) { + for (const BindingProperty &property : propertyList) { if (property.name() == "when" && QmlModelState::isValidQmlModelState(property.parentModelNode())) resetModel(); } @@ -588,7 +588,7 @@ void StatesEditorView::instancesPreviewImageChanged(const QVector &no int minimumIndex = 10000; int maximumIndex = -1; - foreach (const ModelNode &node, nodeList) { + for (const ModelNode &node : nodeList) { if (node.isRootNode()) { minimumIndex = qMin(minimumIndex, 0); maximumIndex = qMax(maximumIndex, 0); diff --git a/src/plugins/qmldesigner/components/texttool/texttool.cpp b/src/plugins/qmldesigner/components/texttool/texttool.cpp index a8b5ac044ae..8b271a7f701 100644 --- a/src/plugins/qmldesigner/components/texttool/texttool.cpp +++ b/src/plugins/qmldesigner/components/texttool/texttool.cpp @@ -240,7 +240,7 @@ void TextTool::instancesParentChanged(const QList & /*itemLis void TextTool::instancePropertyChange(const QList > &propertyList) { using ModelNodePropertyNamePair = QPair; - foreach (const ModelNodePropertyNamePair &propertyPair, propertyList) { + for (const ModelNodePropertyNamePair &propertyPair : propertyList) { if (propertyPair.first == textItem()->formEditorItem()->qmlItemNode().modelNode() && propertyPair.second == "text") textItem()->updateText(); diff --git a/src/plugins/qmldesigner/componentsplugin/entertabdesigneraction.cpp b/src/plugins/qmldesigner/componentsplugin/entertabdesigneraction.cpp index 7973bf565c0..0dccf93d2f1 100644 --- a/src/plugins/qmldesigner/componentsplugin/entertabdesigneraction.cpp +++ b/src/plugins/qmldesigner/componentsplugin/entertabdesigneraction.cpp @@ -86,7 +86,8 @@ void EnterTabDesignerAction::updateContext() && selectedModelNode.metaInfo().isSubclassOf("QtQuick.Controls.TabView")) { const NodeAbstractProperty defaultProperty = selectedModelNode.defaultNodeAbstractProperty(); - foreach (const QmlDesigner::ModelNode &childModelNode, defaultProperty.directSubNodes()) { + const QList childModelNodes = defaultProperty.directSubNodes(); + for (const QmlDesigner::ModelNode &childModelNode : childModelNodes) { createActionForTab(childModelNode); } } diff --git a/src/plugins/qmldesigner/componentsplugin/tabviewindexmodel.cpp b/src/plugins/qmldesigner/componentsplugin/tabviewindexmodel.cpp index ab5c831baef..225ab5e7442 100644 --- a/src/plugins/qmldesigner/componentsplugin/tabviewindexmodel.cpp +++ b/src/plugins/qmldesigner/componentsplugin/tabviewindexmodel.cpp @@ -61,10 +61,11 @@ void TabViewIndexModel::setupModel() if (m_modelNode.isValid() && m_modelNode.metaInfo().isValid() && m_modelNode.metaInfo().isSubclassOf("QtQuick.Controls.TabView")) { - - foreach (const QmlDesigner::ModelNode &childModelNode, m_modelNode.defaultNodeAbstractProperty().directSubNodes()) { + const QList childModelNodes + = m_modelNode.defaultNodeAbstractProperty().directSubNodes(); + for (const QmlDesigner::ModelNode &childModelNode : childModelNodes) { if (childModelNode.metaInfo().isValid() - && childModelNode.metaInfo().isSubclassOf("QtQuick.Controls.Tab")) { + && childModelNode.metaInfo().isSubclassOf("QtQuick.Controls.Tab")) { QmlDesigner::QmlItemNode itemNode(childModelNode); if (itemNode.isValid()) { m_tabViewIndexModel.append(itemNode.instanceValue("title").toString()); diff --git a/src/plugins/qmldesigner/documentmanager.cpp b/src/plugins/qmldesigner/documentmanager.cpp index 453dd96232a..65235aca914 100644 --- a/src/plugins/qmldesigner/documentmanager.cpp +++ b/src/plugins/qmldesigner/documentmanager.cpp @@ -67,7 +67,8 @@ static inline QHash getProperties(const ModelNode &node) { QHash propertyHash; if (QmlObjectNode::isValidQmlObjectNode(node)) { - foreach (const AbstractProperty &abstractProperty, node.properties()) { + const QList abstractProperties = node.properties(); + for (const AbstractProperty &abstractProperty : abstractProperties) { if (abstractProperty.isVariantProperty() || (abstractProperty.isBindingProperty() && !abstractProperty.name().contains("anchors."))) @@ -91,9 +92,10 @@ static inline QHash getProperties(const ModelNode &node) static inline void applyProperties(ModelNode &node, const QHash &propertyHash) { - QHash auxiliaryData = node.auxiliaryData(); + const QHash auxiliaryData = node.auxiliaryData(); - foreach (const PropertyName &propertyName, auxiliaryData.keys()) { + const QList propertyNames = auxiliaryData.keys(); + for (const PropertyName &propertyName : propertyNames) { if (node.hasAuxiliaryData(propertyName)) node.setAuxiliaryData(propertyName, QVariant()); } @@ -281,7 +283,7 @@ bool DocumentManager::hasCurrentDesignDocument() const void DocumentManager::removeEditors(const QList &editors) { - foreach (Core::IEditor *editor, editors) + for (Core::IEditor *editor : editors) delete m_designDocumentHash.take(editor).data(); } diff --git a/src/plugins/qmldesigner/openuiqmlfiledialog.cpp b/src/plugins/qmldesigner/openuiqmlfiledialog.cpp index bfb49c25c56..8bd5a0e17ce 100644 --- a/src/plugins/qmldesigner/openuiqmlfiledialog.cpp +++ b/src/plugins/qmldesigner/openuiqmlfiledialog.cpp @@ -75,7 +75,7 @@ void OpenUiQmlFileDialog::setUiQmlFiles(const QString &projectPath, const QStrin { QDir projectDir(projectPath); - foreach (const QString &fileName, stringList) { + for (const QString &fileName : stringList) { QListWidgetItem *item = new QListWidgetItem(projectDir.relativeFilePath(fileName), ui->listWidget); item->setData(Qt::UserRole, fileName); ui->listWidget->addItem(item); diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index 999f28d2106..6e0ccf5f399 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -369,7 +369,8 @@ static QStringList allUiQmlFilesforCurrentProject(const Utils::FilePath &fileNam ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::projectForFile(fileName); if (currentProject) { - foreach (const Utils::FilePath &fileName, currentProject->files(ProjectExplorer::Project::SourceFiles)) { + const QList fileNames = currentProject->files(ProjectExplorer::Project::SourceFiles); + for (const Utils::FilePath &fileName : fileNames) { if (fileName.endsWith(".ui.qml")) list.append(fileName.toString()); }