diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-09-30 14:09:04 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-10-04 07:40:08 +0200 |
commit | df9d882d41b741fef7c5beeddb0abe9d904443d8 (patch) | |
tree | 6f3e90dacad4581b7f1cabe235cca298833a3da4 /src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp | |
parent | 109e088c7c5d0c9325966e88d55fd9f7a58f67ea (diff) |
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp index d26669e079..81c18741e5 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp @@ -459,7 +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) { + for (int i = 0; i < m_edges.size(); ++i) { AnchorData *e = m_edges.at(i); const bool edgeIsForward = (e->from == prev); @@ -496,7 +496,7 @@ void SequentialAnchorData::calculateSizeHints() AnchorVertex *prev = from; - for (int i = 0; i < m_edges.count(); ++i) { + for (int i = 0; i < m_edges.size(); ++i) { AnchorData *edge = m_edges.at(i); const bool edgeIsForward = (edge->from == prev); @@ -666,7 +666,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); @@ -712,9 +712,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) { @@ -840,7 +840,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); @@ -888,7 +888,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++; @@ -908,7 +908,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); @@ -916,7 +916,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); @@ -1019,7 +1019,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 @@ -1061,7 +1061,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; @@ -1100,7 +1100,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; @@ -1155,7 +1155,7 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedAnchor(AnchorData *edge) } else if (edge->type == AnchorData::Sequential) { SequentialAnchorData *sequence = static_cast<SequentialAnchorData *>(edge); - for (int i = 0; i < sequence->m_edges.count(); ++i) { + for (int i = 0; i < sequence->m_edges.size(); ++i) { AnchorData *data = sequence->m_edges.at(i); restoreSimplifiedAnchor(data); } @@ -1190,7 +1190,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); @@ -1201,7 +1201,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) @@ -1221,7 +1221,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); @@ -1257,14 +1257,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 *> ¶llelAnchors = 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); @@ -1275,7 +1275,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); @@ -1284,7 +1284,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); @@ -1292,7 +1292,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)); } @@ -1502,7 +1502,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; @@ -1523,7 +1523,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)); @@ -2016,7 +2016,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())); @@ -2131,7 +2131,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; @@ -2189,8 +2189,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; @@ -2221,7 +2221,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; @@ -2245,7 +2245,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); } @@ -2337,7 +2337,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(); } @@ -2659,7 +2659,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))); } @@ -2743,7 +2743,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 |