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/gui/text/qtextlayout.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/gui/text/qtextlayout.cpp')
-rw-r--r-- | src/gui/text/qtextlayout.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 43236eec91..32fac09f33 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -646,8 +646,8 @@ int QTextLayout::nextCursorPosition(int oldPos, CursorMode mode) const { const QCharAttributes *attributes = d->attributes(); int len = d->block.isValid() ? d->block.length() - 1 - : d->layoutData->string.length(); - Q_ASSERT(len <= d->layoutData->string.length()); + : d->layoutData->string.size(); + Q_ASSERT(len <= d->layoutData->string.size()); if (!attributes || oldPos < 0 || oldPos >= len) return oldPos; @@ -682,8 +682,8 @@ int QTextLayout::previousCursorPosition(int oldPos, CursorMode mode) const { const QCharAttributes *attributes = d->attributes(); int len = d->block.isValid() ? d->block.length() - 1 - : d->layoutData->string.length(); - Q_ASSERT(len <= d->layoutData->string.length()); + : d->layoutData->string.size(); + Q_ASSERT(len <= d->layoutData->string.size()); if (!attributes || oldPos <= 0 || oldPos > len) return oldPos; @@ -754,7 +754,7 @@ int QTextLayout::leftCursorPosition(int oldPos) const bool QTextLayout::isValidCursorPosition(int pos) const { const QCharAttributes *attributes = d->attributes(); - if (!attributes || pos < 0 || pos > (int)d->layoutData->string.length()) + if (!attributes || pos < 0 || pos > (int)d->layoutData->string.size()) return false; return attributes[pos].graphemeBoundary; } @@ -795,7 +795,7 @@ QTextLine QTextLayout::createLine() } } int from = l > 0 ? d->lines.at(l-1).from + d->lines.at(l-1).length + d->lines.at(l-1).trailingSpaces : 0; - int strlen = d->layoutData->string.length(); + int strlen = d->layoutData->string.size(); if (l && from >= strlen) { if (!d->lines.at(l-1).length || d->layoutData->string.at(strlen - 1) != QChar::LineSeparator) return QTextLine(); @@ -1032,7 +1032,7 @@ QList<QGlyphRun> QTextLayout::glyphRuns(int from, if (from < 0) from = 0; if (length < 0) - length = text().length(); + length = text().size(); QHash<QPair<QFontEngine *, int>, QGlyphRun> glyphRunHash; for (int i=0; i<d->lines.size(); ++i) { @@ -1289,7 +1289,7 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition QPointF position = pos + d->position; - cursorPosition = qBound(0, cursorPosition, d->layoutData->string.length()); + cursorPosition = qBound(0, cursorPosition, d->layoutData->string.size()); int line = d->lineNumberForTextPosition(cursorPosition); if (line < 0) line = 0; @@ -1617,7 +1617,7 @@ void QTextLine::setLineWidth(qreal width) line.width = QFixed::fromReal(width); if (line.length && line.textWidth <= line.width - && line.from + line.length == eng->layoutData->string.length()) + && line.from + line.length == eng->layoutData->string.size()) // no need to do anything if the line is already layouted and the last one. This optimization helps // when using things in a single line layout. return; @@ -1833,12 +1833,12 @@ void QTextLine::layout_helper(int maxGlyphs) line.textWidth = 0; line.hasTrailingSpaces = false; - if (!eng->layoutData->items.size() || line.from >= eng->layoutData->string.length()) { + if (!eng->layoutData->items.size() || line.from >= eng->layoutData->string.size()) { line.setDefaultHeight(eng); return; } - Q_ASSERT(line.from < eng->layoutData->string.length()); + Q_ASSERT(line.from < eng->layoutData->string.size()); LineBreakHelper lbh; @@ -1993,11 +1993,11 @@ void QTextLine::layout_helper(int maxGlyphs) // spaces to behave as in previous Qt versions in the line breaking algorithm. // The line breaks do not currently follow the Unicode specs, but fixing this would // require refactoring the code and would cause behavioral regressions. - const bool isBreakableSpace = lbh.currentPosition < eng->layoutData->string.length() + const bool isBreakableSpace = lbh.currentPosition < eng->layoutData->string.size() && attributes[lbh.currentPosition].whiteSpace && eng->layoutData->string.at(lbh.currentPosition).decompositionTag() != QChar::NoBreak; - if (lbh.currentPosition >= eng->layoutData->string.length() + if (lbh.currentPosition >= eng->layoutData->string.size() || isBreakableSpace || attributes[lbh.currentPosition].lineBreak || lbh.tmpData.textWidth >= QFIXED_MAX) { |