QmlDesigner: Remove foreach / Q_FOREACH usage in formeditor

Task-number: QTCREATORBUG-27464
Change-Id: Ib477df666eb798b302b7a6915bb98f798b7a04ed
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Artem Sokolovskii
2022-05-10 13:42:51 +02:00
parent 59a77a4965
commit 597a9dccb3
18 changed files with 82 additions and 77 deletions

View File

@@ -75,7 +75,7 @@ QList<FormEditorItem *> AbstractFormEditorTool::toFormEditorItemList(const QList
{ {
QList<FormEditorItem *> formEditorItemList; QList<FormEditorItem *> formEditorItemList;
foreach (QGraphicsItem *graphicsItem, itemList) { for (QGraphicsItem *graphicsItem : itemList) {
auto formEditorItem = qgraphicsitem_cast<FormEditorItem*>(graphicsItem); auto formEditorItem = qgraphicsitem_cast<FormEditorItem*>(graphicsItem);
if (formEditorItem) if (formEditorItem)
formEditorItemList.append(formEditorItem); formEditorItemList.append(formEditorItem);
@@ -105,7 +105,7 @@ bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList<QGraphicsItem*
{ {
QList<ModelNode> selectedNodes = view()->selectedModelNodes(); QList<ModelNode> selectedNodes = view()->selectedModelNodes();
foreach (QGraphicsItem *item, itemList) { for (QGraphicsItem *item : itemList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem if (formEditorItem
&& selectedNodes.contains(formEditorItem->qmlItemNode()) && selectedNodes.contains(formEditorItem->qmlItemNode())
@@ -116,7 +116,7 @@ bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList<QGraphicsItem*
return true; return true;
} }
foreach (QGraphicsItem *item, itemList) { for (QGraphicsItem *item : itemList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem if (formEditorItem
&& formEditorItem->qmlItemNode().isValid() && formEditorItem->qmlItemNode().isValid()
@@ -163,7 +163,7 @@ bool AbstractFormEditorTool::topItemIsResizeHandle(const QList<QGraphicsItem*> &
QGraphicsItem *AbstractFormEditorTool::topMovableGraphicsItem(const QList<QGraphicsItem*> &itemList) QGraphicsItem *AbstractFormEditorTool::topMovableGraphicsItem(const QList<QGraphicsItem*> &itemList)
{ {
foreach (QGraphicsItem *item, itemList) { for (QGraphicsItem *item : itemList) {
if (item->flags().testFlag(QGraphicsItem::ItemIsMovable)) if (item->flags().testFlag(QGraphicsItem::ItemIsMovable))
return item; return item;
} }
@@ -173,7 +173,7 @@ QGraphicsItem *AbstractFormEditorTool::topMovableGraphicsItem(const QList<QGraph
FormEditorItem *AbstractFormEditorTool::topMovableFormEditorItem(const QList<QGraphicsItem*> &itemList, bool selectOnlyContentItems) FormEditorItem *AbstractFormEditorTool::topMovableFormEditorItem(const QList<QGraphicsItem*> &itemList, bool selectOnlyContentItems)
{ {
foreach (QGraphicsItem *item, itemList) { for (QGraphicsItem *item : itemList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem if (formEditorItem
&& formEditorItem->qmlItemNode().isValid() && formEditorItem->qmlItemNode().isValid()
@@ -221,7 +221,7 @@ QList<FormEditorItem *> AbstractFormEditorTool::filterSelectedModelNodes(const Q
{ {
QList<FormEditorItem *> filteredItemList; QList<FormEditorItem *> filteredItemList;
foreach (FormEditorItem *item, itemList) { for (FormEditorItem *item : itemList) {
if (view()->isSelectedModelNode(item->qmlItemNode())) if (view()->isSelectedModelNode(item->qmlItemNode()))
filteredItemList.append(item); filteredItemList.append(item);
} }
@@ -266,7 +266,7 @@ void AbstractFormEditorTool::mousePressEvent(const QList<QGraphicsItem*> & /*ite
static bool containsItemNode(const QList<QGraphicsItem*> & itemList, const QmlItemNode &itemNode) static bool containsItemNode(const QList<QGraphicsItem*> & itemList, const QmlItemNode &itemNode)
{ {
foreach (QGraphicsItem *item, itemList) { for (QGraphicsItem *item : itemList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem && formEditorItem->qmlItemNode() == itemNode) if (formEditorItem && formEditorItem->qmlItemNode() == itemNode)
return true; return true;
@@ -340,7 +340,7 @@ Snapper::Snapping AbstractFormEditorTool::generateUseSnapping(Qt::KeyboardModifi
static bool isNotAncestorOfItemInList(FormEditorItem *formEditorItem, const QList<FormEditorItem*> &itemList) static bool isNotAncestorOfItemInList(FormEditorItem *formEditorItem, const QList<FormEditorItem*> &itemList)
{ {
foreach (FormEditorItem *item, itemList) { for (FormEditorItem *item : itemList) {
if (item if (item
&& item->qmlItemNode().isValid() && item->qmlItemNode().isValid()
&& item->qmlItemNode().isAncestorOf(formEditorItem->qmlItemNode())) && item->qmlItemNode().isAncestorOf(formEditorItem->qmlItemNode()))
@@ -352,7 +352,7 @@ static bool isNotAncestorOfItemInList(FormEditorItem *formEditorItem, const QLis
FormEditorItem *AbstractFormEditorTool::containerFormEditorItem(const QList<QGraphicsItem *> &itemUnderMouseList, const QList<FormEditorItem *> &selectedItemList) const FormEditorItem *AbstractFormEditorTool::containerFormEditorItem(const QList<QGraphicsItem *> &itemUnderMouseList, const QList<FormEditorItem *> &selectedItemList) const
{ {
foreach (QGraphicsItem* item, itemUnderMouseList) { for (QGraphicsItem* item : itemUnderMouseList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem if (formEditorItem
&& !selectedItemList.contains(formEditorItem) && !selectedItemList.contains(formEditorItem)

View File

@@ -121,7 +121,7 @@ void AnchorIndicator::setItems(const QList<FormEditorItem *> &itemList)
void AnchorIndicator::updateItems(const QList<FormEditorItem *> &itemList) void AnchorIndicator::updateItems(const QList<FormEditorItem *> &itemList)
{ {
foreach (FormEditorItem *formEditorItem, itemList) { for (FormEditorItem *formEditorItem : itemList) {
if (formEditorItem == m_formEditorItem) { if (formEditorItem == m_formEditorItem) {
QmlItemNode sourceQmlItemNode = m_formEditorItem->qmlItemNode(); QmlItemNode sourceQmlItemNode = m_formEditorItem->qmlItemNode();
if (!sourceQmlItemNode.modelNode().isRootNode()) { if (!sourceQmlItemNode.modelNode().isRootNode()) {

View File

@@ -144,7 +144,7 @@ void BindingIndicator::setItems(const QList<FormEditorItem *> &itemList)
void BindingIndicator::updateItems(const QList<FormEditorItem *> &itemList) void BindingIndicator::updateItems(const QList<FormEditorItem *> &itemList)
{ {
foreach (FormEditorItem *formEditorItem, itemList) { for (FormEditorItem *formEditorItem : itemList) {
if (formEditorItem == m_formEditorItem) { if (formEditorItem == m_formEditorItem) {
const QmlItemNode qmlItemNode = m_formEditorItem->qmlItemNode(); const QmlItemNode qmlItemNode = m_formEditorItem->qmlItemNode();

View File

@@ -48,7 +48,7 @@ ContentNotEditableIndicator::~ContentNotEditableIndicator()
void ContentNotEditableIndicator::clear() void ContentNotEditableIndicator::clear()
{ {
foreach (const EntryPair &entryPair, m_entryList) { for (const EntryPair &entryPair : qAsConst(m_entryList)) {
delete entryPair.second; delete entryPair.second;
entryPair.first->blurContent(false); entryPair.first->blurContent(false);
} }
@@ -71,23 +71,25 @@ void ContentNotEditableIndicator::updateItems(const QList<FormEditorItem *> &ite
{ {
QSet<FormEditorItem*> affectedFormEditorItemItems; QSet<FormEditorItem*> affectedFormEditorItemItems;
affectedFormEditorItemItems.unite(Utils::toSet(itemList)); affectedFormEditorItemItems.unite(Utils::toSet(itemList));
foreach (FormEditorItem *formEditorItem, itemList) for (FormEditorItem *formEditorItem : itemList)
affectedFormEditorItemItems.unite(Utils::toSet(formEditorItem->offspringFormEditorItems())); affectedFormEditorItemItems.unite(Utils::toSet(formEditorItem->offspringFormEditorItems()));
foreach (const EntryPair &entryPair, m_entryList) { for (const EntryPair &entryPair : qAsConst(m_entryList)) {
foreach (FormEditorItem *formEditorItem, affectedFormEditorItemItems) { for (FormEditorItem *formEditorItem : qAsConst(affectedFormEditorItemItems)) {
if (formEditorItem == entryPair.first) { if (formEditorItem == entryPair.first) {
QRectF boundingRectangleInSceneSpace = formEditorItem->qmlItemNode().instanceSceneTransform().mapRect(formEditorItem->qmlItemNode().instanceBoundingRect()); QRectF boundingRectangleInSceneSpace
entryPair.second->setRect(boundingRectangleInSceneSpace); = formEditorItem->qmlItemNode().instanceSceneTransform().mapRect(
entryPair.second->update(); formEditorItem->qmlItemNode().instanceBoundingRect());
} entryPair.second->setRect(boundingRectangleInSceneSpace);
} entryPair.second->update();
}
}
} }
} }
void ContentNotEditableIndicator::addAddiationEntries(const QList<FormEditorItem *> &itemList) void ContentNotEditableIndicator::addAddiationEntries(const QList<FormEditorItem *> &itemList)
{ {
foreach (FormEditorItem *formEditorItem, itemList) { for (FormEditorItem *formEditorItem : itemList) {
const ModelNode modelNode = formEditorItem->qmlItemNode().modelNode(); const ModelNode modelNode = formEditorItem->qmlItemNode().modelNode();
if (modelNode.metaInfo().isValid() && modelNode.metaInfo().isSubclassOf("QtQuick.Loader")) { if (modelNode.metaInfo().isValid() && modelNode.metaInfo().isSubclassOf("QtQuick.Loader")) {

View File

@@ -79,7 +79,8 @@ void FormEditorScene::setupScene()
void FormEditorScene::resetScene() void FormEditorScene::resetScene()
{ {
foreach (QGraphicsItem *item, m_manipulatorLayerItem->childItems()) { const QList<QGraphicsItem *> items = m_manipulatorLayerItem->childItems();
for (QGraphicsItem *item : items) {
removeItem(item); removeItem(item);
delete item; delete item;
} }
@@ -116,7 +117,8 @@ QList<FormEditorItem*> FormEditorScene::allFormEditorItems() const
void FormEditorScene::updateAllFormEditorItems() void FormEditorScene::updateAllFormEditorItems()
{ {
foreach (FormEditorItem *item, allFormEditorItems()) const QList<FormEditorItem *> items = allFormEditorItems();
for (FormEditorItem *item : items)
item->update(); item->update();
} }
@@ -134,8 +136,8 @@ AbstractFormEditorTool* FormEditorScene::currentTool() const
FormEditorItem* FormEditorScene::calulateNewParent(FormEditorItem *formEditorItem) FormEditorItem* FormEditorScene::calulateNewParent(FormEditorItem *formEditorItem)
{ {
if (formEditorItem->qmlItemNode().isValid()) { if (formEditorItem->qmlItemNode().isValid()) {
QList<QGraphicsItem *> list = items(formEditorItem->qmlItemNode().instanceBoundingRect().center()); const QList<QGraphicsItem *> list = items(formEditorItem->qmlItemNode().instanceBoundingRect().center());
foreach (QGraphicsItem *graphicsItem, list) { for (QGraphicsItem *graphicsItem : list) {
if (qgraphicsitem_cast<FormEditorItem*>(graphicsItem) && if (qgraphicsitem_cast<FormEditorItem*>(graphicsItem) &&
graphicsItem->collidesWithItem(formEditorItem, Qt::ContainsItemShape)) graphicsItem->collidesWithItem(formEditorItem, Qt::ContainsItemShape))
return qgraphicsitem_cast<FormEditorItem*>(graphicsItem); return qgraphicsitem_cast<FormEditorItem*>(graphicsItem);
@@ -229,7 +231,7 @@ QList<QGraphicsItem *> FormEditorScene::removeLayerItems(const QList<QGraphicsIt
{ {
QList<QGraphicsItem *> itemListWithoutLayerItems; QList<QGraphicsItem *> itemListWithoutLayerItems;
foreach (QGraphicsItem *item, itemList) for (QGraphicsItem *item : itemList)
if (item != manipulatorLayerItem() && item != formLayerItem()) if (item != manipulatorLayerItem() && item != formLayerItem())
itemListWithoutLayerItems.append(item); itemListWithoutLayerItems.append(item);
@@ -422,16 +424,17 @@ void FormEditorScene::clearFormEditorItems()
const QList<FormEditorItem*> formEditorItems = Utils::filtered(formEditorItemsTransformed, const QList<FormEditorItem*> formEditorItems = Utils::filtered(formEditorItemsTransformed,
[](FormEditorItem *item) { return item; }); [](FormEditorItem *item) { return item; });
foreach (FormEditorItem *item, formEditorItems) for (FormEditorItem *item : formEditorItems)
item->setParentItem(nullptr); item->setParentItem(nullptr);
foreach (FormEditorItem *item, formEditorItems) for (FormEditorItem *item : formEditorItems)
delete item; delete item;
} }
void FormEditorScene::highlightBoundingRect(FormEditorItem *highlighItem) void FormEditorScene::highlightBoundingRect(FormEditorItem *highlighItem)
{ {
foreach (FormEditorItem *item, allFormEditorItems()) { QList<FormEditorItem *> items = allFormEditorItems();
for (FormEditorItem *item : items) {
if (item == highlighItem) if (item == highlighItem)
item->setHighlightBoundingRect(true); item->setHighlightBoundingRect(true);
else else

View File

@@ -166,8 +166,8 @@ void FormEditorView::setupFormEditorItemTree(const QmlItemNode &qmlItemNode)
static void deleteWithoutChildren(const QList<FormEditorItem*> &items) static void deleteWithoutChildren(const QList<FormEditorItem*> &items)
{ {
foreach (FormEditorItem *item, items) { for (const FormEditorItem *item : items) {
foreach (QGraphicsItem *child, item->childItems()) { for (QGraphicsItem *child : item->childItems()) {
child->setParentItem(item->scene()->rootFormEditorItem()); child->setParentItem(item->scene()->rootFormEditorItem());
} }
delete item; delete item;
@@ -286,11 +286,9 @@ void FormEditorView::nodeAboutToBeRemoved(const ModelNode &removedNode)
void FormEditorView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVersion*/, int /*minorVersion*/) void FormEditorView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVersion*/, int /*minorVersion*/)
{ {
foreach (FormEditorItem *item, m_scene->allFormEditorItems()) { const QList<FormEditorItem *> items = m_scene->allFormEditorItems();
for (FormEditorItem *item : items) {
item->setParentItem(nullptr); item->setParentItem(nullptr);
}
foreach (FormEditorItem *item, m_scene->allFormEditorItems()) {
m_scene->removeItemFromHash(item); m_scene->removeItemFromHash(item);
delete item; delete item;
} }
@@ -309,11 +307,12 @@ void FormEditorView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVer
void FormEditorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList) void FormEditorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList)
{ {
QList<FormEditorItem*> removedItems; QList<FormEditorItem*> removedItems;
foreach (const AbstractProperty &property, propertyList) { for (const AbstractProperty &property : propertyList) {
if (property.isNodeAbstractProperty()) { if (property.isNodeAbstractProperty()) {
NodeAbstractProperty nodeAbstractProperty = property.toNodeAbstractProperty(); NodeAbstractProperty nodeAbstractProperty = property.toNodeAbstractProperty();
foreach (const ModelNode &modelNode, nodeAbstractProperty.allSubNodes()) { const QList<ModelNode> modelNodes = nodeAbstractProperty.allSubNodes();
for (const ModelNode &modelNode : modelNodes) {
const QmlItemNode qmlItemNode(modelNode); const QmlItemNode qmlItemNode(modelNode);
if (qmlItemNode.isValid()){ if (qmlItemNode.isValid()){

View File

@@ -32,11 +32,11 @@ namespace QmlDesigner {
class FormEditorItem; class FormEditorItem;
QRectF boundingRectForItemList(QList<FormEditorItem*> itemList) QRectF boundingRectForItemList(const QList<FormEditorItem*> itemList)
{ {
QRectF boundingRect; QRectF boundingRect;
foreach (FormEditorItem *item, itemList) for (FormEditorItem *item : itemList)
{ {
boundingRect = boundingRect.united(item->mapToScene(item->qmlItemNode().instanceBoundingRect()).boundingRect()); boundingRect = boundingRect.united(item->mapToScene(item->qmlItemNode().instanceBoundingRect()).boundingRect());
} }

View File

@@ -69,8 +69,8 @@ QList<QGraphicsItem*> LayerItem::findAllChildItems(const QGraphicsItem *item) co
{ {
QList<QGraphicsItem*> itemList(item->childItems()); QList<QGraphicsItem*> itemList(item->childItems());
foreach (QGraphicsItem *childItem, item->childItems()) for (int end = itemList.length(), i = 0; i < end; ++i)
itemList += findAllChildItems(childItem); itemList += findAllChildItems(itemList.at(i));
return itemList; return itemList;
} }

View File

@@ -88,7 +88,7 @@ void MoveManipulator::synchronizeParent(const QList<FormEditorItem*> &itemList,
{ {
bool snapperUpdated = false; bool snapperUpdated = false;
foreach (FormEditorItem *item, itemList) { for (FormEditorItem *item : itemList) {
if (m_itemList.contains(item)) { if (m_itemList.contains(item)) {
QmlItemNode parentItemNode = QmlItemNode(parentNode); QmlItemNode parentItemNode = QmlItemNode(parentNode);
if (parentItemNode.isValid()) { if (parentItemNode.isValid()) {
@@ -111,7 +111,7 @@ void MoveManipulator::synchronizeInstanceParent(const QList<FormEditorItem*> &it
bool MoveManipulator::itemsCanReparented() const bool MoveManipulator::itemsCanReparented() const
{ {
foreach (FormEditorItem* item, m_itemList) { for (FormEditorItem* item : qAsConst(m_itemList)) {
if (item if (item
&& item->qmlItemNode().isValid() && item->qmlItemNode().isValid()
&& !item->qmlItemNode().instanceCanReparent()) && !item->qmlItemNode().instanceCanReparent())
@@ -123,7 +123,7 @@ bool MoveManipulator::itemsCanReparented() const
void MoveManipulator::setDirectUpdateInNodeInstances(bool directUpdate) void MoveManipulator::setDirectUpdateInNodeInstances(bool directUpdate)
{ {
foreach (FormEditorItem* item, m_itemList) { for (FormEditorItem* item : qAsConst(m_itemList)) {
if (item && item->qmlItemNode().isValid()) if (item && item->qmlItemNode().isValid())
item->qmlItemNode().nodeInstance().setDirectUpdate(directUpdate); item->qmlItemNode().nodeInstance().setDirectUpdate(directUpdate);
} }
@@ -136,7 +136,7 @@ void MoveManipulator::begin(const QPointF &beginPoint)
m_snapper.updateSnappingLines(m_itemList); m_snapper.updateSnappingLines(m_itemList);
foreach (FormEditorItem* item, m_itemList) { for (FormEditorItem* item : qAsConst(m_itemList)) {
if (item && item->qmlItemNode().isValid()) { if (item && item->qmlItemNode().isValid()) {
QTransform fromItemToSceneTransform = item->qmlItemNode().instanceSceneTransform(); QTransform fromItemToSceneTransform = item->qmlItemNode().instanceSceneTransform();
m_beginItemRectInSceneSpaceHash.insert(item, fromItemToSceneTransform.mapRect(item->qmlItemNode().instanceBoundingRect())); 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(); QTransform fromContentItemToSceneTransform = m_snapper.containerFormEditorItem()->qmlItemNode().instanceSceneContentItemTransform();
foreach (FormEditorItem* item, m_itemList) { for (FormEditorItem* item : qAsConst(m_itemList)) {
if (item && item->qmlItemNode().isValid()) { if (item && item->qmlItemNode().isValid()) {
QPointF positionInScenesSpace = fromContentItemToSceneTransform.map(item->instancePosition()); QPointF positionInScenesSpace = fromContentItemToSceneTransform.map(item->instancePosition());
m_beginPositionInSceneSpaceHash.insert(item, positionInScenesSpace); m_beginPositionInSceneSpaceHash.insert(item, positionInScenesSpace);
} }
} }
foreach (FormEditorItem* item, m_itemList) { for (FormEditorItem* item : qAsConst(m_itemList)) {
if (item && item->qmlItemNode().isValid()) { if (item && item->qmlItemNode().isValid()) {
QmlAnchors anchors(item->qmlItemNode().anchors()); QmlAnchors anchors(item->qmlItemNode().anchors());
m_beginTopMarginHash.insert(item, anchors.instanceMargin(AnchorLineTop)); 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)); 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); QPointF positionInContainerSpace(fromSceneToContentItemTransform.map(m_beginPositionInSceneSpaceHash.value(item)) + offsetVector);
if (!item || !item->qmlItemNode().isValid()) if (!item || !item->qmlItemNode().isValid())
@@ -363,7 +363,7 @@ void MoveManipulator::reparentTo(FormEditorItem *newParent, ReparentFlag flag)
else else
parentProperty = parentItemNode.nodeAbstractProperty("data"); parentProperty = parentItemNode.nodeAbstractProperty("data");
foreach (FormEditorItem* item, m_itemList) { for (FormEditorItem* item : qAsConst(m_itemList)) {
if (!item || !item->qmlItemNode().isValid()) if (!item || !item->qmlItemNode().isValid())
continue; 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); parentProperty.reparentHere(nodeToReparented);
synchronizeParent(m_itemList, parentProperty.parentModelNode()); synchronizeParent(m_itemList, parentProperty.parentModelNode());
@@ -393,7 +393,7 @@ void MoveManipulator::end()
void MoveManipulator::end(Snapper::Snapping useSnapping) void MoveManipulator::end(Snapper::Snapping useSnapping)
{ {
if (useSnapping == Snapper::UseSnappingAndAnchoring) { if (useSnapping == Snapper::UseSnappingAndAnchoring) {
foreach (FormEditorItem *formEditorItem, m_itemList) for (FormEditorItem* formEditorItem : qAsConst(m_itemList))
m_snapper.adjustAnchoringOfItem(formEditorItem); m_snapper.adjustAnchoringOfItem(formEditorItem);
} }
@@ -402,7 +402,7 @@ void MoveManipulator::end(Snapper::Snapping useSnapping)
void MoveManipulator::moveBy(double deltaX, double deltaY) void MoveManipulator::moveBy(double deltaX, double deltaY)
{ {
foreach (FormEditorItem* item, m_itemList) { for (FormEditorItem* item : qAsConst(m_itemList)) {
if (!item || !item->qmlItemNode().isValid()) if (!item || !item->qmlItemNode().isValid())
continue; continue;
@@ -444,14 +444,14 @@ void MoveManipulator::endRewriterTransaction()
void MoveManipulator::setOpacityForAllElements(qreal opacity) void MoveManipulator::setOpacityForAllElements(qreal opacity)
{ {
foreach (FormEditorItem* item, m_itemList) for (FormEditorItem* item : qAsConst(m_itemList))
item->setOpacity(opacity); item->setOpacity(opacity);
} }
void MoveManipulator::deleteSnapLines() void MoveManipulator::deleteSnapLines()
{ {
if (m_layerItem) { if (m_layerItem) {
foreach (QGraphicsItem *item, m_graphicsLineList) { for (QGraphicsItem *item : qAsConst(m_graphicsLineList)) {
m_layerItem->scene()->removeItem(item); m_layerItem->scene()->removeItem(item);
delete item; delete item;
} }

View File

@@ -271,7 +271,7 @@ void MoveTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> &itemList, QGra
void MoveTool::itemsAboutToRemoved(const QList<FormEditorItem*> &removedItemList) void MoveTool::itemsAboutToRemoved(const QList<FormEditorItem*> &removedItemList)
{ {
foreach (FormEditorItem* removedItem, removedItemList) for (FormEditorItem* removedItem : removedItemList)
m_movingItems.removeOne(removedItem); m_movingItems.removeOne(removedItem);
} }
@@ -304,7 +304,7 @@ bool MoveTool::haveSameParent(const QList<FormEditorItem*> &itemList)
return false; return false;
QGraphicsItem *firstParent = itemList.constFirst()->parentItem(); QGraphicsItem *firstParent = itemList.constFirst()->parentItem();
foreach (FormEditorItem* item, itemList) for (FormEditorItem* item : itemList)
{ {
if (firstParent != item->parentItem()) if (firstParent != item->parentItem())
return false; return false;
@@ -316,7 +316,7 @@ bool MoveTool::haveSameParent(const QList<FormEditorItem*> &itemList)
bool MoveTool::isAncestorOfAllItems(FormEditorItem* maybeAncestorItem, bool MoveTool::isAncestorOfAllItems(FormEditorItem* maybeAncestorItem,
const QList<FormEditorItem*> &itemList) const QList<FormEditorItem*> &itemList)
{ {
foreach (FormEditorItem* item, itemList) for (FormEditorItem* item : itemList)
{ {
if (!maybeAncestorItem->isAncestorOf(item) && item != maybeAncestorItem) if (!maybeAncestorItem->isAncestorOf(item) && item != maybeAncestorItem)
return false; return false;
@@ -332,7 +332,7 @@ FormEditorItem* MoveTool::ancestorIfOtherItemsAreChild(const QList<FormEditorIte
return nullptr; return nullptr;
foreach (FormEditorItem* item, itemList) for (FormEditorItem* item : itemList)
{ {
if (isAncestorOfAllItems(item, itemList)) if (isAncestorOfAllItems(item, itemList))
return item; return item;

View File

@@ -69,7 +69,7 @@ double OneDimensionalCluster::constFirst() const
QList<OneDimensionalCluster> OneDimensionalCluster::createOneDimensionalClusterList(const QList<double> & oneDimensionalCoordinateList) QList<OneDimensionalCluster> OneDimensionalCluster::createOneDimensionalClusterList(const QList<double> & oneDimensionalCoordinateList)
{ {
QList<OneDimensionalCluster> oneDimensionalClusterList; QList<OneDimensionalCluster> oneDimensionalClusterList;
foreach (double coordinate, oneDimensionalCoordinateList) for (double coordinate : oneDimensionalCoordinateList)
{ {
QList<double> initialList; QList<double> initialList;
initialList.append(coordinate); initialList.append(coordinate);
@@ -134,7 +134,7 @@ QList<double> OneDimensionalCluster::reduceLines(const QList<double> & oneDimens
clusterList = reduceOneDimensionalClusterList(clusterList, maximumDistance); clusterList = reduceOneDimensionalClusterList(clusterList, maximumDistance);
QList<double> lineList; QList<double> lineList;
foreach (const OneDimensionalCluster &cluster, clusterList) for (const OneDimensionalCluster &cluster : qAsConst(clusterList))
lineList.append(cluster.constFirst()); lineList.append(cluster.constFirst());
return lineList; return lineList;

View File

@@ -71,7 +71,7 @@ void ResizeIndicator::setItems(const QList<FormEditorItem*> &itemList)
{ {
clear(); clear();
foreach (FormEditorItem* item, itemList) { for (FormEditorItem* item : itemList) {
if (item && itemIsResizable(item->qmlItemNode())) { if (item && itemIsResizable(item->qmlItemNode())) {
ResizeController controller(m_layerItem, item); ResizeController controller(m_layerItem, item);
m_itemControllerHash.insert(item, controller); m_itemControllerHash.insert(item, controller);
@@ -81,7 +81,7 @@ void ResizeIndicator::setItems(const QList<FormEditorItem*> &itemList)
void ResizeIndicator::updateItems(const QList<FormEditorItem*> &itemList) void ResizeIndicator::updateItems(const QList<FormEditorItem*> &itemList)
{ {
foreach (FormEditorItem* item, itemList) { for (FormEditorItem* item : itemList) {
if (m_itemControllerHash.contains(item)) { if (m_itemControllerHash.contains(item)) {
if (!item || !itemIsResizable(item->qmlItemNode())) { if (!item || !itemIsResizable(item->qmlItemNode())) {
m_itemControllerHash.take(item); m_itemControllerHash.take(item);

View File

@@ -628,7 +628,7 @@ bool ResizeManipulator::isInvalidSize(const QSizeF & size)
void ResizeManipulator::deleteSnapLines() void ResizeManipulator::deleteSnapLines()
{ {
if (m_layerItem) { if (m_layerItem) {
foreach (QGraphicsItem *item, m_graphicsLineList) { for (QGraphicsItem *item : qAsConst(m_graphicsLineList)) {
m_layerItem->scene()->removeItem(item); m_layerItem->scene()->removeItem(item);
delete item; delete item;
} }

View File

@@ -220,7 +220,7 @@ void RotationManipulator::end()
void RotationManipulator::deleteSnapLines() void RotationManipulator::deleteSnapLines()
{ {
if (m_layerItem) { if (m_layerItem) {
foreach (QGraphicsItem *item, m_graphicsLineList) { for (QGraphicsItem *item : qAsConst(m_graphicsLineList)) {
m_layerItem->scene()->removeItem(item); m_layerItem->scene()->removeItem(item);
delete item; delete item;
} }

View File

@@ -51,7 +51,7 @@ void RubberBandSelectionManipulator::clear()
FormEditorItem *RubberBandSelectionManipulator::topFormEditorItem(const QList<QGraphicsItem*> &itemList) FormEditorItem *RubberBandSelectionManipulator::topFormEditorItem(const QList<QGraphicsItem*> &itemList)
{ {
foreach (QGraphicsItem *item, itemList) { for (QGraphicsItem *item : itemList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem) if (formEditorItem)

View File

@@ -54,7 +54,7 @@ SelectionIndicator::~SelectionIndicator()
void SelectionIndicator::show() void SelectionIndicator::show()
{ {
foreach (QGraphicsPolygonItem *item, m_indicatorShapeHash) for (QGraphicsPolygonItem *item : qAsConst(m_indicatorShapeHash))
item->show(); item->show();
if (m_labelItem) if (m_labelItem)
m_labelItem->show(); m_labelItem->show();
@@ -62,7 +62,7 @@ void SelectionIndicator::show()
void SelectionIndicator::hide() void SelectionIndicator::hide()
{ {
foreach (QGraphicsPolygonItem *item, m_indicatorShapeHash) for (QGraphicsPolygonItem *item : qAsConst(m_indicatorShapeHash))
item->hide(); item->hide();
if (m_labelItem) if (m_labelItem)
m_labelItem->hide(); m_labelItem->hide();
@@ -71,7 +71,7 @@ void SelectionIndicator::hide()
void SelectionIndicator::clear() void SelectionIndicator::clear()
{ {
if (m_layerItem) { if (m_layerItem) {
foreach (QGraphicsItem *item, m_indicatorShapeHash) { for (QGraphicsPolygonItem *item : qAsConst(m_indicatorShapeHash)) {
m_layerItem->scene()->removeItem(item); m_layerItem->scene()->removeItem(item);
delete item; delete item;
} }
@@ -102,7 +102,7 @@ void SelectionIndicator::setItems(const QList<FormEditorItem*> &itemList)
static QColor selectionColor = Utils::creatorTheme()->color(Utils::Theme::QmlDesigner_FormEditorSelectionColor); static QColor selectionColor = Utils::creatorTheme()->color(Utils::Theme::QmlDesigner_FormEditorSelectionColor);
foreach (FormEditorItem *item, itemList) { for (FormEditorItem *item : itemList) {
if (!item->qmlItemNode().isValid()) if (!item->qmlItemNode().isValid())
continue; continue;
@@ -178,7 +178,7 @@ void SelectionIndicator::setItems(const QList<FormEditorItem*> &itemList)
void SelectionIndicator::updateItems(const QList<FormEditorItem*> &itemList) void SelectionIndicator::updateItems(const QList<FormEditorItem*> &itemList)
{ {
foreach (FormEditorItem *item, itemList) { for (FormEditorItem *item : itemList) {
if (m_indicatorShapeHash.contains(item)) { if (m_indicatorShapeHash.contains(item)) {
QGraphicsPolygonItem *indicatorGraphicsItem = m_indicatorShapeHash.value(item); QGraphicsPolygonItem *indicatorGraphicsItem = m_indicatorShapeHash.value(item);
indicatorGraphicsItem->setPolygon(boundingRectInLayerItemSpaceForItem(item, m_layerItem.data())); indicatorGraphicsItem->setPolygon(boundingRectInLayerItemSpaceForItem(item, m_layerItem.data()));
@@ -207,7 +207,7 @@ void SelectionIndicator::setCursor(const QCursor &cursor)
{ {
m_cursor = cursor; m_cursor = cursor;
foreach (QGraphicsItem *item, m_indicatorShapeHash) for (QGraphicsItem *item : qAsConst(m_indicatorShapeHash))
item->setCursor(cursor); item->setCursor(cursor);
} }

View File

@@ -453,7 +453,7 @@ static QLineF mergedHorizontalLine(const QList<QLineF> &lineList)
double minimumX = std::numeric_limits<double>::max(); double minimumX = std::numeric_limits<double>::max();
double maximumX = std::numeric_limits<double>::min(); double maximumX = std::numeric_limits<double>::min();
foreach (const QLineF &line, lineList) { for (const QLineF &line : lineList) {
minimumX = qMin(minimumX, double(line.x1())); minimumX = qMin(minimumX, double(line.x1()));
minimumX = qMin(minimumX, double(line.x2())); minimumX = qMin(minimumX, double(line.x2()));
maximumX = qMax(maximumX, double(line.x1())); maximumX = qMax(maximumX, double(line.x1()));
@@ -471,7 +471,7 @@ static QLineF mergedVerticalLine(const QList<QLineF> &lineList)
double minimumY = std::numeric_limits<double>::max(); double minimumY = std::numeric_limits<double>::max();
double maximumY = std::numeric_limits<double>::min(); double maximumY = std::numeric_limits<double>::min();
foreach (const QLineF &line, lineList) { for (const QLineF &line : lineList) {
minimumY = qMin(minimumY, double(line.y1())); minimumY = qMin(minimumY, double(line.y1()));
minimumY = qMin(minimumY, double(line.y2())); minimumY = qMin(minimumY, double(line.y2()));
maximumY = qMax(maximumY, double(line.y1())); maximumY = qMax(maximumY, double(line.y1()));
@@ -705,13 +705,13 @@ QList<QGraphicsItem*> Snapper::generateSnappingLines(const QList<QRectF> &boundi
{ {
QList<QGraphicsItem*> graphicsItemList; QList<QGraphicsItem*> graphicsItemList;
QList<QLineF> lineList; QList<QLineF> lineList;
foreach (const QRectF &boundingRect, boundingRectList) { for (const QRectF &boundingRect : boundingRectList) {
QList<QRectF> snappedBoundingRectList; QList<QRectF> snappedBoundingRectList;
lineList += mergedHorizontalLines(horizontalSnappedLines(boundingRect, &snappedBoundingRectList)); lineList += mergedHorizontalLines(horizontalSnappedLines(boundingRect, &snappedBoundingRectList));
lineList += mergedVerticalLines(verticalSnappedLines(boundingRect, &snappedBoundingRectList)); lineList += mergedVerticalLines(verticalSnappedLines(boundingRect, &snappedBoundingRectList));
} }
foreach (const QLineF &line, lineList) { for (const QLineF &line : qAsConst(lineList)) {
QLineF lineInTransformationSpace = transform.map(line); QLineF lineInTransformationSpace = transform.map(line);
auto lineItem = new QGraphicsLineItem(lineInTransformationSpace, layerItem); auto lineItem = new QGraphicsLineItem(lineInTransformationSpace, layerItem);
lineItem->setZValue(40); lineItem->setZValue(40);

View File

@@ -99,7 +99,8 @@ void SnappingLineCreator::generateLines(const QList<FormEditorItem*> &exceptionL
addLines(containerBoundingRectInTransformationSpace, m_formEditorItem); addLines(containerBoundingRectInTransformationSpace, m_formEditorItem);
} }
foreach (FormEditorItem *item, m_formEditorItem->childFormEditorItems()) { const QList<FormEditorItem *> items = m_formEditorItem->childFormEditorItems();
for (FormEditorItem *item : items) {
if (!item || !item->qmlItemNode().isValid()) if (!item || !item->qmlItemNode().isValid())
continue; continue;