diff options
author | Topi Reinio <topi.reinio@qt.io> | 2022-06-20 11:05:09 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-06-20 17:02:19 +0000 |
commit | 71b65c8154bd10b040be80148a9d10c4392e1ec0 (patch) | |
tree | da0ebdfcab1cfc027b8352774ac75f8c479b353c | |
parent | f1ac16b7b629c0f4300a36ba041658809dcf1a96 (diff) |
qdoc: Always consider section titles as the last resort for linking
This commit amends a8cb221c. There was one more situation where a
section title could mask a more high-priority link target in the same
project.
This happened because in Tree::findNodeForTarget(), we search the
target map first as it's a relatively fast operation. If the target
is found but refers to a section title, delay returning the node as
there may be higher-priority targets in the same tree.
Fixes: QTBUG-104369
Change-Id: Ifecf94fb09b3484dac6d3329b8624d26b3e26a2c
Reviewed-by: Luca Di Sera <luca.disera@qt.io>
(cherry picked from commit f92c4463e63b36cce6c10affadd9817a20e8d1dd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qdoc/tree.cpp | 53 | ||||
-rw-r--r-- | tests/auto/qdoc/generatedoutput/expected_output/autolinking.html | 2 |
2 files changed, 27 insertions, 28 deletions
diff --git a/src/qdoc/tree.cpp b/src/qdoc/tree.cpp index 468b46815..0c0fe6fab 100644 --- a/src/qdoc/tree.cpp +++ b/src/qdoc/tree.cpp @@ -422,12 +422,12 @@ const Node *Tree::findNodeForTarget(const QStringList &path, const QString &targ QString &ref, TargetRec::TargetType *targetType) const { const Node *node = nullptr; + if ((genus == Node::DontCare) || (genus == Node::DOC)) { node = findPageNodeByTitle(path.at(0)); if (node) { if (!target.isEmpty()) { - ref = getRef(target, node); - if (ref.isEmpty()) + if (ref = getRef(target, node); ref.isEmpty()) node = nullptr; } if (node) @@ -435,34 +435,32 @@ const Node *Tree::findNodeForTarget(const QStringList &path, const QString &targ } } - const TargetRec *result = findUnambiguousTarget(path.join(QLatin1String("::")), genus); if (result) { node = result->m_node; ref = result->m_ref; if (!target.isEmpty()) { - ref = getRef(target, node); - if (ref.isEmpty()) + if (ref = getRef(target, node); ref.isEmpty()) node = nullptr; } if (node) { if (targetType) *targetType = result->m_type; - return node; + // Delay returning references to section titles as we + // may find a better match below + if (!targetType || *targetType != TargetRec::Contents) + return node; + else + ref.clear(); } } - const Node *current = start; - if (current == nullptr) - current = root(); - + const Node *current = start ? start : root(); /* If the path contains one or two double colons ("::"), - check first to see if the first two path strings refer - to a QML element. If they do, path[0] will be the QML - module identifier, and path[1] will be the QML type. - If the answer is yes, the reference identifies a QML - type node. + check if the first two path elements refer to a QML type. + If so, path[0] is QML module identifier, and path[1] is + the type. */ int path_idx = 0; if (((genus == Node::QML) || (genus == Node::DontCare)) && (path.size() >= 2) @@ -473,27 +471,28 @@ const Node *Tree::findNodeForTarget(const QStringList &path, const QString &targ if (path.size() == 2) { if (!target.isEmpty()) { ref = getRef(target, current); - if (!ref.isEmpty()) - return current; - return nullptr; - } else - return current; + return (!ref.isEmpty()) ? current : nullptr; + } + return current; } path_idx = 2; } } - while (current != nullptr) { - if (current->isAggregate()) { // Should this be isPageNode() ??? - const Node *node = - matchPathAndTarget(path, path_idx, target, current, flags, genus, ref); - if (node) - return node; + while (current) { + if (current->isAggregate()) { + if (const Node *match = matchPathAndTarget( + path, path_idx, target, current, flags, genus, ref); + match != nullptr) + return match; } current = current->parent(); path_idx = 0; } - return nullptr; + + if (node && result) + ref = result->m_ref; // Restore section title's ref + return node; } /*! diff --git a/tests/auto/qdoc/generatedoutput/expected_output/autolinking.html b/tests/auto/qdoc/generatedoutput/expected_output/autolinking.html index b86a94d61..29bfe5c06 100644 --- a/tests/auto/qdoc/generatedoutput/expected_output/autolinking.html +++ b/tests/auto/qdoc/generatedoutput/expected_output/autolinking.html @@ -18,7 +18,7 @@ <!-- $$$autolinking.html-description --> <div class="descr" id="details"> <h2 id="testqdoc">TestQDoc</h2> -<p>The string <a href="testqdoc.html">TestQDoc</a> links to the C++ namespace unless linking explicitly, <a href="autolinking.html#testqdoc">like this</a>, or <a href="autolinking.html#testqdoc">this</a>. Also,</p> +<p>The string <a href="testqdoc.html">TestQDoc</a> links to the C++ namespace unless linking explicitly, <a href="autolinking.html#testqdoc">like this</a>, or <a href="testqdoc.html">this</a>. Also,</p> <p>Autolinks:</p> <ul> <li><a href="testqdoc-testderived.html">TestQDoc::TestDerived</a></li> |