From dd15658245e36c764964397d64120bc26607787a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 5 Oct 2022 08:16:07 +0200 Subject: Port from container::count() and length() to size() This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8: auto QtContainerClass = anyOf( expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o), expr(hasType(namedDecl(hasAnyName()))).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', with the extended set of container classes recognized. Change-Id: I591240bbee393617e15beee71a2a5e1e7ba79510 Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- src/svg/qsvggraphics.cpp | 4 +-- src/svg/qsvghandler.cpp | 88 +++++++++++++++++++++++------------------------ src/svg/qsvgstructure.cpp | 4 +-- src/svg/qsvgstyle.cpp | 6 ++-- 4 files changed, 51 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/svg/qsvggraphics.cpp b/src/svg/qsvggraphics.cpp index 41fa7c1..4f735b6 100644 --- a/src/svg/qsvggraphics.cpp +++ b/src/svg/qsvggraphics.cpp @@ -341,8 +341,8 @@ void QSvgText::draw_helper(QPainter *p, QSvgExtraStates &states, QRectF *boundin } QTextLayout::FormatRange range; - range.start = paragraphs.back().length(); - range.length = newText.length(); + range.start = paragraphs.back().size(); + range.length = newText.size(); range.format.setFont(font); range.format.setTextOutline(p->pen()); range.format.setForeground(p->brush()); diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index e88e83b..09da1a3 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -195,7 +195,7 @@ struct QSvgAttributes QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHandler *handler) { - for (int i = 0; i < xmlAttributes.count(); ++i) { + for (int i = 0; i < xmlAttributes.size(); ++i) { const QXmlStreamAttribute &attribute = xmlAttributes.at(i); QStringView name = attribute.qualifiedName(); if (name.isEmpty()) @@ -252,8 +252,8 @@ QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHa break; case 's': - if (name.length() > 5 && name.mid(1, 5) == QLatin1String("troke")) { - QStringView strokeRef = name.mid(6, name.length() - 6); + if (name.size() > 5 && name.mid(1, 5) == QLatin1String("troke")) { + QStringView strokeRef = name.mid(6, name.size() - 6); if (strokeRef.isEmpty()) stroke = value; else if (strokeRef == QLatin1String("-dasharray")) @@ -306,7 +306,7 @@ QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHa QStringView style = xmlAttributes.value(QLatin1String("style")); if (!style.isEmpty()) { handler->parseCSStoXMLAttrs(style.toString(), &m_cssAttributes); - for (int j = 0; j < m_cssAttributes.count(); ++j) { + for (int j = 0; j < m_cssAttributes.size(); ++j) { const QSvgCssAttribute &attribute = m_cssAttributes.at(j); QStringView name = attribute.name; QStringView value = attribute.value; @@ -360,8 +360,8 @@ QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHa break; case 's': - if (name.length() > 5 && name.mid(1, 5) == QLatin1String("troke")) { - QStringView strokeRef = name.mid(6, name.length() - 6); + if (name.size() > 5 && name.mid(1, 5) == QLatin1String("troke")) { + QStringView strokeRef = name.mid(6, name.size() - 6); if (strokeRef.isEmpty()) stroke = value; else if (strokeRef == QLatin1String("-dasharray")) @@ -657,7 +657,7 @@ static qreal toDouble(QStringView str, bool *ok = NULL) const QChar *c = str.constData(); qreal res = (c == nullptr ? qreal{} : toDouble(c)); if (ok) - *ok = (c == (str.constData() + str.length())); + *ok = (c == (str.constData() + str.size())); return res; } @@ -798,7 +798,7 @@ static bool resolveColor(QStringView colorStr, QColor &color, QSvgHandler *handl // #rrggbb is very very common, so let's tackle it here // rather than falling back to QColor QRgb rgb; - bool ok = qsvg_get_hex_rgb(colorStrTr.constData(), colorStrTr.length(), &rgb); + bool ok = qsvg_get_hex_rgb(colorStrTr.constData(), colorStrTr.size(), &rgb); if (ok) color.setRgb(rgb); return ok; @@ -808,7 +808,7 @@ static bool resolveColor(QStringView colorStr, QColor &color, QSvgHandler *handl case 'r': { // starts with "rgb(", ends with ")" and consists of at least 7 characters "rgb(,,)" - if (colorStrTr.length() >= 7 && colorStrTr.at(colorStrTr.length() - 1) == QLatin1Char(')') + if (colorStrTr.size() >= 7 && colorStrTr.at(colorStrTr.size() - 1) == QLatin1Char(')') && colorStrTr.mid(0, 4) == QLatin1String("rgb(")) { const QChar *s = colorStrTr.constData() + 4; QList compo = parseNumbersList(s); @@ -997,8 +997,8 @@ static void parseBrush(QSvgNode *node, //fill attribute handling if ((!attributes.fill.isEmpty()) && (attributes.fill != QT_INHERIT) ) { - if (attributes.fill.length() > 3 && attributes.fill.mid(0, 3) == QLatin1String("url")) { - QString value = attributes.fill.mid(3, attributes.fill.length() - 3).toString(); + if (attributes.fill.size() > 3 && attributes.fill.mid(0, 3) == QLatin1String("url")) { + QString value = attributes.fill.mid(3, attributes.fill.size() - 3).toString(); QSvgStyleProperty *style = styleFromUrl(node, value); if (style) { if (style->type() == QSvgStyleProperty::SOLID_COLOR || style->type() == QSvgStyleProperty::GRADIENT) @@ -1029,7 +1029,7 @@ static QTransform parseTransformationMatrix(QStringView value) QTransform matrix; const QChar *str = value.constData(); - const QChar *end = str + value.length(); + const QChar *end = str + value.size(); while (str < end) { if (str->isSpace() || *str == QLatin1Char(',')) { @@ -1108,22 +1108,22 @@ static QTransform parseTransformationMatrix(QStringView value) ++str; if(state == Matrix) { - if(points.count() != 6) + if(points.size() != 6) goto error; matrix = QTransform(points[0], points[1], points[2], points[3], points[4], points[5]) * matrix; } else if (state == Translate) { - if (points.count() == 1) + if (points.size() == 1) matrix.translate(points[0], 0); - else if (points.count() == 2) + else if (points.size() == 2) matrix.translate(points[0], points[1]); else goto error; } else if (state == Rotate) { - if(points.count() == 1) { + if(points.size() == 1) { matrix.rotate(points[0]); - } else if (points.count() == 3) { + } else if (points.size() == 3) { matrix.translate(points[1], points[2]); matrix.rotate(points[0]); matrix.translate(-points[1], -points[2]); @@ -1131,19 +1131,19 @@ static QTransform parseTransformationMatrix(QStringView value) goto error; } } else if (state == Scale) { - if (points.count() < 1 || points.count() > 2) + if (points.size() < 1 || points.size() > 2) goto error; qreal sx = points[0]; qreal sy = sx; - if(points.count() == 2) + if(points.size() == 2) sy = points[1]; matrix.scale(sx, sy); } else if (state == SkewX) { - if (points.count() != 1) + if (points.size() != 1) goto error; matrix.shear(qTan(qDegreesToRadians(points[0])), 0); } else if (state == SkewY) { - if (points.count() != 1) + if (points.size() != 1) goto error; matrix.shear(0, qTan(qDegreesToRadians(points[0]))); } @@ -1166,8 +1166,8 @@ static void parsePen(QSvgNode *node, //stroke attribute handling if ((!attributes.stroke.isEmpty()) && (attributes.stroke != QT_INHERIT) ) { - if (attributes.stroke.length() > 3 && attributes.stroke.mid(0, 3) == QLatin1String("url")) { - QString value = attributes.stroke.mid(3, attributes.stroke.length() - 3).toString(); + if (attributes.stroke.size() > 3 && attributes.stroke.mid(0, 3) == QLatin1String("url")) { + QString value = attributes.stroke.mid(3, attributes.stroke.size() - 3).toString(); QSvgStyleProperty *style = styleFromUrl(node, value); if (style) { if (style->type() == QSvgStyleProperty::SOLID_COLOR || style->type() == QSvgStyleProperty::GRADIENT) @@ -1314,7 +1314,7 @@ static void parseFont(QSvgNode *node, if (!attributes.fontFamily.isEmpty() && attributes.fontFamily != QT_INHERIT) { QString family = attributes.fontFamily.toString().trimmed(); if (family.at(0) == QLatin1Char('\'') || family.at(0) == QLatin1Char('\"')) - family = family.mid(1, family.length() - 2); + family = family.mid(1, family.size() - 2); fontStyle->setFamily(family); } @@ -1584,7 +1584,7 @@ static bool parsePathDataFast(QStringView dataStr, QPainterPath &path) if (pathElem == QLatin1Char('z') || pathElem == QLatin1Char('Z')) arg.append(0);//dummy const qreal *num = arg.constData(); - int count = arg.count(); + int count = arg.size(); while (ok && count > 0) { qreal offsetX = x; // correction offsets qreal offsetY = y; // for relative commands @@ -1898,13 +1898,13 @@ static bool parseStyle(QSvgNode *node, static void parseCSStoXMLAttrs(const QList &declarations, QXmlStreamAttributes &attributes) { - for (int i = 0; i < declarations.count(); ++i) { + for (int i = 0; i < declarations.size(); ++i) { const QCss::Declaration &decl = declarations.at(i); if (decl.d->property.isEmpty()) continue; QCss::Value val = decl.d->values.first(); QString valueStr; - const int valCount = decl.d->values.count(); + const int valCount = decl.d->values.size(); if (valCount != 1) { for (int i = 0; i < valCount; ++i) { valueStr += decl.d->values[i].toString(); @@ -1921,9 +1921,9 @@ static void parseCSStoXMLAttrs(const QList &declarations, QStringList lst = val.variant.toStringList(); valueStr.append(lst.at(0)); valueStr.append(QLatin1Char('(')); - for (int i = 1; i < lst.count(); ++i) { + for (int i = 1; i < lst.size(); ++i) { valueStr.append(lst.at(i)); - if ((i +1) < lst.count()) + if ((i +1) < lst.size()) valueStr.append(QLatin1Char(',')); } valueStr.append(QLatin1Char(')')); @@ -2044,7 +2044,7 @@ static bool parseCoreNode(QSvgNode *node, QStringList fonts; QString xmlClassStr; - for (int i = 0; i < attributes.count(); ++i) { + for (int i = 0; i < attributes.size(); ++i) { const QXmlStreamAttribute &attribute = attributes.at(i); QStringView name = attribute.qualifiedName(); if (name.isEmpty()) @@ -2361,7 +2361,7 @@ static bool parseAnimateColorNode(QSvgNode *parent, colors.append(endColor); } else { QStringList str = valuesStr.split(QLatin1Char(';')); - colors.reserve(str.count()); + colors.reserve(str.size()); QStringList::const_iterator itr; for (itr = str.constBegin(); itr != str.constEnd(); ++itr) { QColor color; @@ -2465,7 +2465,7 @@ static bool parseAnimateTransformNode(QSvgNode *parent, ++s; } } - if (vals.count() % 3 != 0) + if (vals.size() % 3 != 0) return false; bool ok = true; @@ -2958,7 +2958,7 @@ static QSvgNode *createPolygonNode(QSvgNode *parent, //same QPolygon parsing is in createPolylineNode const QChar *s = pointsStr.constData(); QList points = parseNumbersList(s); - QPolygonF poly(points.count()/2); + QPolygonF poly(points.size()/2); for (int i = 0; i < poly.size(); ++i) poly[i] = QPointF(points.at(2 * i), points.at(2 * i + 1)); QSvgNode *polygon = new QSvgPolygon(parent, poly); @@ -2974,7 +2974,7 @@ static QSvgNode *createPolylineNode(QSvgNode *parent, //same QPolygon parsing is in createPolygonNode const QChar *s = pointsStr.constData(); QList points = parseNumbersList(s); - QPolygonF poly(points.count()/2); + QPolygonF poly(points.size()/2); for (int i = 0; i < poly.size(); ++i) poly[i] = QPointF(points.at(2 * i), points.at(2 * i + 1)); @@ -3140,12 +3140,12 @@ static bool parseStopNode(QSvgStyleProperty *parent, cssNode.ptr = &anim; QList decls = handler->selector()->declarationsForNode(cssNode); - for (int i = 0; i < decls.count(); ++i) { + for (int i = 0; i < decls.size(); ++i) { const QCss::Declaration &decl = decls.at(i); if (decl.d->property.isEmpty()) continue; - if (decl.d->values.count() != 1) + if (decl.d->values.size() != 1) continue; QCss::Value val = decl.d->values.first(); QString valueStr = val.toString(); @@ -3253,7 +3253,7 @@ static QSvgNode *createSvgNode(QSvgNode *parent, viewBoxStr = viewBoxStr.replace(QLatin1Char('\t'), QLatin1Char(',')); viewBoxValues = viewBoxStr.split(QLatin1Char(','), Qt::SkipEmptyParts); } - if (viewBoxValues.count() == 4) { + if (viewBoxValues.size() == 4) { QString xStr = viewBoxValues.at(0).trimmed(); QString yStr = viewBoxValues.at(1).trimmed(); QString widthStr = viewBoxValues.at(2).trimmed(); @@ -3409,7 +3409,7 @@ static FactoryMethod findGroupFactory(const QString &name) if (name.isEmpty()) return 0; - QStringView ref = QStringView{name}.mid(1, name.length() - 1); + QStringView ref = QStringView{name}.mid(1, name.size() - 1); switch (name.at(0).unicode()) { case 'd': if (ref == QLatin1String("efs")) return createDefsNode; @@ -3432,7 +3432,7 @@ static FactoryMethod findGraphicsFactory(const QString &name) if (name.isEmpty()) return 0; - QStringView ref = QStringView{name}.mid(1, name.length() - 1); + QStringView ref = QStringView{name}.mid(1, name.size() - 1); switch (name.at(0).unicode()) { case 'a': if (ref == QLatin1String("nimation")) return createAnimationNode; @@ -3481,7 +3481,7 @@ static ParseMethod findUtilFactory(const QString &name) if (name.isEmpty()) return 0; - QStringView ref = QStringView{name}.mid(1, name.length() - 1); + QStringView ref = QStringView{name}.mid(1, name.size() - 1); switch (name.at(0).unicode()) { case 'a': if (ref.isEmpty()) return parseAnchorNode; @@ -3533,7 +3533,7 @@ static StyleFactoryMethod findStyleFactoryMethod(const QString &name) if (name.isEmpty()) return 0; - QStringView ref = QStringView{name}.mid(1, name.length() - 1); + QStringView ref = QStringView{name}.mid(1, name.size() - 1); switch (name.at(0).unicode()) { case 'f': if (ref == QLatin1String("ont")) return createFontNode; @@ -3562,7 +3562,7 @@ static StyleParseMethod findStyleUtilFactoryMethod(const QString &name) if (name.isEmpty()) return 0; - QStringView ref = QStringView{name}.mid(1, name.length() - 1); + QStringView ref = QStringView{name}.mid(1, name.size() - 1); switch (name.at(0).unicode()) { case 'f': if (ref == QLatin1String("ont-face")) return parseFontFaceNode; @@ -3966,7 +3966,7 @@ void QSvgHandler::pushColor(const QColor &color) void QSvgHandler::pushColorCopy() { - if (m_colorTagCount.count()) + if (m_colorTagCount.size()) ++m_colorTagCount.top(); else pushColor(Qt::black); @@ -3974,7 +3974,7 @@ void QSvgHandler::pushColorCopy() void QSvgHandler::popColor() { - if (m_colorTagCount.count()) { + if (m_colorTagCount.size()) { if (!--m_colorTagCount.top()) { m_colorStack.pop(); m_colorTagCount.pop(); diff --git a/src/svg/qsvgstructure.cpp b/src/svg/qsvgstructure.cpp index 38ac822..5ab1978 100644 --- a/src/svg/qsvgstructure.cpp +++ b/src/svg/qsvgstructure.cpp @@ -218,12 +218,12 @@ inline static bool isSupportedSvgFeature(const QString &str) "http://www.w3.org/Graphics/SVG/feature/1.2/#ExternalResourcesRequiredAttribute" }; - if (str.length() <= MAX_WORD_LENGTH && str.length() >= MIN_WORD_LENGTH) { + if (str.size() <= MAX_WORD_LENGTH && str.size() >= MIN_WORD_LENGTH) { const char16_t unicode44 = str.at(44).unicode(); const char16_t unicode45 = str.at(45).unicode(); if (unicode44 >= sizeof(asso_values) || unicode45 >= sizeof(asso_values)) return false; - const int key = str.length() + const int key = str.size() + asso_values[unicode45] + asso_values[unicode44]; if (key <= MAX_HASH_VALUE && key >= 0) diff --git a/src/svg/qsvgstyle.cpp b/src/svg/qsvgstyle.cpp index 8b20926..604b4e4 100644 --- a/src/svg/qsvgstyle.cpp +++ b/src/svg/qsvgstyle.cpp @@ -630,8 +630,8 @@ void QSvgAnimateTransform::setArgs(TransformType type, Additive additive, const m_type = type; m_args = args; m_additive = additive; - Q_ASSERT(!(args.count()%3)); - m_count = args.count() / 3; + Q_ASSERT(!(args.size()%3)); + m_count = args.size() / 3; } void QSvgAnimateTransform::apply(QPainter *p, const QSvgNode *node, QSvgExtraStates &) @@ -836,7 +836,7 @@ void QSvgAnimateColor::apply(QPainter *p, const QSvgNode *node, QSvgExtraStates percentOfAnimation -= ((int)percentOfAnimation); } - qreal currentPosition = percentOfAnimation * (m_colors.count() - 1); + qreal currentPosition = percentOfAnimation * (m_colors.size() - 1); int startElem = qFloor(currentPosition); int endElem = qCeil(currentPosition); -- cgit v1.2.1