summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Wicking <paul.wicking@qt.io>2024-04-11 15:46:22 +0200
committerPaul Wicking <paul.wicking@qt.io>2024-04-18 09:41:57 +0200
commita3d461d80d55258fa89ed3800c301ad8be6f9119 (patch)
tree9971d837e4e18ea6a821ea04a14ef9ff3bbc2857
parentd282992eceee23007813e353d80b8e19fc94fcd1 (diff)
QDoc: Extract method from Tree::resolveTargets (1/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's responsible for ensuring that each unique PageNode is stored in the `m_pageNodesByTitle` under its title and delegate to the new method from the call site. As part of the extraction, replace a manual loop with a call to the std::any_of algorithm. Task-number: QTBUG-122261 Change-Id: I391da5bc38d64e6a737a0c77874c9683cce50f48 Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
-rw-r--r--src/qdoc/qdoc/src/qdoc/tree.cpp50
-rw-r--r--src/qdoc/qdoc/src/qdoc/tree.h2
2 files changed, 30 insertions, 22 deletions
diff --git a/src/qdoc/qdoc/src/qdoc/tree.cpp b/src/qdoc/qdoc/src/qdoc/tree.cpp
index 91fa5fa72..fd4ecbf0b 100644
--- a/src/qdoc/qdoc/src/qdoc/tree.cpp
+++ b/src/qdoc/qdoc/src/qdoc/tree.cpp
@@ -755,28 +755,7 @@ void Tree::insertTarget(const QString &name, const QString &title, TargetRec::Ta
void Tree::resolveTargets(Aggregate *root)
{
for (auto *child : root->childNodes()) {
- if (child->isTextPageNode()) {
- auto *node = static_cast<PageNode *>(child);
- QString key = node->title();
- if (!key.isEmpty()) {
- if (key.contains(QChar(' ')))
- key = Utilities::asAsciiPrintable(key);
- QList<PageNode *> nodes = m_pageNodesByTitle.values(key);
- bool alreadyThere = false;
- if (!nodes.empty()) {
- for (const auto &node_ : nodes) {
- if (node_->isExternalPage()) {
- if (node->name() == node_->name()) {
- alreadyThere = true;
- break;
- }
- }
- }
- }
- if (!alreadyThere)
- m_pageNodesByTitle.insert(key, node);
- }
- }
+ addToPageNodeByTitleMap(child);
if (child->doc().hasTableOfContents()) {
const QList<Atom *> &toc = child->doc().tableOfContents();
@@ -822,6 +801,33 @@ void Tree::resolveTargets(Aggregate *root)
}
/*!
+ \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.
+ */
+void Tree::addToPageNodeByTitleMap(Node *node) {
+ if (!node || !node->isTextPageNode())
+ return;
+
+ auto *pageNode = static_cast<PageNode *>(node);
+ QString key = pageNode->title();
+ if (key.isEmpty())
+ return;
+
+ if (key.contains(QChar(' ')))
+ key = Utilities::asAsciiPrintable(key);
+ const QList<PageNode *> nodes = m_pageNodesByTitle.values(key);
+
+ bool alreadyThere = std::any_of(nodes.cbegin(), nodes.cend(), [&](const auto &knownNode) {
+ return knownNode->isExternalPage() && knownNode->name() == pageNode->name();
+ });
+
+ if (!alreadyThere)
+ m_pageNodesByTitle.insert(key, pageNode);
+}
+
+/*!
Searches for a \a target anchor, matching the given \a genus, and returns
the associated TargetRec instance.
*/
diff --git a/src/qdoc/qdoc/src/qdoc/tree.h b/src/qdoc/qdoc/src/qdoc/tree.h
index 649040ecb..083ba42fb 100644
--- a/src/qdoc/qdoc/src/qdoc/tree.h
+++ b/src/qdoc/qdoc/src/qdoc/tree.h
@@ -101,6 +101,8 @@ private: // The rest of the class is private.
void insertTarget(const QString &name, const QString &title, TargetRec::TargetType type,
Node *node, int priority);
void resolveTargets(Aggregate *root);
+ void addToPageNodeByTitleMap(Node *node);
+
const TargetRec *findUnambiguousTarget(const QString &target, Node::Genus genus) const;
[[nodiscard]] const PageNode *findPageNodeByTitle(const QString &title) const;