From 597a9dccb348da08d5fb633fd89228af150588c1 Mon Sep 17 00:00:00 2001 From: Artem Sokolovskii Date: Tue, 10 May 2022 13:42:51 +0200 Subject: [PATCH] QmlDesigner: Remove foreach / Q_FOREACH usage in formeditor Task-number: QTCREATORBUG-27464 Change-Id: Ib477df666eb798b302b7a6915bb98f798b7a04ed Reviewed-by: Reviewed-by: Thomas Hartmann Reviewed-by: Qt CI Bot --- .../formeditor/abstractformeditortool.cpp | 18 ++++++------- .../components/formeditor/anchorindicator.cpp | 2 +- .../formeditor/bindingindicator.cpp | 2 +- .../contentnoteditableindicator.cpp | 24 +++++++++-------- .../components/formeditor/formeditorscene.cpp | 19 ++++++++------ .../components/formeditor/formeditorview.cpp | 15 +++++------ .../formeditor/itemutilfunctions.cpp | 4 +-- .../components/formeditor/layeritem.cpp | 4 +-- .../components/formeditor/movemanipulator.cpp | 26 +++++++++---------- .../components/formeditor/movetool.cpp | 8 +++--- .../formeditor/onedimensionalcluster.cpp | 4 +-- .../components/formeditor/resizeindicator.cpp | 4 +-- .../formeditor/resizemanipulator.cpp | 2 +- .../formeditor/rotationmanipulator.cpp | 2 +- .../rubberbandselectionmanipulator.cpp | 2 +- .../formeditor/selectionindicator.cpp | 12 ++++----- .../components/formeditor/snapper.cpp | 8 +++--- .../formeditor/snappinglinecreator.cpp | 3 ++- 18 files changed, 82 insertions(+), 77 deletions(-) diff --git a/src/plugins/qmldesigner/components/formeditor/abstractformeditortool.cpp b/src/plugins/qmldesigner/components/formeditor/abstractformeditortool.cpp index f9d05307aad..2b1f4e9503e 100644 --- a/src/plugins/qmldesigner/components/formeditor/abstractformeditortool.cpp +++ b/src/plugins/qmldesigner/components/formeditor/abstractformeditortool.cpp @@ -75,7 +75,7 @@ QList AbstractFormEditorTool::toFormEditorItemList(const QList { QList formEditorItemList; - foreach (QGraphicsItem *graphicsItem, itemList) { + for (QGraphicsItem *graphicsItem : itemList) { auto formEditorItem = qgraphicsitem_cast(graphicsItem); if (formEditorItem) formEditorItemList.append(formEditorItem); @@ -105,7 +105,7 @@ bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList selectedNodes = view()->selectedModelNodes(); - foreach (QGraphicsItem *item, itemList) { + for (QGraphicsItem *item : itemList) { FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); if (formEditorItem && selectedNodes.contains(formEditorItem->qmlItemNode()) @@ -116,7 +116,7 @@ bool AbstractFormEditorTool::topSelectedItemIsMovable(const QListqmlItemNode().isValid() @@ -163,7 +163,7 @@ bool AbstractFormEditorTool::topItemIsResizeHandle(const QList & QGraphicsItem *AbstractFormEditorTool::topMovableGraphicsItem(const QList &itemList) { - foreach (QGraphicsItem *item, itemList) { + for (QGraphicsItem *item : itemList) { if (item->flags().testFlag(QGraphicsItem::ItemIsMovable)) return item; } @@ -173,7 +173,7 @@ QGraphicsItem *AbstractFormEditorTool::topMovableGraphicsItem(const QList &itemList, bool selectOnlyContentItems) { - foreach (QGraphicsItem *item, itemList) { + for (QGraphicsItem *item : itemList) { FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); if (formEditorItem && formEditorItem->qmlItemNode().isValid() @@ -221,7 +221,7 @@ QList AbstractFormEditorTool::filterSelectedModelNodes(const Q { QList filteredItemList; - foreach (FormEditorItem *item, itemList) { + for (FormEditorItem *item : itemList) { if (view()->isSelectedModelNode(item->qmlItemNode())) filteredItemList.append(item); } @@ -266,7 +266,7 @@ void AbstractFormEditorTool::mousePressEvent(const QList & /*ite static bool containsItemNode(const QList & itemList, const QmlItemNode &itemNode) { - foreach (QGraphicsItem *item, itemList) { + for (QGraphicsItem *item : itemList) { FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); if (formEditorItem && formEditorItem->qmlItemNode() == itemNode) return true; @@ -340,7 +340,7 @@ Snapper::Snapping AbstractFormEditorTool::generateUseSnapping(Qt::KeyboardModifi static bool isNotAncestorOfItemInList(FormEditorItem *formEditorItem, const QList &itemList) { - foreach (FormEditorItem *item, itemList) { + for (FormEditorItem *item : itemList) { if (item && item->qmlItemNode().isValid() && item->qmlItemNode().isAncestorOf(formEditorItem->qmlItemNode())) @@ -352,7 +352,7 @@ static bool isNotAncestorOfItemInList(FormEditorItem *formEditorItem, const QLis FormEditorItem *AbstractFormEditorTool::containerFormEditorItem(const QList &itemUnderMouseList, const QList &selectedItemList) const { - foreach (QGraphicsItem* item, itemUnderMouseList) { + for (QGraphicsItem* item : itemUnderMouseList) { FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); if (formEditorItem && !selectedItemList.contains(formEditorItem) diff --git a/src/plugins/qmldesigner/components/formeditor/anchorindicator.cpp b/src/plugins/qmldesigner/components/formeditor/anchorindicator.cpp index 81bd86e1f64..5c634a773e5 100644 --- a/src/plugins/qmldesigner/components/formeditor/anchorindicator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/anchorindicator.cpp @@ -121,7 +121,7 @@ void AnchorIndicator::setItems(const QList &itemList) void AnchorIndicator::updateItems(const QList &itemList) { - foreach (FormEditorItem *formEditorItem, itemList) { + for (FormEditorItem *formEditorItem : itemList) { if (formEditorItem == m_formEditorItem) { QmlItemNode sourceQmlItemNode = m_formEditorItem->qmlItemNode(); if (!sourceQmlItemNode.modelNode().isRootNode()) { diff --git a/src/plugins/qmldesigner/components/formeditor/bindingindicator.cpp b/src/plugins/qmldesigner/components/formeditor/bindingindicator.cpp index 238a13eac0a..416042f085c 100644 --- a/src/plugins/qmldesigner/components/formeditor/bindingindicator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/bindingindicator.cpp @@ -144,7 +144,7 @@ void BindingIndicator::setItems(const QList &itemList) void BindingIndicator::updateItems(const QList &itemList) { - foreach (FormEditorItem *formEditorItem, itemList) { + for (FormEditorItem *formEditorItem : itemList) { if (formEditorItem == m_formEditorItem) { const QmlItemNode qmlItemNode = m_formEditorItem->qmlItemNode(); diff --git a/src/plugins/qmldesigner/components/formeditor/contentnoteditableindicator.cpp b/src/plugins/qmldesigner/components/formeditor/contentnoteditableindicator.cpp index 4c96433e5be..935340996ff 100644 --- a/src/plugins/qmldesigner/components/formeditor/contentnoteditableindicator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/contentnoteditableindicator.cpp @@ -48,7 +48,7 @@ ContentNotEditableIndicator::~ContentNotEditableIndicator() void ContentNotEditableIndicator::clear() { - foreach (const EntryPair &entryPair, m_entryList) { + for (const EntryPair &entryPair : qAsConst(m_entryList)) { delete entryPair.second; entryPair.first->blurContent(false); } @@ -71,23 +71,25 @@ void ContentNotEditableIndicator::updateItems(const QList &ite { QSet affectedFormEditorItemItems; affectedFormEditorItemItems.unite(Utils::toSet(itemList)); - foreach (FormEditorItem *formEditorItem, itemList) + for (FormEditorItem *formEditorItem : itemList) affectedFormEditorItemItems.unite(Utils::toSet(formEditorItem->offspringFormEditorItems())); - foreach (const EntryPair &entryPair, m_entryList) { - foreach (FormEditorItem *formEditorItem, affectedFormEditorItemItems) { - if (formEditorItem == entryPair.first) { - QRectF boundingRectangleInSceneSpace = formEditorItem->qmlItemNode().instanceSceneTransform().mapRect(formEditorItem->qmlItemNode().instanceBoundingRect()); - entryPair.second->setRect(boundingRectangleInSceneSpace); - entryPair.second->update(); - } - } + for (const EntryPair &entryPair : qAsConst(m_entryList)) { + for (FormEditorItem *formEditorItem : qAsConst(affectedFormEditorItemItems)) { + if (formEditorItem == entryPair.first) { + QRectF boundingRectangleInSceneSpace + = formEditorItem->qmlItemNode().instanceSceneTransform().mapRect( + formEditorItem->qmlItemNode().instanceBoundingRect()); + entryPair.second->setRect(boundingRectangleInSceneSpace); + entryPair.second->update(); + } + } } } void ContentNotEditableIndicator::addAddiationEntries(const QList &itemList) { - foreach (FormEditorItem *formEditorItem, itemList) { + for (FormEditorItem *formEditorItem : itemList) { const ModelNode modelNode = formEditorItem->qmlItemNode().modelNode(); if (modelNode.metaInfo().isValid() && modelNode.metaInfo().isSubclassOf("QtQuick.Loader")) { diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp index dea52631d85..5beb60a98e5 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp @@ -79,7 +79,8 @@ void FormEditorScene::setupScene() void FormEditorScene::resetScene() { - foreach (QGraphicsItem *item, m_manipulatorLayerItem->childItems()) { + const QList items = m_manipulatorLayerItem->childItems(); + for (QGraphicsItem *item : items) { removeItem(item); delete item; } @@ -116,7 +117,8 @@ QList FormEditorScene::allFormEditorItems() const void FormEditorScene::updateAllFormEditorItems() { - foreach (FormEditorItem *item, allFormEditorItems()) + const QList items = allFormEditorItems(); + for (FormEditorItem *item : items) item->update(); } @@ -134,8 +136,8 @@ AbstractFormEditorTool* FormEditorScene::currentTool() const FormEditorItem* FormEditorScene::calulateNewParent(FormEditorItem *formEditorItem) { if (formEditorItem->qmlItemNode().isValid()) { - QList list = items(formEditorItem->qmlItemNode().instanceBoundingRect().center()); - foreach (QGraphicsItem *graphicsItem, list) { + const QList list = items(formEditorItem->qmlItemNode().instanceBoundingRect().center()); + for (QGraphicsItem *graphicsItem : list) { if (qgraphicsitem_cast(graphicsItem) && graphicsItem->collidesWithItem(formEditorItem, Qt::ContainsItemShape)) return qgraphicsitem_cast(graphicsItem); @@ -229,7 +231,7 @@ QList FormEditorScene::removeLayerItems(const QList itemListWithoutLayerItems; - foreach (QGraphicsItem *item, itemList) + for (QGraphicsItem *item : itemList) if (item != manipulatorLayerItem() && item != formLayerItem()) itemListWithoutLayerItems.append(item); @@ -422,16 +424,17 @@ void FormEditorScene::clearFormEditorItems() const QList formEditorItems = Utils::filtered(formEditorItemsTransformed, [](FormEditorItem *item) { return item; }); - foreach (FormEditorItem *item, formEditorItems) + for (FormEditorItem *item : formEditorItems) item->setParentItem(nullptr); - foreach (FormEditorItem *item, formEditorItems) + for (FormEditorItem *item : formEditorItems) delete item; } void FormEditorScene::highlightBoundingRect(FormEditorItem *highlighItem) { - foreach (FormEditorItem *item, allFormEditorItems()) { + QList items = allFormEditorItems(); + for (FormEditorItem *item : items) { if (item == highlighItem) item->setHighlightBoundingRect(true); else diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp index b624078c141..dbb137bbebf 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp @@ -166,8 +166,8 @@ void FormEditorView::setupFormEditorItemTree(const QmlItemNode &qmlItemNode) static void deleteWithoutChildren(const QList &items) { - foreach (FormEditorItem *item, items) { - foreach (QGraphicsItem *child, item->childItems()) { + for (const FormEditorItem *item : items) { + for (QGraphicsItem *child : item->childItems()) { child->setParentItem(item->scene()->rootFormEditorItem()); } delete item; @@ -286,11 +286,9 @@ void FormEditorView::nodeAboutToBeRemoved(const ModelNode &removedNode) void FormEditorView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVersion*/, int /*minorVersion*/) { - foreach (FormEditorItem *item, m_scene->allFormEditorItems()) { + const QList items = m_scene->allFormEditorItems(); + for (FormEditorItem *item : items) { item->setParentItem(nullptr); - } - - foreach (FormEditorItem *item, m_scene->allFormEditorItems()) { m_scene->removeItemFromHash(item); delete item; } @@ -309,11 +307,12 @@ void FormEditorView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVer void FormEditorView::propertiesAboutToBeRemoved(const QList& propertyList) { QList removedItems; - foreach (const AbstractProperty &property, propertyList) { + for (const AbstractProperty &property : propertyList) { if (property.isNodeAbstractProperty()) { NodeAbstractProperty nodeAbstractProperty = property.toNodeAbstractProperty(); - foreach (const ModelNode &modelNode, nodeAbstractProperty.allSubNodes()) { + const QList modelNodes = nodeAbstractProperty.allSubNodes(); + for (const ModelNode &modelNode : modelNodes) { const QmlItemNode qmlItemNode(modelNode); if (qmlItemNode.isValid()){ diff --git a/src/plugins/qmldesigner/components/formeditor/itemutilfunctions.cpp b/src/plugins/qmldesigner/components/formeditor/itemutilfunctions.cpp index a16ca4b54dd..9daf5cd98e4 100644 --- a/src/plugins/qmldesigner/components/formeditor/itemutilfunctions.cpp +++ b/src/plugins/qmldesigner/components/formeditor/itemutilfunctions.cpp @@ -32,11 +32,11 @@ namespace QmlDesigner { class FormEditorItem; -QRectF boundingRectForItemList(QList itemList) +QRectF boundingRectForItemList(const QList itemList) { QRectF boundingRect; - foreach (FormEditorItem *item, itemList) + for (FormEditorItem *item : itemList) { boundingRect = boundingRect.united(item->mapToScene(item->qmlItemNode().instanceBoundingRect()).boundingRect()); } diff --git a/src/plugins/qmldesigner/components/formeditor/layeritem.cpp b/src/plugins/qmldesigner/components/formeditor/layeritem.cpp index 5be1d109266..0752450fd87 100644 --- a/src/plugins/qmldesigner/components/formeditor/layeritem.cpp +++ b/src/plugins/qmldesigner/components/formeditor/layeritem.cpp @@ -69,8 +69,8 @@ QList LayerItem::findAllChildItems(const QGraphicsItem *item) co { QList itemList(item->childItems()); - foreach (QGraphicsItem *childItem, item->childItems()) - itemList += findAllChildItems(childItem); + for (int end = itemList.length(), i = 0; i < end; ++i) + itemList += findAllChildItems(itemList.at(i)); return itemList; } diff --git a/src/plugins/qmldesigner/components/formeditor/movemanipulator.cpp b/src/plugins/qmldesigner/components/formeditor/movemanipulator.cpp index 9bf0d3fc511..0969776a028 100644 --- a/src/plugins/qmldesigner/components/formeditor/movemanipulator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/movemanipulator.cpp @@ -88,7 +88,7 @@ void MoveManipulator::synchronizeParent(const QList &itemList, { bool snapperUpdated = false; - foreach (FormEditorItem *item, itemList) { + for (FormEditorItem *item : itemList) { if (m_itemList.contains(item)) { QmlItemNode parentItemNode = QmlItemNode(parentNode); if (parentItemNode.isValid()) { @@ -111,7 +111,7 @@ void MoveManipulator::synchronizeInstanceParent(const QList &it bool MoveManipulator::itemsCanReparented() const { - foreach (FormEditorItem* item, m_itemList) { + for (FormEditorItem* item : qAsConst(m_itemList)) { if (item && item->qmlItemNode().isValid() && !item->qmlItemNode().instanceCanReparent()) @@ -123,7 +123,7 @@ bool MoveManipulator::itemsCanReparented() const void MoveManipulator::setDirectUpdateInNodeInstances(bool directUpdate) { - foreach (FormEditorItem* item, m_itemList) { + for (FormEditorItem* item : qAsConst(m_itemList)) { if (item && item->qmlItemNode().isValid()) item->qmlItemNode().nodeInstance().setDirectUpdate(directUpdate); } @@ -136,7 +136,7 @@ void MoveManipulator::begin(const QPointF &beginPoint) m_snapper.updateSnappingLines(m_itemList); - foreach (FormEditorItem* item, m_itemList) { + for (FormEditorItem* item : qAsConst(m_itemList)) { if (item && item->qmlItemNode().isValid()) { QTransform fromItemToSceneTransform = item->qmlItemNode().instanceSceneTransform(); m_beginItemRectInSceneSpaceHash.insert(item, fromItemToSceneTransform.mapRect(item->qmlItemNode().instanceBoundingRect())); @@ -144,14 +144,14 @@ void MoveManipulator::begin(const QPointF &beginPoint) } QTransform fromContentItemToSceneTransform = m_snapper.containerFormEditorItem()->qmlItemNode().instanceSceneContentItemTransform(); - foreach (FormEditorItem* item, m_itemList) { + for (FormEditorItem* item : qAsConst(m_itemList)) { if (item && item->qmlItemNode().isValid()) { QPointF positionInScenesSpace = fromContentItemToSceneTransform.map(item->instancePosition()); m_beginPositionInSceneSpaceHash.insert(item, positionInScenesSpace); } } - foreach (FormEditorItem* item, m_itemList) { + for (FormEditorItem* item : qAsConst(m_itemList)) { if (item && item->qmlItemNode().isValid()) { QmlAnchors anchors(item->qmlItemNode().anchors()); m_beginTopMarginHash.insert(item, anchors.instanceMargin(AnchorLineTop)); @@ -278,7 +278,7 @@ void MoveManipulator::update(const QPointF& updatePoint, Snapper::Snapping useSn generateSnappingLines(tanslatedBoundingRects(m_beginItemRectInSceneSpaceHash, offsetVector, fromSceneToItemTransform)); } - foreach (FormEditorItem* item, m_itemList) { + for (FormEditorItem* item : qAsConst(m_itemList)) { QPointF positionInContainerSpace(fromSceneToContentItemTransform.map(m_beginPositionInSceneSpaceHash.value(item)) + offsetVector); if (!item || !item->qmlItemNode().isValid()) @@ -363,7 +363,7 @@ void MoveManipulator::reparentTo(FormEditorItem *newParent, ReparentFlag flag) else parentProperty = parentItemNode.nodeAbstractProperty("data"); - foreach (FormEditorItem* item, m_itemList) { + for (FormEditorItem* item : qAsConst(m_itemList)) { if (!item || !item->qmlItemNode().isValid()) continue; @@ -372,7 +372,7 @@ void MoveManipulator::reparentTo(FormEditorItem *newParent, ReparentFlag flag) } - foreach (const ModelNode &nodeToReparented, nodeReparentVector) + for (const ModelNode &nodeToReparented : qAsConst(nodeReparentVector)) parentProperty.reparentHere(nodeToReparented); synchronizeParent(m_itemList, parentProperty.parentModelNode()); @@ -393,7 +393,7 @@ void MoveManipulator::end() void MoveManipulator::end(Snapper::Snapping useSnapping) { if (useSnapping == Snapper::UseSnappingAndAnchoring) { - foreach (FormEditorItem *formEditorItem, m_itemList) + for (FormEditorItem* formEditorItem : qAsConst(m_itemList)) m_snapper.adjustAnchoringOfItem(formEditorItem); } @@ -402,7 +402,7 @@ void MoveManipulator::end(Snapper::Snapping useSnapping) void MoveManipulator::moveBy(double deltaX, double deltaY) { - foreach (FormEditorItem* item, m_itemList) { + for (FormEditorItem* item : qAsConst(m_itemList)) { if (!item || !item->qmlItemNode().isValid()) continue; @@ -444,14 +444,14 @@ void MoveManipulator::endRewriterTransaction() void MoveManipulator::setOpacityForAllElements(qreal opacity) { - foreach (FormEditorItem* item, m_itemList) + for (FormEditorItem* item : qAsConst(m_itemList)) item->setOpacity(opacity); } void MoveManipulator::deleteSnapLines() { if (m_layerItem) { - foreach (QGraphicsItem *item, m_graphicsLineList) { + for (QGraphicsItem *item : qAsConst(m_graphicsLineList)) { m_layerItem->scene()->removeItem(item); delete item; } diff --git a/src/plugins/qmldesigner/components/formeditor/movetool.cpp b/src/plugins/qmldesigner/components/formeditor/movetool.cpp index a383a746590..81cbc8273e3 100644 --- a/src/plugins/qmldesigner/components/formeditor/movetool.cpp +++ b/src/plugins/qmldesigner/components/formeditor/movetool.cpp @@ -271,7 +271,7 @@ void MoveTool::mouseDoubleClickEvent(const QList &itemList, QGra void MoveTool::itemsAboutToRemoved(const QList &removedItemList) { - foreach (FormEditorItem* removedItem, removedItemList) + for (FormEditorItem* removedItem : removedItemList) m_movingItems.removeOne(removedItem); } @@ -304,7 +304,7 @@ bool MoveTool::haveSameParent(const QList &itemList) return false; QGraphicsItem *firstParent = itemList.constFirst()->parentItem(); - foreach (FormEditorItem* item, itemList) + for (FormEditorItem* item : itemList) { if (firstParent != item->parentItem()) return false; @@ -316,7 +316,7 @@ bool MoveTool::haveSameParent(const QList &itemList) bool MoveTool::isAncestorOfAllItems(FormEditorItem* maybeAncestorItem, const QList &itemList) { - foreach (FormEditorItem* item, itemList) + for (FormEditorItem* item : itemList) { if (!maybeAncestorItem->isAncestorOf(item) && item != maybeAncestorItem) return false; @@ -332,7 +332,7 @@ FormEditorItem* MoveTool::ancestorIfOtherItemsAreChild(const QList OneDimensionalCluster::createOneDimensionalClusterList(const QList & oneDimensionalCoordinateList) { QList oneDimensionalClusterList; - foreach (double coordinate, oneDimensionalCoordinateList) + for (double coordinate : oneDimensionalCoordinateList) { QList initialList; initialList.append(coordinate); @@ -134,7 +134,7 @@ QList OneDimensionalCluster::reduceLines(const QList & oneDimens clusterList = reduceOneDimensionalClusterList(clusterList, maximumDistance); QList lineList; - foreach (const OneDimensionalCluster &cluster, clusterList) + for (const OneDimensionalCluster &cluster : qAsConst(clusterList)) lineList.append(cluster.constFirst()); return lineList; diff --git a/src/plugins/qmldesigner/components/formeditor/resizeindicator.cpp b/src/plugins/qmldesigner/components/formeditor/resizeindicator.cpp index ad5f2feffff..cdb56ae044f 100644 --- a/src/plugins/qmldesigner/components/formeditor/resizeindicator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/resizeindicator.cpp @@ -71,7 +71,7 @@ void ResizeIndicator::setItems(const QList &itemList) { clear(); - foreach (FormEditorItem* item, itemList) { + for (FormEditorItem* item : itemList) { if (item && itemIsResizable(item->qmlItemNode())) { ResizeController controller(m_layerItem, item); m_itemControllerHash.insert(item, controller); @@ -81,7 +81,7 @@ void ResizeIndicator::setItems(const QList &itemList) void ResizeIndicator::updateItems(const QList &itemList) { - foreach (FormEditorItem* item, itemList) { + for (FormEditorItem* item : itemList) { if (m_itemControllerHash.contains(item)) { if (!item || !itemIsResizable(item->qmlItemNode())) { m_itemControllerHash.take(item); diff --git a/src/plugins/qmldesigner/components/formeditor/resizemanipulator.cpp b/src/plugins/qmldesigner/components/formeditor/resizemanipulator.cpp index 8907aab2bce..65c454fbe6a 100644 --- a/src/plugins/qmldesigner/components/formeditor/resizemanipulator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/resizemanipulator.cpp @@ -628,7 +628,7 @@ bool ResizeManipulator::isInvalidSize(const QSizeF & size) void ResizeManipulator::deleteSnapLines() { if (m_layerItem) { - foreach (QGraphicsItem *item, m_graphicsLineList) { + for (QGraphicsItem *item : qAsConst(m_graphicsLineList)) { m_layerItem->scene()->removeItem(item); delete item; } diff --git a/src/plugins/qmldesigner/components/formeditor/rotationmanipulator.cpp b/src/plugins/qmldesigner/components/formeditor/rotationmanipulator.cpp index a7dbe75418b..6d7b054d0f6 100644 --- a/src/plugins/qmldesigner/components/formeditor/rotationmanipulator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/rotationmanipulator.cpp @@ -220,7 +220,7 @@ void RotationManipulator::end() void RotationManipulator::deleteSnapLines() { if (m_layerItem) { - foreach (QGraphicsItem *item, m_graphicsLineList) { + for (QGraphicsItem *item : qAsConst(m_graphicsLineList)) { m_layerItem->scene()->removeItem(item); delete item; } diff --git a/src/plugins/qmldesigner/components/formeditor/rubberbandselectionmanipulator.cpp b/src/plugins/qmldesigner/components/formeditor/rubberbandselectionmanipulator.cpp index fa399f8860a..0327bb882cc 100644 --- a/src/plugins/qmldesigner/components/formeditor/rubberbandselectionmanipulator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/rubberbandselectionmanipulator.cpp @@ -51,7 +51,7 @@ void RubberBandSelectionManipulator::clear() FormEditorItem *RubberBandSelectionManipulator::topFormEditorItem(const QList &itemList) { - foreach (QGraphicsItem *item, itemList) { + for (QGraphicsItem *item : itemList) { FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); if (formEditorItem) diff --git a/src/plugins/qmldesigner/components/formeditor/selectionindicator.cpp b/src/plugins/qmldesigner/components/formeditor/selectionindicator.cpp index 02f3ce9ee66..382d9cc9163 100644 --- a/src/plugins/qmldesigner/components/formeditor/selectionindicator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/selectionindicator.cpp @@ -54,7 +54,7 @@ SelectionIndicator::~SelectionIndicator() void SelectionIndicator::show() { - foreach (QGraphicsPolygonItem *item, m_indicatorShapeHash) + for (QGraphicsPolygonItem *item : qAsConst(m_indicatorShapeHash)) item->show(); if (m_labelItem) m_labelItem->show(); @@ -62,7 +62,7 @@ void SelectionIndicator::show() void SelectionIndicator::hide() { - foreach (QGraphicsPolygonItem *item, m_indicatorShapeHash) + for (QGraphicsPolygonItem *item : qAsConst(m_indicatorShapeHash)) item->hide(); if (m_labelItem) m_labelItem->hide(); @@ -71,7 +71,7 @@ void SelectionIndicator::hide() void SelectionIndicator::clear() { if (m_layerItem) { - foreach (QGraphicsItem *item, m_indicatorShapeHash) { + for (QGraphicsPolygonItem *item : qAsConst(m_indicatorShapeHash)) { m_layerItem->scene()->removeItem(item); delete item; } @@ -102,7 +102,7 @@ void SelectionIndicator::setItems(const QList &itemList) static QColor selectionColor = Utils::creatorTheme()->color(Utils::Theme::QmlDesigner_FormEditorSelectionColor); - foreach (FormEditorItem *item, itemList) { + for (FormEditorItem *item : itemList) { if (!item->qmlItemNode().isValid()) continue; @@ -178,7 +178,7 @@ void SelectionIndicator::setItems(const QList &itemList) void SelectionIndicator::updateItems(const QList &itemList) { - foreach (FormEditorItem *item, itemList) { + for (FormEditorItem *item : itemList) { if (m_indicatorShapeHash.contains(item)) { QGraphicsPolygonItem *indicatorGraphicsItem = m_indicatorShapeHash.value(item); indicatorGraphicsItem->setPolygon(boundingRectInLayerItemSpaceForItem(item, m_layerItem.data())); @@ -207,7 +207,7 @@ void SelectionIndicator::setCursor(const QCursor &cursor) { m_cursor = cursor; - foreach (QGraphicsItem *item, m_indicatorShapeHash) + for (QGraphicsItem *item : qAsConst(m_indicatorShapeHash)) item->setCursor(cursor); } diff --git a/src/plugins/qmldesigner/components/formeditor/snapper.cpp b/src/plugins/qmldesigner/components/formeditor/snapper.cpp index 361a8a46b42..312b2751c1a 100644 --- a/src/plugins/qmldesigner/components/formeditor/snapper.cpp +++ b/src/plugins/qmldesigner/components/formeditor/snapper.cpp @@ -453,7 +453,7 @@ static QLineF mergedHorizontalLine(const QList &lineList) double minimumX = std::numeric_limits::max(); double maximumX = std::numeric_limits::min(); - foreach (const QLineF &line, lineList) { + for (const QLineF &line : lineList) { minimumX = qMin(minimumX, double(line.x1())); minimumX = qMin(minimumX, double(line.x2())); maximumX = qMax(maximumX, double(line.x1())); @@ -471,7 +471,7 @@ static QLineF mergedVerticalLine(const QList &lineList) double minimumY = std::numeric_limits::max(); double maximumY = std::numeric_limits::min(); - foreach (const QLineF &line, lineList) { + for (const QLineF &line : lineList) { minimumY = qMin(minimumY, double(line.y1())); minimumY = qMin(minimumY, double(line.y2())); maximumY = qMax(maximumY, double(line.y1())); @@ -705,13 +705,13 @@ QList Snapper::generateSnappingLines(const QList &boundi { QList graphicsItemList; QList lineList; - foreach (const QRectF &boundingRect, boundingRectList) { + for (const QRectF &boundingRect : boundingRectList) { QList snappedBoundingRectList; lineList += mergedHorizontalLines(horizontalSnappedLines(boundingRect, &snappedBoundingRectList)); lineList += mergedVerticalLines(verticalSnappedLines(boundingRect, &snappedBoundingRectList)); } - foreach (const QLineF &line, lineList) { + for (const QLineF &line : qAsConst(lineList)) { QLineF lineInTransformationSpace = transform.map(line); auto lineItem = new QGraphicsLineItem(lineInTransformationSpace, layerItem); lineItem->setZValue(40); diff --git a/src/plugins/qmldesigner/components/formeditor/snappinglinecreator.cpp b/src/plugins/qmldesigner/components/formeditor/snappinglinecreator.cpp index 45d71cb9b18..6658a846a45 100644 --- a/src/plugins/qmldesigner/components/formeditor/snappinglinecreator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/snappinglinecreator.cpp @@ -99,7 +99,8 @@ void SnappingLineCreator::generateLines(const QList &exceptionL addLines(containerBoundingRectInTransformationSpace, m_formEditorItem); } - foreach (FormEditorItem *item, m_formEditorItem->childFormEditorItems()) { + const QList items = m_formEditorItem->childFormEditorItems(); + for (FormEditorItem *item : items) { if (!item || !item->qmlItemNode().isValid()) continue;