summaryrefslogtreecommitdiff
path: root/src/qdoc/cppcodemarker.cpp
diff options
context:
space:
mode:
authorPaul Wicking <paul.wicking@qt.io>2019-08-11 20:11:48 +0200
committerPaul Wicking <paul.wicking@qt.io>2019-09-28 07:47:54 +0200
commitbe8ffa4e910a3413bd3df907d8e15514691a0342 (patch)
tree2be24fb7cadbbe17fb8a2a10fdbddd8ff113b3bb /src/qdoc/cppcodemarker.cpp
parent72a5776421948ab82bcfa4d744a027cadcd7267e (diff)
downloadqttools-be8ffa4e910a3413bd3df907d8e15514691a0342.tar.gz
QDoc: Use range-based for instead of foreach
This change replaces the use of foreach with range-based for throughout QDoc. It also ensures that the loop body doesn't modify the container being iterated over, by: - Making a const copy when the container is a member variable or the result of an expression, and iterating over that copy. This is the preferred approach. - Using qAsConst() when the container is a (static) member variable or local to the method and not const. The latter is typical where the collection is sorted immediately before the loop. In two cases (doc.cpp), replaced Q_FOREACH + delete with qDeleteAll. In two cases (cppcodeparser.cpp), the range declaration is replaced within the loop statement. These rewrites express the behavior clearer than the original code. In two cases (codeparser.cpp), use a range-based for instead of a while loop where the condition is an iterator, for more expressive code. Finally, use the auto keyword where appropriate and improve a few variable names. QDoc warning count and generated output is unchanged after this refactoring. Change-Id: I64f02d24dca373a3a41402d535382e2c526bb55e Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/qdoc/cppcodemarker.cpp')
-rw-r--r--src/qdoc/cppcodemarker.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/qdoc/cppcodemarker.cpp b/src/qdoc/cppcodemarker.cpp
index 26a43794d..a59654cfa 100644
--- a/src/qdoc/cppcodemarker.cpp
+++ b/src/qdoc/cppcodemarker.cpp
@@ -245,11 +245,12 @@ QString CppCodeMarker::markedUpSynopsis(const Node *node,
QStringList documentedItems = enume->doc().enumItemNames();
if (documentedItems.isEmpty()) {
- foreach (const EnumItem &item, enume->items())
+ const auto enumItems = enume->items();
+ for (const auto &item : enumItems)
documentedItems << item.name();
}
- QStringList omitItems = enume->doc().omitEnumItemNames();
- foreach (const QString &item, omitItems)
+ const QStringList omitItems = enume->doc().omitEnumItemNames();
+ for (const auto &item : omitItems)
documentedItems.removeAll(item);
if (documentedItems.size() <= MaxEnumValues) {