diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-12-07 11:59:02 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-01-23 18:49:02 +0000 |
commit | 26f7edb09eaf66590de9a3603489464fd868eedc (patch) | |
tree | b49374b0649421072494150d7ec6ff84f43fa051 /examples/widgets/graphicsview/diagramscene/mainwindow.cpp | |
parent | bce32c8ab8c547d0fc9d12d192546dde361443fa (diff) |
Cleanup Widgets examples - foreach
Cleanup the Widgets examples - replace foreach with range-based for loop
in graphicsview subdirectory
Change-Id: I9093b3ae89d73d0b860d29929943881c90074bce
Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'examples/widgets/graphicsview/diagramscene/mainwindow.cpp')
-rw-r--r-- | examples/widgets/graphicsview/diagramscene/mainwindow.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp index 875c41b284..07f92f61c1 100644 --- a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp +++ b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp @@ -92,8 +92,8 @@ MainWindow::MainWindow() //! [1] void MainWindow::backgroundButtonGroupClicked(QAbstractButton *button) { - QList<QAbstractButton *> buttons = backgroundButtonGroup->buttons(); - foreach (QAbstractButton *myButton, buttons) { + const QList<QAbstractButton *> buttons = backgroundButtonGroup->buttons(); + for (QAbstractButton *myButton : buttons) { if (myButton != button) button->setChecked(false); } @@ -115,8 +115,8 @@ void MainWindow::backgroundButtonGroupClicked(QAbstractButton *button) //! [2] void MainWindow::buttonGroupClicked(int id) { - QList<QAbstractButton *> buttons = buttonGroup->buttons(); - foreach (QAbstractButton *button, buttons) { + const QList<QAbstractButton *> buttons = buttonGroup->buttons(); + for (QAbstractButton *button : buttons) { if (buttonGroup->button(id) != button) button->setChecked(false); } @@ -132,7 +132,8 @@ void MainWindow::buttonGroupClicked(int id) //! [3] void MainWindow::deleteItem() { - foreach (QGraphicsItem *item, scene->selectedItems()) { + QList<QGraphicsItem *> selectedItems = scene->selectedItems(); + for (QGraphicsItem *item : qAsConst(selectedItems)) { if (item->type() == Arrow::Type) { scene->removeItem(item); Arrow *arrow = qgraphicsitem_cast<Arrow *>(item); @@ -142,7 +143,8 @@ void MainWindow::deleteItem() } } - foreach (QGraphicsItem *item, scene->selectedItems()) { + selectedItems = scene->selectedItems(); + for (QGraphicsItem *item : qAsConst(selectedItems)) { if (item->type() == DiagramItem::Type) qgraphicsitem_cast<DiagramItem *>(item)->removeArrows(); scene->removeItem(item); @@ -165,10 +167,10 @@ void MainWindow::bringToFront() return; QGraphicsItem *selectedItem = scene->selectedItems().first(); - QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems(); + const QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems(); qreal zValue = 0; - foreach (QGraphicsItem *item, overlapItems) { + for (const QGraphicsItem *item : overlapItems) { if (item->zValue() >= zValue && item->type() == DiagramItem::Type) zValue = item->zValue() + 0.1; } @@ -183,10 +185,10 @@ void MainWindow::sendToBack() return; QGraphicsItem *selectedItem = scene->selectedItems().first(); - QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems(); + const QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems(); qreal zValue = 0; - foreach (QGraphicsItem *item, overlapItems) { + for (const QGraphicsItem *item : overlapItems) { if (item->zValue() <= zValue && item->type() == DiagramItem::Type) zValue = item->zValue() - 0.1; } |