diff options
author | Paul Wicking <paul.wicking@qt.io> | 2024-04-12 13:40:53 +0200 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2024-04-18 09:41:59 +0200 |
commit | 59b69f19c2f5379c973076bb635dc2d16f448026 (patch) | |
tree | 00c6dd39f7839b81088e7e98b60d23869b0afb6f | |
parent | a3d461d80d55258fa89ed3800c301ad8be6f9119 (diff) |
QDoc: Extract method from Tree::resolveTargets (2/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 is responsible for populating the maps for
each section in the table of contents of the Node being processed.
Task-number: QTBUG-122261
Change-Id: I72b9698b2b848bd58eade95981aae2144b536fdc
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
-rw-r--r-- | src/qdoc/qdoc/src/qdoc/tree.cpp | 37 | ||||
-rw-r--r-- | src/qdoc/qdoc/src/qdoc/tree.h | 1 |
2 files changed, 25 insertions, 13 deletions
diff --git a/src/qdoc/qdoc/src/qdoc/tree.cpp b/src/qdoc/qdoc/src/qdoc/tree.cpp index fd4ecbf0b..258aa14e3 100644 --- a/src/qdoc/qdoc/src/qdoc/tree.cpp +++ b/src/qdoc/qdoc/src/qdoc/tree.cpp @@ -756,20 +756,8 @@ void Tree::resolveTargets(Aggregate *root) { for (auto *child : root->childNodes()) { addToPageNodeByTitleMap(child); + populateTocSectionTargetMap(child); - if (child->doc().hasTableOfContents()) { - const QList<Atom *> &toc = child->doc().tableOfContents(); - for (Atom *i : toc) { - QString ref = refForAtom(i); - QString title = Text::sectionHeading(i).toString(); - if (!ref.isEmpty() && !title.isEmpty()) { - QString key = Utilities::asAsciiPrintable(title); - auto *target = new TargetRec(ref, TargetRec::Contents, child, 3); - m_nodesByTargetRef.insert(key, target); - m_nodesByTargetTitle.insert(title, target); - } - } - } if (child->doc().hasKeywords()) { const QList<Atom *> &keywords = child->doc().keywords(); for (Atom *i : keywords) { @@ -803,6 +791,29 @@ void Tree::resolveTargets(Aggregate *root) /*! \internal + Populates the map of targets for each section in the table of contents for + the given \a node. + */ +void Tree::populateTocSectionTargetMap(Node *node) { + if (!node || !node->doc().hasTableOfContents()) + return; + + for (Atom *atom : std::as_const(node->doc().tableOfContents()) { + const QString &ref = refForAtom(atom); + const QString &title = Text::sectionHeading(atom).toString(); + if (ref.isEmpty() || title.isEmpty()) + continue; + + const QString &key = Utilities::asAsciiPrintable(title); + auto *target = new TargetRec(ref, TargetRec::Contents, node, 3); + m_nodesByTargetRef.insert(key, target); + m_nodesByTargetTitle.insert(title, target); + } +} + +/*! + \internal + Checks if the \a node's title is registered in the page nodes by title map. If not, it stores the page node in the map. */ diff --git a/src/qdoc/qdoc/src/qdoc/tree.h b/src/qdoc/qdoc/src/qdoc/tree.h index 083ba42fb..d59fe86e8 100644 --- a/src/qdoc/qdoc/src/qdoc/tree.h +++ b/src/qdoc/qdoc/src/qdoc/tree.h @@ -102,6 +102,7 @@ private: // The rest of the class is private. Node *node, int priority); void resolveTargets(Aggregate *root); void addToPageNodeByTitleMap(Node *node); + void populateTocSectionTargetMap(Node *node); const TargetRec *findUnambiguousTarget(const QString &target, Node::Genus genus) const; [[nodiscard]] const PageNode *findPageNodeByTitle(const QString &title) const; |