summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Wicking <paul.wicking@qt.io>2024-04-17 20:51:04 +0200
committerPaul Wicking <paul.wicking@qt.io>2024-04-18 09:42:01 +0200
commit58bf8b59016e1eb00acbe1a84575611850db5075 (patch)
tree6422bdad38a27d394914dac2e2162f80e4bdbb5c
parent59b69f19c2f5379c973076bb635dc2d16f448026 (diff)
QDoc: Extract method from Tree::resolveTargets (3/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 that adds keywords (defined by QDoc's \keyword command) associated with the Node being processed to the maps. Task-number: QTBUG-122261 Change-Id: I5d11b8d64680046f57468871b682868318be04ac Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
-rw-r--r--src/qdoc/qdoc/src/qdoc/tree.cpp33
-rw-r--r--src/qdoc/qdoc/src/qdoc/tree.h1
2 files changed, 22 insertions, 12 deletions
diff --git a/src/qdoc/qdoc/src/qdoc/tree.cpp b/src/qdoc/qdoc/src/qdoc/tree.cpp
index 258aa14e3..18f836062 100644
--- a/src/qdoc/qdoc/src/qdoc/tree.cpp
+++ b/src/qdoc/qdoc/src/qdoc/tree.cpp
@@ -757,19 +757,8 @@ void Tree::resolveTargets(Aggregate *root)
for (auto *child : root->childNodes()) {
addToPageNodeByTitleMap(child);
populateTocSectionTargetMap(child);
+ addKeywordsToTargetMaps(child);
- if (child->doc().hasKeywords()) {
- const QList<Atom *> &keywords = child->doc().keywords();
- for (Atom *i : keywords) {
- QString ref = refForAtom(i);
- QString title = i->string();
- if (!ref.isEmpty() && !title.isEmpty()) {
- auto *target = new TargetRec(ref, TargetRec::Keyword, child, 1);
- m_nodesByTargetRef.insert(Utilities::asAsciiPrintable(title), target);
- m_nodesByTargetTitle.insert(title, target);
- }
- }
- }
if (child->doc().hasTargets()) {
const QList<Atom *> &targets = child->doc().targets();
for (Atom *i : targets) {
@@ -791,6 +780,26 @@ void Tree::resolveTargets(Aggregate *root)
/*!
\internal
+ Updates the target maps for keywords associated with the given \a node.
+ */
+void Tree::addKeywordsToTargetMaps(Node *node) {
+ if (!node->doc().hasKeywords())
+ return;
+
+ for (Atom *i : std::as_const(node->doc().keywords())) {
+ QString ref = refForAtom(i);
+ QString title = i->string();
+ if (!ref.isEmpty() && !title.isEmpty()) {
+ auto *target = new TargetRec(ref, TargetRec::Keyword, node, 1);
+ m_nodesByTargetRef.insert(Utilities::asAsciiPrintable(title), target);
+ m_nodesByTargetTitle.insert(title, target);
+ }
+ }
+}
+
+/*!
+ \internal
+
Populates the map of targets for each section in the table of contents for
the given \a node.
*/
diff --git a/src/qdoc/qdoc/src/qdoc/tree.h b/src/qdoc/qdoc/src/qdoc/tree.h
index d59fe86e8..9d1248492 100644
--- a/src/qdoc/qdoc/src/qdoc/tree.h
+++ b/src/qdoc/qdoc/src/qdoc/tree.h
@@ -103,6 +103,7 @@ private: // The rest of the class is private.
void resolveTargets(Aggregate *root);
void addToPageNodeByTitleMap(Node *node);
void populateTocSectionTargetMap(Node *node);
+ void addKeywordsToTargetMaps(Node *node);
const TargetRec *findUnambiguousTarget(const QString &target, Node::Genus genus) const;
[[nodiscard]] const PageNode *findPageNodeByTitle(const QString &title) const;