diff options
author | Paul Wicking <paul.wicking@qt.io> | 2021-04-28 13:36:28 +0200 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2021-05-03 10:05:04 +0200 |
commit | 6f462ac37916d9fc3fae793e040690741845ef62 (patch) | |
tree | 66bc4b997e0b38cd3d2cd86e8787d54672ca38a6 /src/qdoc/cppcodeparser.cpp | |
parent | a1ed48d0d073a8bdd7b5e608982a5bbd9af47af8 (diff) | |
download | qttools-6f462ac37916d9fc3fae793e040690741845ef62.tar.gz |
QDoc: Code cleanup
* Use multiple arguments for QStrings instead of calling
.arg() multiple times.
* Define trivial constructor/destructor '= default' instead of adding
empty implementations.
* Remove unreachable code.
* Prefer ranged-based for loops.
* Initialize with auto from static_cast<>() and new.
* Simplify expressions.
* Prefer "QList::empty()" over "QList::size() > 0".
* Remove unused method.
* Return qsizetype instead of int to avoid narrowing conversion.
* Remove unused include.
* Remove unreachable return statement.
* Prefer raw string literals over escaped regexes.
* Initialize struct members.
* Make variables used as const refs const refs.
* Use std::move instead of passing const ref in ctor.
* Drop redundant 'virtual' from methods marked 'override'.
* Make local copies that arent ever modified const refs to avoid copying.
* Turn for-loop into std::any_of.
* Made single-argument constructor explicit.
* Don't shadow variable names from outer scope if not necessary.
* Remove const at top level that does not improve const correctness.
* Update copyright notice for affected classes.
Task-number: QTBUG-71176
Change-Id: Ia41e5b947b72f594b60d189b6b0ff68587c3afb9
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/qdoc/cppcodeparser.cpp')
-rw-r--r-- | src/qdoc/cppcodeparser.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp index 106e5f75d..cdb3041d4 100644 --- a/src/qdoc/cppcodeparser.cpp +++ b/src/qdoc/cppcodeparser.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the tools applications of the Qt Toolkit. @@ -44,7 +44,6 @@ #include "sharedcommentnode.h" #include <QtCore/qdebug.h> -#include <QtCore/qfile.h> #include <algorithm> @@ -204,7 +203,7 @@ Node *CppCodeParser::processTopicCommand(const Doc &doc, const QString &command, Node::NodeType type = m_nodeTypeMap[command]; QStringList words = arg.first.split(QLatin1Char(' ')); QStringList path; - int idx = 0; + qsizetype idx = 0; Node *node = nullptr; if (type == Node::Variable && words.size() > 1) @@ -231,8 +230,7 @@ Node *CppCodeParser::processTopicCommand(const Doc &doc, const QString &command, if (isWorthWarningAbout(doc)) { doc.location().warning( QStringLiteral("Cannot find '%1' specified with '\\%2' in any header file") - .arg(arg.first) - .arg(command)); + .arg(arg.first, command)); } } else if (node->isAggregate()) { if (type == Node::Namespace) { @@ -416,7 +414,7 @@ void CppCodeParser::processQmlProperties(const Doc &doc, NodeList &nodes, DocLis bool jsProps = isJSPropertyTopic(topic.topic); arg = topic.args; if (splitQmlPropertyArg(arg, type, module, qmlTypeName, property, doc.location())) { - int i = property.indexOf('.'); + qsizetype i = property.indexOf('.'); if (i != -1) group = property.left(i); } @@ -528,17 +526,15 @@ void CppCodeParser::processMetaCommand(const Doc &doc, const QString &command, if (fn->overridesThis().isEmpty() && isWorthWarningAbout(doc)) { doc.location().warning( QStringLiteral("Cannot find base function for '\\%1' in %2()") - .arg(COMMAND_REIMP) - .arg(node->name()), + .arg(COMMAND_REIMP, node->name()), QStringLiteral("The function either doesn't exist in any " "base class with the same signature or it " "exists but isn't virtual.")); } fn->setReimpFlag(); } else { - doc.location().warning(QStringLiteral("Ignored '\\%1' in %2") - .arg(COMMAND_REIMP) - .arg(node->name())); + doc.location().warning( + QStringLiteral("Ignored '\\%1' in %2").arg(COMMAND_REIMP, node->name())); } } } else if (command == COMMAND_RELATES) { @@ -705,12 +701,12 @@ FunctionNode *CppCodeParser::parseOtherFuncArg(const QString &topic, const Locat QString funcName; QString returnType; - int leftParen = funcArg.indexOf(QChar('(')); + qsizetype leftParen = funcArg.indexOf(QChar('(')); if (leftParen > 0) funcName = funcArg.left(leftParen); else funcName = funcArg; - int firstBlank = funcName.indexOf(QChar(' ')); + qsizetype firstBlank = funcName.indexOf(QChar(' ')); if (firstBlank > 0) { returnType = funcName.left(firstBlank); funcName = funcName.right(funcName.length() - firstBlank - 1); @@ -782,7 +778,7 @@ FunctionNode *CppCodeParser::parseMacroArg(const Location &location, const QStri QString params; if (leftParenSplit.size() > 1) { const QString &afterParen = leftParenSplit.at(1); - int rightParen = afterParen.indexOf(')'); + qsizetype rightParen = afterParen.indexOf(')'); if (rightParen >= 0) params = afterParen.left(rightParen); } @@ -856,7 +852,7 @@ void CppCodeParser::setExampleFileLists(ExampleNode *en) QLatin1String("*.qrc *.pro *.qmlproject *.pyproject CMakeLists.txt qmldir")); } - const int pathLen = exampleDir.path().size() - en->name().size(); + const qsizetype pathLen = exampleDir.path().size() - en->name().size(); for (auto &file : exampleFiles) file = file.mid(pathLen); for (auto &file : imageFiles) @@ -1006,7 +1002,7 @@ bool CppCodeParser::hasTooManyTopics(const Doc &doc) const for (const auto &t : topicCommandsUsed) topicList += QLatin1String(" \\") + t + QLatin1Char(','); topicList[topicList.lastIndexOf(',')] = '.'; - int i = topicList.lastIndexOf(','); + qsizetype i = topicList.lastIndexOf(','); Q_ASSERT(i >= 0); // we had at least two commas topicList[i] = ' '; topicList.insert(i + 1, "and"); |