diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-11-30 12:19:31 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-12-16 17:41:37 +0000 |
commit | b69751863472b186aaad08db6b9b08de81e95dc4 (patch) | |
tree | 8bea3d79caf491f50770c34f1194a932c62493c1 /src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp | |
parent | 2d3b04e4f613ad3dfec9626bb5840dd91a3b1a82 (diff) |
QtWidgets: replace some Q_FOREACH loops 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 cannot happen, because all
containers are marked as const (either by this patch or before).
Separate patches will deal with other situations.
Range-for loops are much more efficient than foreach loops.
This patch shaves almost 3K of text size off an optimized Linux
AMD64 GCC 4.9 build.
Change-Id: I7b1d41db4d9b5db8b515cb75686dc5135177da68
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp index 5033264459..328d20be6e 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp @@ -602,10 +602,10 @@ QSimplexConstraint *GraphPath::constraint(const GraphPath &path) const QString GraphPath::toString() const { QString string(QLatin1String("Path: ")); - foreach(AnchorData *edge, positives) + for (AnchorData *edge : positives) string += QString::fromLatin1(" (+++) %1").arg(edge->toString()); - foreach(AnchorData *edge, negatives) + for (AnchorData *edge : negatives) string += QString::fromLatin1(" (---) %1").arg(edge->toString()); return string; @@ -1932,8 +1932,7 @@ void QGraphicsAnchorLayoutPrivate::removeVertex(QGraphicsLayoutItem *item, Qt::A if (AnchorVertex *v = internalVertex(item, edge)) { Graph<AnchorVertex, AnchorData> &g = graph[edgeOrientation(edge)]; const QList<AnchorVertex *> allVertices = graph[edgeOrientation(edge)].adjacentVertices(v); - AnchorVertex *v2; - foreach (v2, allVertices) { + for (auto *v2 : allVertices) { g.removeEdge(v, v2); removeInternalVertex(item, edge); removeInternalVertex(v2->m_item, v2->m_edge); @@ -2223,12 +2222,10 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const // Calculate and set the preferred size for the layout, // from the edge sizes that were calculated above. qreal pref(0.0); - foreach (const AnchorData *ad, path.positives) { + for (const AnchorData *ad : path.positives) pref += ad->sizeAtPreferred; - } - foreach (const AnchorData *ad, path.negatives) { + for (const AnchorData *ad : path.negatives) pref -= ad->sizeAtPreferred; - } sizeHints[orientation][Qt::MinimumSize] = min; sizeHints[orientation][Qt::PreferredSize] = pref; @@ -2368,8 +2365,8 @@ void QGraphicsAnchorLayoutPrivate::findPaths(Orientation orientation) */ void QGraphicsAnchorLayoutPrivate::constraintsFromPaths(Orientation orientation) { - foreach (AnchorVertex *vertex, graphPaths[orientation].uniqueKeys()) - { + const auto vertices = graphPaths[orientation].uniqueKeys(); + for (AnchorVertex *vertex : vertices) { int valueCount = graphPaths[orientation].count(vertex); if (valueCount == 1) continue; |