QGraphicsAnchorLayout: compile with QT_NO_FOREACH

The m_edges container isn't changed after it's initialized in the
constructor (in a later commit I'll make this container const, so as to
keep this commit backport-able), and it isn't changed by the loop. Port
all loops over m_edges to ranged-for.

Remove "#undef QT_NO_FOREACH" from the source file, as that was the only
usage of foreach in it. And remove that source file from NO_PCH_SOURCES.

Pick-to: 6.6 6.5
Task-number: QTBUG-115803
Change-Id: I9cfc0c95865cbc7415dbecc82388c64c65ded4be
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
This commit is contained in:
Ahmad Samir 2023-08-13 01:05:06 +03:00
parent 4f1bb8ee40
commit 641bccce2a
2 changed files with 9 additions and 21 deletions

View File

@ -805,8 +805,6 @@ qt_internal_extend_target(Widgets CONDITION QT_FEATURE_graphicsview
graphicsview/qgraphicsview.cpp graphicsview/qgraphicsview.h graphicsview/qgraphicsview_p.h
graphicsview/qgraphicswidget.cpp graphicsview/qgraphicswidget.h graphicsview/qgraphicswidget_p.cpp graphicsview/qgraphicswidget_p.h
graphicsview/qsimplex_p.cpp graphicsview/qsimplex_p.h
NO_PCH_SOURCES
graphicsview/qgraphicsanchorlayout_p.cpp # undef QT_NO_FOREACH
)
qt_internal_extend_target(Widgets CONDITION QT_FEATURE_easingcurve AND QT_FEATURE_graphicsview

View File

@ -1,8 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "qgraphicsanchorlayout_p.h"
#include <QtWidgets/qwidget.h>
@ -461,9 +459,7 @@ void SequentialAnchorData::updateChildrenSizes()
// "from" or "to", that _contains_ one of them.
AnchorVertex *prev = from;
for (int i = 0; i < m_edges.size(); ++i) {
AnchorData *e = m_edges.at(i);
for (AnchorData *e : std::as_const(m_edges)) {
const bool edgeIsForward = (e->from == prev);
if (edgeIsForward) {
e->sizeAtMinimum = interpolate(minFactor, e->minSize, e->minPrefSize,
@ -498,9 +494,7 @@ void SequentialAnchorData::calculateSizeHints()
AnchorVertex *prev = from;
for (int i = 0; i < m_edges.size(); ++i) {
AnchorData *edge = m_edges.at(i);
for (AnchorData *edge : std::as_const(m_edges)) {
const bool edgeIsForward = (edge->from == prev);
if (edgeIsForward) {
minSize += edge->minSize;
@ -534,12 +528,10 @@ void AnchorData::dump(int indent) {
p->firstEdge->dump(indent+2);
p->secondEdge->dump(indent+2);
} else if (type == Sequential) {
SequentialAnchorData *s = static_cast<SequentialAnchorData *>(this);
int kids = s->m_edges.count();
qDebug("%*s type: sequential(%d):", indent, "", kids);
for (int i = 0; i < kids; ++i) {
s->m_edges.at(i)->dump(indent+2);
}
const auto *s = static_cast<SequentialAnchorData *>(this);
qDebug("%*s type: sequential(%lld):", indent, "", s->m_edges.size());
for (AnchorData *e : s->m_edges)
e->dump(indent + 2);
} else {
qDebug("%*s type: Normal:", indent, "");
}
@ -1155,12 +1147,10 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedAnchor(AnchorData *edge)
g.createEdge(edge->from, edge->to, edge);
} else if (edge->type == AnchorData::Sequential) {
SequentialAnchorData *sequence = static_cast<SequentialAnchorData *>(edge);
const auto *sequence = static_cast<SequentialAnchorData *>(edge);
for (int i = 0; i < sequence->m_edges.size(); ++i) {
AnchorData *data = sequence->m_edges.at(i);
for (AnchorData *data : sequence->m_edges)
restoreSimplifiedAnchor(data);
}
delete sequence;
@ -2556,7 +2546,7 @@ void QGraphicsAnchorLayoutPrivate::identifyNonFloatItems_helper(const AnchorData
nonFloatingItemsIdentifiedSoFar->insert(ad->item);
break;
case AnchorData::Sequential:
foreach (const AnchorData *d, static_cast<const SequentialAnchorData *>(ad)->m_edges)
for (const AnchorData *d : static_cast<const SequentialAnchorData *>(ad)->m_edges)
identifyNonFloatItems_helper(d, nonFloatingItemsIdentifiedSoFar);
break;
case AnchorData::Parallel: