summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraphicswidget.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-11-30 12:19:31 +0100
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-12-23 09:14:03 +0000
commit4e628397b0ef6f8d5e9294e85507488cebe740f3 (patch)
tree47e39ade7cf381fd862e0d399811b997fd83b22e /src/widgets/graphicsview/qgraphicswidget.cpp
parent29ddfc3be730ca48cbec0e3b4508b006ba79eb66 (diff)
QGraphicsView: replace some Q_FOREACH loops over rvalues with C++11 range-for
This needs to be handled a bit carefully, because Qt containers will detach upon being iterated over using range-for. In the cases of this patch, that trivially cannot happen, because all containers are marked as const when being assigned the rvalues previously found on the rhs of the Q_FOREACH. The new code thus does exactly what the old code did: take a const copy, then iterate over it. Separate patches will deal with other situations. Range-for loops are much more efficient than foreach loops. This patch shaves almost 4K of text size off an optimized Linux AMD64 GCC 4.9 build. Change-Id: Ida868b77d078cbfa0516d17e98e6f0a86fcdb7a3 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/widgets/graphicsview/qgraphicswidget.cpp')
-rw-r--r--src/widgets/graphicsview/qgraphicswidget.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp
index ef086aeab0..db1cdd42ab 100644
--- a/src/widgets/graphicsview/qgraphicswidget.cpp
+++ b/src/widgets/graphicsview/qgraphicswidget.cpp
@@ -251,7 +251,8 @@ QGraphicsWidget::~QGraphicsWidget()
//we check if we have a layout previously
if (d->layout) {
QGraphicsLayout *temp = d->layout;
- foreach (QGraphicsItem * item, childItems()) {
+ const auto items = childItems();
+ for (QGraphicsItem *item : items) {
// In case of a custom layout which doesn't remove and delete items, we ensure that
// the parent layout item does not point to the deleted layout. This code is here to
// avoid regression from 4.4 to 4.5, because according to 4.5 docs it is not really needed.