summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp')
-rw-r--r--src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp94
1 files changed, 44 insertions, 50 deletions
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
index 16286e47bf..8a5280d44c 100644
--- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -459,9 +459,7 @@ void SequentialAnchorData::updateChildrenSizes()
// "from" or "to", that _contains_ one of them.
AnchorVertex *prev = from;
- for (int i = 0; i < m_edges.count(); ++i) {
- AnchorData *e = m_edges.at(i);
-
+ for (AnchorData *e : m_edges) {
const bool edgeIsForward = (e->from == prev);
if (edgeIsForward) {
e->sizeAtMinimum = interpolate(minFactor, e->minSize, e->minPrefSize,
@@ -496,9 +494,7 @@ void SequentialAnchorData::calculateSizeHints()
AnchorVertex *prev = from;
- for (int i = 0; i < m_edges.count(); ++i) {
- AnchorData *edge = m_edges.at(i);
-
+ for (AnchorData *edge : m_edges) {
const bool edgeIsForward = (edge->from == prev);
if (edgeIsForward) {
minSize += edge->minSize;
@@ -532,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, "", qint64(s->m_edges.size()));
+ for (AnchorData *e : s->m_edges)
+ e->dump(indent + 2);
} else {
qDebug("%*s type: Normal:", indent, "");
}
@@ -575,7 +569,9 @@ QSimplexConstraint *GraphPath::constraint(const GraphPath &path) const
#ifdef QT_DEBUG
QString GraphPath::toString() const
{
- QString string("Path: "_L1);
+ QString string;
+ string += "Path: "_L1;
+
for (AnchorData *edge : positives)
string += QString::fromLatin1(" (+++) %1").arg(edge->toString());
@@ -664,7 +660,7 @@ AnchorData *QGraphicsAnchorLayoutPrivate::addAnchorMaybeParallel(AnchorData *new
parallel->isCenterAnchor = true;
- for (int j = 0; j < constraints.count(); ++j) {
+ for (int j = 0; j < constraints.size(); ++j) {
QSimplexConstraint *c = constraints[j];
if (c->variables.contains(child)) {
childConstraints->append(c);
@@ -710,9 +706,9 @@ static AnchorData *createSequence(Graph<AnchorVertex, AnchorData> *graph, Anchor
AnchorVertex *prev = before;
QList<AnchorData *> edges;
- edges.reserve(vertices.count() + 1);
+ edges.reserve(vertices.size() + 1);
- const int numVertices = vertices.count();
+ const int numVertices = vertices.size();
edges.reserve(numVertices + 1);
// Take from the graph, the edges that will be simplificated
for (int i = 0; i < numVertices; ++i) {
@@ -838,7 +834,7 @@ bool QGraphicsAnchorLayoutPrivate::replaceVertex(Qt::Orientation orientation, An
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
bool feasible = true;
- for (int i = 0; i < edges.count(); ++i) {
+ for (int i = 0; i < edges.size(); ++i) {
AnchorData *ad = edges[i];
AnchorVertex *otherV = replaceVertex_helper(ad, oldV, newV);
@@ -886,7 +882,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyVertices(Qt::Orientation orientation)
QList<AnchorVertex *> adjacents = g.adjacentVertices(v);
int index = 0;
- while (index < adjacents.count()) {
+ while (index < adjacents.size()) {
AnchorVertex *next = adjacents.at(index);
index++;
@@ -906,7 +902,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyVertices(Qt::Orientation orientation)
const QList<AnchorVertex *> &vAdjacents = g.adjacentVertices(v);
const QList<AnchorVertex *> &nextAdjacents = g.adjacentVertices(next);
- for (int i = 0; i < vAdjacents.count(); ++i) {
+ for (int i = 0; i < vAdjacents.size(); ++i) {
AnchorVertex *adjacent = vAdjacents.at(i);
if (adjacent != next) {
AnchorData *ad = g.edgeData(v, adjacent);
@@ -914,7 +910,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyVertices(Qt::Orientation orientation)
}
}
- for (int i = 0; i < nextAdjacents.count(); ++i) {
+ for (int i = 0; i < nextAdjacents.size(); ++i) {
AnchorVertex *adjacent = nextAdjacents.at(i);
if (adjacent != v) {
AnchorData *ad = g.edgeData(next, adjacent);
@@ -1017,7 +1013,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(Qt::Orientation orient
//
// Identifies cases (a) and (b)
- endOfSequence = isLayoutVertex || adjacents.count() != 2;
+ endOfSequence = isLayoutVertex || adjacents.size() != 2;
if (!endOfSequence) {
// This is a tricky part. We peek at the next vertex to find out whether
@@ -1059,7 +1055,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(Qt::Orientation orient
//
// Add next non-visited vertices to the stack.
//
- for (int i = 0; i < adjacents.count(); ++i) {
+ for (int i = 0; i < adjacents.size(); ++i) {
AnchorVertex *next = adjacents.at(i);
if (visited.contains(next))
continue;
@@ -1098,7 +1094,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(Qt::Orientation orient
const AnchorData *lastAnchor = g.edgeData(candidates.constLast(), afterSequence);
if (lastAnchor->isCenterAnchor) {
afterSequence = candidates.constLast();
- candidates.remove(candidates.count() - 1);
+ candidates.remove(candidates.size() - 1);
if (candidates.isEmpty())
continue;
@@ -1151,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.count(); ++i) {
- AnchorData *data = sequence->m_edges.at(i);
+ for (AnchorData *data : sequence->m_edges)
restoreSimplifiedAnchor(data);
- }
delete sequence;
@@ -1188,7 +1182,7 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedConstraints(ParallelAnchorDa
if (!parallel->isCenterAnchor)
return;
- for (int i = 0; i < parallel->m_firstConstraints.count(); ++i) {
+ for (int i = 0; i < parallel->m_firstConstraints.size(); ++i) {
QSimplexConstraint *c = parallel->m_firstConstraints.at(i);
qreal v = c->variables[parallel];
c->variables.remove(parallel);
@@ -1199,7 +1193,7 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedConstraints(ParallelAnchorDa
// addAnchorMaybeParallel().
const bool needsReverse = !parallel->secondForward();
- for (int i = 0; i < parallel->m_secondConstraints.count(); ++i) {
+ for (int i = 0; i < parallel->m_secondConstraints.size(); ++i) {
QSimplexConstraint *c = parallel->m_secondConstraints.at(i);
qreal v = c->variables[parallel];
if (needsReverse)
@@ -1219,7 +1213,7 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Qt::Orientation orient
// Restore anchor simplification
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
QList<QPair<AnchorVertex *, AnchorVertex *>> connections = g.connections();
- for (int i = 0; i < connections.count(); ++i) {
+ for (int i = 0; i < connections.size(); ++i) {
AnchorVertex *v1 = connections.at(i).first;
AnchorVertex *v2 = connections.at(i).second;
AnchorData *edge = g.edgeData(v1, v2);
@@ -1255,14 +1249,14 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Qt::Orientation orientation)
// In the next step, we'll change the anchors vertices so that would not be possible anymore.
QList<AnchorData *> &parallelAnchors = anchorsFromSimplifiedVertices[orientation];
- for (int i = parallelAnchors.count() - 1; i >= 0; --i) {
+ for (int i = parallelAnchors.size() - 1; i >= 0; --i) {
ParallelAnchorData *parallel = static_cast<ParallelAnchorData *>(parallelAnchors.at(i));
restoreSimplifiedConstraints(parallel);
}
// Then, we will restore the vertices in the inverse order of creation, this way we ensure that
// the vertex being restored was not wrapped by another simplification.
- for (int i = toRestore.count() - 1; i >= 0; --i) {
+ for (int i = toRestore.size() - 1; i >= 0; --i) {
AnchorVertexPair *pair = toRestore.at(i);
QList<AnchorVertex *> adjacents = g.adjacentVertices(pair);
@@ -1273,7 +1267,7 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Qt::Orientation orientation)
g.createEdge(first, second, pair->m_removedAnchor);
// Restore the anchors for the first child vertex
- for (int j = 0; j < pair->m_firstAnchors.count(); ++j) {
+ for (int j = 0; j < pair->m_firstAnchors.size(); ++j) {
AnchorData *ad = pair->m_firstAnchors.at(j);
Q_ASSERT(ad->from == pair || ad->to == pair);
@@ -1282,7 +1276,7 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Qt::Orientation orientation)
}
// Restore the anchors for the second child vertex
- for (int j = 0; j < pair->m_secondAnchors.count(); ++j) {
+ for (int j = 0; j < pair->m_secondAnchors.size(); ++j) {
AnchorData *ad = pair->m_secondAnchors.at(j);
Q_ASSERT(ad->from == pair || ad->to == pair);
@@ -1290,7 +1284,7 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Qt::Orientation orientation)
g.createEdge(ad->from, ad->to, ad);
}
- for (int j = 0; j < adjacents.count(); ++j) {
+ for (int j = 0; j < adjacents.size(); ++j) {
g.takeEdge(pair, adjacents.at(j));
}
@@ -1500,7 +1494,7 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors(
AnchorData *oldData = g.edgeData(first, center);
// Remove center constraint
- for (int i = itemCenterConstraints[orientation].count() - 1; i >= 0; --i) {
+ for (int i = itemCenterConstraints[orientation].size() - 1; i >= 0; --i) {
if (itemCenterConstraints[orientation].at(i)->variables.contains(oldData)) {
delete itemCenterConstraints[orientation].takeAt(i);
break;
@@ -1521,7 +1515,7 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors(
// this is only called from removeAnchors()
// first, remove all non-internal anchors
QList<AnchorVertex*> adjacents = g.adjacentVertices(center);
- for (int i = 0; i < adjacents.count(); ++i) {
+ for (int i = 0; i < adjacents.size(); ++i) {
AnchorVertex *v = adjacents.at(i);
if (v->m_item != item) {
removeAnchor_helper(center, internalVertex(v->m_item, v->m_edge));
@@ -2014,7 +2008,7 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs()
QList<AnchorData *> getVariables(const QList<QSimplexConstraint *> &constraints)
{
QSet<AnchorData *> variableSet;
- for (int i = 0; i < constraints.count(); ++i) {
+ for (int i = 0; i < constraints.size(); ++i) {
const QSimplexConstraint *c = constraints.at(i);
for (auto it = c->variables.cbegin(), end = c->variables.cend(); it != end; ++it)
variableSet.insert(static_cast<AnchorData *>(it.key()));
@@ -2129,7 +2123,7 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs(Qt::Orientation orientation)
*/
static void shiftConstraints(const QList<QSimplexConstraint *> &constraints, qreal amount)
{
- for (int i = 0; i < constraints.count(); ++i) {
+ for (int i = 0; i < constraints.size(); ++i) {
QSimplexConstraint *c = constraints.at(i);
const qreal multiplier = std::accumulate(c->variables.cbegin(), c->variables.cend(), qreal(0));
c->constant += multiplier * amount;
@@ -2187,8 +2181,8 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Qt::Orientation orientation, c
} else {
// No Simplex is necessary because the path was simplified all the way to a single
// anchor.
- Q_ASSERT(path.positives.count() == 1);
- Q_ASSERT(path.negatives.count() == 0);
+ Q_ASSERT(path.positives.size() == 1);
+ Q_ASSERT(path.negatives.size() == 0);
AnchorData *ad = *path.positives.cbegin();
ad->sizeAtMinimum = ad->minSize;
@@ -2219,7 +2213,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList<QSimplexConstra
if (feasible) {
// Propagate size at preferred to other sizes. Semi-floats always will be
// in their sizeAtPreferred.
- for (int j = 0; j < variables.count(); ++j) {
+ for (int j = 0; j < variables.size(); ++j) {
AnchorData *ad = variables.at(j);
Q_ASSERT(ad);
ad->sizeAtMinimum = ad->sizeAtPreferred;
@@ -2243,7 +2237,7 @@ void QGraphicsAnchorLayoutPrivate::refreshAllSizeHints(Qt::Orientation orientati
QList<QPair<AnchorVertex *, AnchorVertex *>> vertices = g.connections();
QLayoutStyleInfo styleInf = styleInfo();
- for (int i = 0; i < vertices.count(); ++i) {
+ for (int i = 0; i < vertices.size(); ++i) {
AnchorData *data = g.edgeData(vertices.at(i).first, vertices.at(i).second);
data->refreshSizeHints(&styleInf);
}
@@ -2335,7 +2329,7 @@ void QGraphicsAnchorLayoutPrivate::updateAnchorSizes(Qt::Orientation orientation
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
const QList<QPair<AnchorVertex *, AnchorVertex *>> &vertices = g.connections();
- for (int i = 0; i < vertices.count(); ++i) {
+ for (int i = 0; i < vertices.size(); ++i) {
AnchorData *ad = g.edgeData(vertices.at(i).first, vertices.at(i).second);
ad->updateChildrenSizes();
}
@@ -2478,7 +2472,7 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Qt::Orientation orientation)
// Check if this constraint have some overlap with current
// trunk variables...
- for (QSimplexVariable *ad : qAsConst(trunkVariables)) {
+ for (QSimplexVariable *ad : std::as_const(trunkVariables)) {
if (c->variables.contains(ad)) {
match = true;
break;
@@ -2527,7 +2521,7 @@ void QGraphicsAnchorLayoutPrivate::identifyFloatItems(const QSet<AnchorData *> &
identifyNonFloatItems_helper(ad, &nonFloating);
QSet<QGraphicsLayoutItem *> floatItems;
- for (QGraphicsLayoutItem *item : qAsConst(items)) {
+ for (QGraphicsLayoutItem *item : std::as_const(items)) {
if (!nonFloating.contains(item))
floatItems.insert(item);
}
@@ -2552,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:
@@ -2586,7 +2580,7 @@ void QGraphicsAnchorLayoutPrivate::setItemsGeometries(const QRectF &geom)
top += geom.top();
right = geom.right() - right;
- for (QGraphicsLayoutItem *item : qAsConst(items)) {
+ for (QGraphicsLayoutItem *item : std::as_const(items)) {
QRectF newGeom;
QSizeF itemPreferredSize = item->effectiveSizeHint(Qt::PreferredSize);
if (m_floatItems[Qt::Horizontal].contains(item)) {
@@ -2657,7 +2651,7 @@ void QGraphicsAnchorLayoutPrivate::calculateVertexPositions(Qt::Orientation orie
interpolateEdge(pair.first, edge);
QList<AnchorVertex *> adjacents = graph[orientation].adjacentVertices(pair.second);
- for (int i = 0; i < adjacents.count(); ++i) {
+ for (int i = 0; i < adjacents.size(); ++i) {
if (!visited.contains(adjacents.at(i)))
queue.enqueue(qMakePair(pair.second, adjacents.at(i)));
}
@@ -2741,7 +2735,7 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList<QSimplexConstraint *>
for (iter = path.negatives.constBegin(); iter != path.negatives.constEnd(); ++iter)
objective.variables.insert(*iter, -1.0);
- const qreal objectiveOffset = (path.positives.count() - path.negatives.count()) * g_offset;
+ const qreal objectiveOffset = (path.positives.size() - path.negatives.size()) * g_offset;
simplex.setObjective(&objective);
// Calculate minimum values