diff options
author | Paul Wicking <paul.wicking@qt.io> | 2024-04-15 11:33:28 +0200 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2024-04-18 09:42:03 +0200 |
commit | 25f2bb922188e759cd6beb11b3b80d8772105574 (patch) | |
tree | 30fc7e45aa9ca2deb4ad53d1959808e166cb5e9a /src/qdoc/qdoc/src/qdoc/tree.cpp | |
parent | 58bf8b59016e1eb00acbe1a84575611850db5075 (diff) |
QDoc: Extract method from Tree::resolveTargets (4/4)
`Tree::resolveTargets` is responsible for ensuring the maps
`m_nodesByTargetRef` and `m_nodesByTargetTitle` are correct. The
implementation details for the various tasks clutter reading the
algorithm.
Extract the code responsible for adding targets (defined with QDoc's
\target command) associated with the Node being processed to the maps.
Task-number: QTBUG-122261
Change-Id: If0ab471003267ab41a229ac4bf81e0eae882ad81
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/qdoc/qdoc/src/qdoc/tree.cpp')
-rw-r--r-- | src/qdoc/qdoc/src/qdoc/tree.cpp | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/qdoc/qdoc/src/qdoc/tree.cpp b/src/qdoc/qdoc/src/qdoc/tree.cpp index 18f836062..d1b518fd2 100644 --- a/src/qdoc/qdoc/src/qdoc/tree.cpp +++ b/src/qdoc/qdoc/src/qdoc/tree.cpp @@ -751,6 +751,12 @@ void Tree::insertTarget(const QString &name, const QString &title, TargetRec::Ta } /*! + \internal + + \a root is the root node of the tree to resolve targets for. This function + traverses the tree starting from the root node and processes each child + node. If the child node is an aggregate node, this function is called + recursively on the child node. */ void Tree::resolveTargets(Aggregate *root) { @@ -758,20 +764,8 @@ void Tree::resolveTargets(Aggregate *root) addToPageNodeByTitleMap(child); populateTocSectionTargetMap(child); addKeywordsToTargetMaps(child); + addTargetsToTargetMap(child); - if (child->doc().hasTargets()) { - const QList<Atom *> &targets = child->doc().targets(); - for (Atom *i : targets) { - QString ref = refForAtom(i); - QString title = i->string(); - if (!ref.isEmpty() && !title.isEmpty()) { - QString key = Utilities::asAsciiPrintable(title); - auto *target = new TargetRec(ref, TargetRec::Target, child, 2); - m_nodesByTargetRef.insert(key, target); - m_nodesByTargetTitle.insert(title, target); - } - } - } if (child->isAggregate()) resolveTargets(static_cast<Aggregate *>(child)); } @@ -780,6 +774,27 @@ void Tree::resolveTargets(Aggregate *root) /*! \internal + Updates the target maps for targets associated with the given \a node. + */ +void Tree::addTargetsToTargetMap(Node *node) { + if (!node || !node->doc().hasTargets()) + return; + + for (Atom *i : std::as_const(node->doc().targets())) { + const QString ref = refForAtom(i); + const QString title = i->string(); + if (!ref.isEmpty() && !title.isEmpty()) { + QString key = Utilities::asAsciiPrintable(title); + auto *target = new TargetRec(ref, TargetRec::Target, node, 2); + m_nodesByTargetRef.insert(key, target); + m_nodesByTargetTitle.insert(title, target); + } + } +} + +/*! + \internal + Updates the target maps for keywords associated with the given \a node. */ void Tree::addKeywordsToTargetMaps(Node *node) { |