Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdocdatabase.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#include "qdocdatabase.h"
5
6#include "aggregate.h"
7#include "atom.h"
9#include "functionnode.h"
10#include "generator.h"
11#include "genustypes.h"
12#include "qdocindexfiles.h"
13#include "qdoclogging.h"
15#include "qmltypenode.h"
16#include "tree.h"
17#include "utilities.h"
18
19#include <QtCore/qregularexpression.h>
20#include <stack>
21
22QT_BEGIN_NAMESPACE
23
24using namespace Qt::StringLiterals;
26
27/*!
28 \class QDocForest
29
30 A class representing a forest of Tree objects.
31
32 This private class manages a collection of Tree objects (a
33 forest) for the singleton QDocDatabase object. It is only
34 accessed by that singleton QDocDatabase object, which is a
35 friend. Each tree in the forest is an instance of class
36 Tree, which is a mostly private class. Both QDocForest and
37 QDocDatabase are friends of Tree and have full access.
38
39 There are two kinds of trees in the forest, differing not
40 in structure but in use. One Tree is the primary tree. It
41 is the tree representing the module being documented. All
42 the other trees in the forest are called index trees. Each
43 one represents the contents of the index file for one of
44 the modules the current module must be able to link to.
45
46 The instances of subclasses of Node in the primary tree
47 will contain documentation in an instance of Doc. The
48 index trees contain no documentation, and each Node in
49 an index tree is marked as an index node.
50
51 Each tree is named with the name of its module.
52
53 The search order is created by searchOrder(), if it has
54 not already been created. The search order and module
55 names arrays have parallel structure, i.e. modulNames_[i]
56 is the module name of the Tree at searchOrder_[i].
57
58 The primary tree is always the first tree in the search
59 order. i.e., when the database is searched, the primary
60 tree is always searched first, unless a specific tree is
61 being searched.
62 */
63
64/*!
65 Destroys the qdoc forest. This requires deleting
66 each Tree in the forest. Note that the forest has
67 been transferred into the search order array, so
68 what is really being used to destroy the forest
69 is the search order array.
70 */
71QDocForest::~QDocForest()
72{
73 for (auto *entry : m_searchOrder)
74 delete entry;
75 m_forest.clear();
76 m_searchOrder.clear();
77 m_indexSearchOrder.clear();
78 m_moduleNames.clear();
79 m_primaryTree = nullptr;
80}
81
82/*!
83 Initializes the forest prior to a traversal and
84 returns a pointer to the primary tree. If the
85 forest is empty, it returns \nullptr.
86 */
87Tree *QDocForest::firstTree()
88{
89 m_currentIndex = 0;
90 return (!searchOrder().isEmpty() ? searchOrder()[0] : nullptr);
91}
92
93/*!
94 Increments the forest's current tree index. If the current
95 tree index is still within the forest, the function returns
96 the pointer to the current tree. Otherwise it returns \nullptr.
97 */
98Tree *QDocForest::nextTree()
99{
100 ++m_currentIndex;
101 return (m_currentIndex < searchOrder().size() ? searchOrder()[m_currentIndex] : nullptr);
102}
103
104/*!
105 \fn Tree *QDocForest::primaryTree()
106
107 Returns the pointer to the primary tree.
108 */
109
110/*!
111 Finds the tree for module \a t in the forest and
112 sets the primary tree to be that tree. After the
113 primary tree is set, that tree is removed from the
114 forest.
115
116 \node It gets re-inserted into the forest after the
117 search order is built.
118 */
119void QDocForest::setPrimaryTree(const QString &t)
120{
121 QString T = t.toLower();
122 m_primaryTree = findTree(T);
123 m_forest.remove(T);
124 if (m_primaryTree == nullptr)
125 qCCritical(lcQdoc) << "Error: Could not set primary tree to" << t;
126}
127
128/*!
129 If the search order array is empty, create the search order.
130 If the search order array is not empty, do nothing.
131 */
132void QDocForest::setSearchOrder(const QStringList &t)
133{
134 if (!m_searchOrder.isEmpty())
135 return;
136
137 /* Allocate space for the search order. */
138 m_searchOrder.reserve(m_forest.size() + 1);
139 m_searchOrder.clear();
140 m_moduleNames.reserve(m_forest.size() + 1);
141 m_moduleNames.clear();
142
143 /* The primary tree is always first in the search order. */
144 QString primaryName = primaryTree()->physicalModuleName();
145 m_searchOrder.append(m_primaryTree);
146 m_moduleNames.append(primaryName);
147 m_forest.remove(primaryName);
148
149 for (const QString &m : t) {
150 if (primaryName != m) {
151 auto it = m_forest.find(m);
152 if (it != m_forest.end()) {
153 m_searchOrder.append(it.value());
154 m_moduleNames.append(m);
155 m_forest.remove(m);
156 }
157 }
158 }
159 /*
160 If any trees remain in the forest, just add them
161 to the search order sequentially, because we don't
162 know any better at this point.
163 */
164 if (!m_forest.isEmpty()) {
165 for (auto it = m_forest.begin(); it != m_forest.end(); ++it) {
166 m_searchOrder.append(it.value());
167 m_moduleNames.append(it.key());
168 }
169 m_forest.clear();
170 }
171
172 /*
173 Rebuild the forest after constructing the search order.
174 It was destroyed during construction of the search order,
175 but it is needed for module-specific searches.
176
177 Note that this loop also inserts the primary tree into the
178 forrest. That is a requirement.
179 */
180 for (int i = 0; i < m_searchOrder.size(); ++i) {
181 if (!m_forest.contains(m_moduleNames.at(i))) {
182 m_forest.insert(m_moduleNames.at(i), m_searchOrder.at(i));
183 }
184 }
185}
186
187/*!
188 Returns an ordered array of Tree pointers that represents
189 the order in which the trees should be searched. The first
190 Tree in the array is the tree for the current module, i.e.
191 the module for which qdoc is generating documentation.
192
193 The other Tree pointers in the array represent the index
194 files that were loaded in preparation for generating this
195 module's documentation. Each Tree pointer represents one
196 index file. The index file Tree points have been ordered
197 heuristically to, hopefully, minimize searching. Thr order
198 will probably be changed.
199
200 If the search order array is empty, this function calls
201 indexSearchOrder(). The search order array is empty while
202 the index files are being loaded, but some searches must
203 be performed during this time, notably searches for base
204 class nodes. These searches require a temporary search
205 order. The temporary order changes throughout the loading
206 of the index files, but it is always the tree for the
207 current index file first, followed by the trees for the
208 index files that have already been loaded. The only
209 ordering required in this temporary search order is that
210 the current tree must be searched first.
211 */
212const QList<Tree *> &QDocForest::searchOrder()
213{
214 if (m_searchOrder.isEmpty())
215 return indexSearchOrder();
216 return m_searchOrder;
217}
218
219/*!
220 There are two search orders used by qdoc when searching for
221 things. The normal search order is returned by searchOrder(),
222 but this normal search order is not known until all the index
223 files have been read. At that point, setSearchOrder() is
224 called.
225
226 During the reading of the index files, the vector holding
227 the normal search order remains empty. Whenever the search
228 order is requested, if that vector is empty, this function
229 is called to return a temporary search order, which includes
230 all the index files that have been read so far, plus the
231 one being read now. That one is prepended to the front of
232 the vector.
233 */
234const QList<Tree *> &QDocForest::indexSearchOrder()
235{
236 if (m_forest.size() > m_indexSearchOrder.size())
237 m_indexSearchOrder.prepend(m_primaryTree);
238 return m_indexSearchOrder;
239}
240
241/*!
242 Create a new Tree for the index file for the specified
243 \a module and add it to the forest. Return the pointer
244 to its root.
245 */
246NamespaceNode *QDocForest::newIndexTree(const QString &module)
247{
248 m_primaryTree = new Tree(module, m_qdb);
249 m_forest.insert(module.toLower(), m_primaryTree);
250 return m_primaryTree->root();
251}
252
253/*!
254 Create a new Tree for use as the primary tree. This tree
255 will represent the primary module. \a module is camel case.
256 */
257void QDocForest::newPrimaryTree(const QString &module)
258{
259 m_primaryTree = new Tree(module, m_qdb);
260}
261
262/*!
263 Searches through the forest for a node named \a targetPath
264 and returns a pointer to it if found. The \a relative node
265 is the starting point. It only makes sense for the primary
266 tree, which is searched first. After the primary tree has
267 been searched, \a relative is set to 0 for searching the
268 other trees, which are all index trees. With relative set
269 to 0, the starting point for each index tree is the root
270 of the index tree.
271
272 If \a targetPath is resolved successfully but it refers to
273 a \\section title, continue the search, keeping the section
274 title as a fallback if no higher-priority targets are found.
275 */
276const Node *QDocForest::findNodeForTarget(QStringList &targetPath, const Node *relative,
277 Genus genus, QString &ref, int findFlags)
278{
279 int flags = SearchBaseClasses | SearchEnumValues | findFlags;
280
281 QString entity = targetPath.takeFirst();
282 QStringList entityPath = entity.split("::");
283
284 QString target;
285 if (!targetPath.isEmpty())
286 target = targetPath.takeFirst();
287
289 const Node *tocNode = nullptr;
290 for (const auto *tree : searchOrder()) {
291 const Node *n = tree->findNodeForTarget(entityPath, target, relative, flags, genus, ref, &type);
292 if (n) {
293 // Targets referring to non-section titles are returned immediately
294 if (type != TargetRec::Contents)
295 return n;
296 if (!tocNode)
297 tocNode = n;
298 }
299 relative = nullptr;
300 }
301 return tocNode;
302}
303
304/*!
305 Finds the FunctionNode for the qualified function name
306 in \a path, that also has the specified \a parameters.
307 Returns a pointer to the first matching function.
308
309 \a relative is a node in the primary tree where the search
310 should begin. It is only used when searching the primary
311 tree. \a genus can be used to force the search to find a
312 C++ function or a QML function.
313 */
314const FunctionNode *QDocForest::findFunctionNode(const QStringList &path,
315 const Parameters &parameters, const Node *relative,
316 Genus genus)
317{
318 for (const auto *tree : searchOrder()) {
319 const FunctionNode *fn = tree->findFunctionNode(path, parameters, relative, genus);
320 if (fn)
321 return fn;
322 relative = nullptr;
323 }
324 return nullptr;
325}
326
327/*! \class QDocDatabase
328 This class provides exclusive access to the qdoc database,
329 which consists of a forrest of trees and a lot of maps and
330 other useful data structures.
331 */
332
333QDocDatabase *QDocDatabase::s_qdocDB = nullptr;
334NodeMap QDocDatabase::s_typeNodeMap;
335NodeMultiMap QDocDatabase::s_obsoleteClasses;
336NodeMultiMap QDocDatabase::s_classesWithObsoleteMembers;
337NodeMultiMap QDocDatabase::s_obsoleteQmlTypes;
338NodeMultiMap QDocDatabase::s_qmlTypesWithObsoleteMembers;
339NodeMultiMap QDocDatabase::s_cppClasses;
340NodeMultiMap QDocDatabase::s_qmlBasicTypes;
341NodeMultiMap QDocDatabase::s_qmlTypes;
342NodeMultiMap QDocDatabase::s_examples;
343NodeMultiMapMap QDocDatabase::s_newClassMaps;
344NodeMultiMapMap QDocDatabase::s_newQmlTypeMaps;
345NodeMultiMapMap QDocDatabase::s_newEnumValueMaps;
346NodeMultiMapMap QDocDatabase::s_newSinceMaps;
347
348/*!
349 Constructs the singleton qdoc database object. The singleton
350 constructs the \a forest_ object, which is also a singleton.
351 \a m_showInternal is normally false. If it is true, qdoc will
352 write documentation for nodes marked \c internal.
353
354 \a singleExec_ is false when qdoc is being used in the standard
355 way of running qdoc twices for each module, first with --prepare
356 and then with --generate. First the --prepare phase is run for
357 each module, then the --generate phase is run for each module.
358
359 When \a singleExec_ is true, qdoc is run only once. During the
360 single execution, qdoc processes the qdocconf files for all the
361 modules sequentially in a loop. Each source file for each module
362 is read exactly once.
363 */
364QDocDatabase::QDocDatabase() : m_forest(this)
365{
366 // nothing
367}
368
369/*!
370 Creates the singleton. Allows only one instance of the class
371 to be created. Returns a pointer to the singleton.
372*/
374{
375 if (s_qdocDB == nullptr) {
376 s_qdocDB = new QDocDatabase;
377 initializeDB();
378 }
379 return s_qdocDB;
380}
381
382/*!
383 Destroys the singleton.
384 */
386{
387 if (s_qdocDB != nullptr) {
388 delete s_qdocDB;
389 s_qdocDB = nullptr;
390 }
391}
392
393/*!
394 Initialize data structures in the singleton qdoc database.
395
396 In particular, the type node map is initialized with a lot
397 type names that don't refer to documented types. For example,
398 many C++ standard types are included. These might be documented
399 here at some point, but for now they are not. Other examples
400 include \c array and \c data, which are just generic names
401 used as place holders in function signatures that appear in
402 the documentation.
403
404 \note Do not add QML basic types into this list as it will
405 break linking to those types.
406 */
407void QDocDatabase::initializeDB()
408{
409 s_typeNodeMap.insert("accepted", nullptr);
410 s_typeNodeMap.insert("actionPerformed", nullptr);
411 s_typeNodeMap.insert("activated", nullptr);
412 s_typeNodeMap.insert("alias", nullptr);
413 s_typeNodeMap.insert("anchors", nullptr);
414 s_typeNodeMap.insert("any", nullptr);
415 s_typeNodeMap.insert("array", nullptr);
416 s_typeNodeMap.insert("autoSearch", nullptr);
417 s_typeNodeMap.insert("axis", nullptr);
418 s_typeNodeMap.insert("backClicked", nullptr);
419 s_typeNodeMap.insert("boomTime", nullptr);
420 s_typeNodeMap.insert("border", nullptr);
421 s_typeNodeMap.insert("buttonClicked", nullptr);
422 s_typeNodeMap.insert("callback", nullptr);
423 s_typeNodeMap.insert("char", nullptr);
424 s_typeNodeMap.insert("clicked", nullptr);
425 s_typeNodeMap.insert("close", nullptr);
426 s_typeNodeMap.insert("closed", nullptr);
427 s_typeNodeMap.insert("cond", nullptr);
428 s_typeNodeMap.insert("data", nullptr);
429 s_typeNodeMap.insert("dataReady", nullptr);
430 s_typeNodeMap.insert("dateString", nullptr);
431 s_typeNodeMap.insert("dateTimeString", nullptr);
432 s_typeNodeMap.insert("datetime", nullptr);
433 s_typeNodeMap.insert("day", nullptr);
434 s_typeNodeMap.insert("deactivated", nullptr);
435 s_typeNodeMap.insert("drag", nullptr);
436 s_typeNodeMap.insert("easing", nullptr);
437 s_typeNodeMap.insert("error", nullptr);
438 s_typeNodeMap.insert("exposure", nullptr);
439 s_typeNodeMap.insert("fatalError", nullptr);
440 s_typeNodeMap.insert("fileSelected", nullptr);
441 s_typeNodeMap.insert("flags", nullptr);
442 s_typeNodeMap.insert("float", nullptr);
443 s_typeNodeMap.insert("focus", nullptr);
444 s_typeNodeMap.insert("focusZone", nullptr);
445 s_typeNodeMap.insert("format", nullptr);
446 s_typeNodeMap.insert("framePainted", nullptr);
447 s_typeNodeMap.insert("from", nullptr);
448 s_typeNodeMap.insert("frontClicked", nullptr);
449 s_typeNodeMap.insert("function", nullptr);
450 s_typeNodeMap.insert("hasOpened", nullptr);
451 s_typeNodeMap.insert("hovered", nullptr);
452 s_typeNodeMap.insert("hoveredTitle", nullptr);
453 s_typeNodeMap.insert("hoveredUrl", nullptr);
454 s_typeNodeMap.insert("imageCapture", nullptr);
455 s_typeNodeMap.insert("imageProcessing", nullptr);
456 s_typeNodeMap.insert("index", nullptr);
457 s_typeNodeMap.insert("initialized", nullptr);
458 s_typeNodeMap.insert("isLoaded", nullptr);
459 s_typeNodeMap.insert("item", nullptr);
460 s_typeNodeMap.insert("key", nullptr);
461 s_typeNodeMap.insert("keysequence", nullptr);
462 s_typeNodeMap.insert("listViewClicked", nullptr);
463 s_typeNodeMap.insert("loadRequest", nullptr);
464 s_typeNodeMap.insert("locale", nullptr);
465 s_typeNodeMap.insert("location", nullptr);
466 s_typeNodeMap.insert("long", nullptr);
467 s_typeNodeMap.insert("message", nullptr);
468 s_typeNodeMap.insert("messageReceived", nullptr);
469 s_typeNodeMap.insert("mode", nullptr);
470 s_typeNodeMap.insert("month", nullptr);
471 s_typeNodeMap.insert("name", nullptr);
472 s_typeNodeMap.insert("number", nullptr);
473 s_typeNodeMap.insert("object", nullptr);
474 s_typeNodeMap.insert("offset", nullptr);
475 s_typeNodeMap.insert("ok", nullptr);
476 s_typeNodeMap.insert("openCamera", nullptr);
477 s_typeNodeMap.insert("openImage", nullptr);
478 s_typeNodeMap.insert("openVideo", nullptr);
479 s_typeNodeMap.insert("padding", nullptr);
480 s_typeNodeMap.insert("parent", nullptr);
481 s_typeNodeMap.insert("path", nullptr);
482 s_typeNodeMap.insert("photoModeSelected", nullptr);
483 s_typeNodeMap.insert("position", nullptr);
484 s_typeNodeMap.insert("precision", nullptr);
485 s_typeNodeMap.insert("presetClicked", nullptr);
486 s_typeNodeMap.insert("preview", nullptr);
487 s_typeNodeMap.insert("previewSelected", nullptr);
488 s_typeNodeMap.insert("progress", nullptr);
489 s_typeNodeMap.insert("puzzleLost", nullptr);
490 s_typeNodeMap.insert("qmlSignal", nullptr);
491 s_typeNodeMap.insert("rectangle", nullptr);
492 s_typeNodeMap.insert("request", nullptr);
493 s_typeNodeMap.insert("requestId", nullptr);
494 s_typeNodeMap.insert("section", nullptr);
495 s_typeNodeMap.insert("selected", nullptr);
496 s_typeNodeMap.insert("send", nullptr);
497 s_typeNodeMap.insert("settingsClicked", nullptr);
498 s_typeNodeMap.insert("shoe", nullptr);
499 s_typeNodeMap.insert("short", nullptr);
500 s_typeNodeMap.insert("signed", nullptr);
501 s_typeNodeMap.insert("sizeChanged", nullptr);
502 s_typeNodeMap.insert("size_t", nullptr);
503 s_typeNodeMap.insert("sockaddr", nullptr);
504 s_typeNodeMap.insert("someOtherSignal", nullptr);
505 s_typeNodeMap.insert("sourceSize", nullptr);
506 s_typeNodeMap.insert("startButtonClicked", nullptr);
507 s_typeNodeMap.insert("state", nullptr);
508 s_typeNodeMap.insert("std::initializer_list", nullptr);
509 s_typeNodeMap.insert("std::list", nullptr);
510 s_typeNodeMap.insert("std::map", nullptr);
511 s_typeNodeMap.insert("std::pair", nullptr);
512 s_typeNodeMap.insert("std::string", nullptr);
513 s_typeNodeMap.insert("std::vector", nullptr);
514 s_typeNodeMap.insert("stringlist", nullptr);
515 s_typeNodeMap.insert("swapPlayers", nullptr);
516 s_typeNodeMap.insert("symbol", nullptr);
517 s_typeNodeMap.insert("t", nullptr);
518 s_typeNodeMap.insert("T", nullptr);
519 s_typeNodeMap.insert("tagChanged", nullptr);
520 s_typeNodeMap.insert("timeString", nullptr);
521 s_typeNodeMap.insert("timeout", nullptr);
522 s_typeNodeMap.insert("to", nullptr);
523 s_typeNodeMap.insert("toggled", nullptr);
524 s_typeNodeMap.insert("type", nullptr);
525 s_typeNodeMap.insert("unsigned", nullptr);
526 s_typeNodeMap.insert("urllist", nullptr);
527 s_typeNodeMap.insert("va_list", nullptr);
528 s_typeNodeMap.insert("value", nullptr);
529 s_typeNodeMap.insert("valueEmitted", nullptr);
530 s_typeNodeMap.insert("videoFramePainted", nullptr);
531 s_typeNodeMap.insert("videoModeSelected", nullptr);
532 s_typeNodeMap.insert("videoRecorder", nullptr);
533 s_typeNodeMap.insert("void", nullptr);
534 s_typeNodeMap.insert("volatile", nullptr);
535 s_typeNodeMap.insert("wchar_t", nullptr);
536 s_typeNodeMap.insert("x", nullptr);
537 s_typeNodeMap.insert("y", nullptr);
538 s_typeNodeMap.insert("zoom", nullptr);
539 s_typeNodeMap.insert("zoomTo", nullptr);
540}
541
542/*! \fn NamespaceNode *QDocDatabase::primaryTreeRoot()
543 Returns a pointer to the root node of the primary tree.
544 */
545
546/*!
547 \fn const CNMap &QDocDatabase::groups()
548 Returns a const reference to the collection of all
549 group nodes in the primary tree.
550*/
551
552/*!
553 \fn const CNMap &QDocDatabase::modules()
554 Returns a const reference to the collection of all
555 module nodes in the primary tree.
556*/
557
558/*!
559 \fn const CNMap &QDocDatabase::qmlModules()
560 Returns a const reference to the collection of all
561 QML module nodes in the primary tree.
562*/
563
564/*! \fn CollectionNode *QDocDatabase::findGroup(const QString &name)
565 Find the group node named \a name and return a pointer
566 to it. If a matching node is not found, add a new group
567 node named \a name and return a pointer to that one.
568
569 If a new group node is added, its parent is the tree root,
570 and the new group node is marked \e{not seen}.
571 */
572
573/*! \fn CollectionNode *QDocDatabase::findModule(const QString &name)
574 Find the module node named \a name and return a pointer
575 to it. If a matching node is not found, add a new module
576 node named \a name and return a pointer to that one.
577
578 If a new module node is added, its parent is the tree root,
579 and the new module node is marked \e{not seen}.
580 */
581
582/*! \fn CollectionNode *QDocDatabase::addGroup(const QString &name)
583 Looks up the group named \a name in the primary tree. If
584 a match is found, a pointer to the node is returned.
585 Otherwise, a new group node named \a name is created and
586 inserted into the collection, and the pointer to that node
587 is returned.
588 */
589
590/*! \fn CollectionNode *QDocDatabase::addModule(const QString &name)
591 Looks up the module named \a name in the primary tree. If
592 a match is found, a pointer to the node is returned.
593 Otherwise, a new module node named \a name is created and
594 inserted into the collection, and the pointer to that node
595 is returned.
596 */
597
598/*! \fn CollectionNode *QDocDatabase::addQmlModule(const QString &name)
599 Looks up the QML module named \a name in the primary tree.
600 If a match is found, a pointer to the node is returned.
601 Otherwise, a new QML module node named \a name is created
602 and inserted into the collection, and the pointer to that
603 node is returned.
604 */
605
606/*! \fn CollectionNode *QDocDatabase::addToGroup(const QString &name, Node *node)
607 Looks up the group node named \a name in the collection
608 of all group nodes. If a match is not found, a new group
609 node named \a name is created and inserted into the collection.
610 Then append \a node to the group's members list, and append the
611 group node to the member list of the \a node. The parent of the
612 \a node is not changed by this function. Returns a pointer to
613 the group node.
614 */
615
616/*! \fn CollectionNode *QDocDatabase::addToModule(const QString &name, Node *node)
617 Looks up the module node named \a name in the collection
618 of all module nodes. If a match is not found, a new module
619 node named \a name is created and inserted into the collection.
620 Then append \a node to the module's members list. The parent of
621 \a node is not changed by this function. Returns the module node.
622 */
623
624/*! \fn Collection *QDocDatabase::addToQmlModule(const QString &name, Node *node)
625 Looks up the QML module named \a name. If it isn't there,
626 create it. Then append \a node to the QML module's member
627 list. The parent of \a node is not changed by this function.
628 */
629
630/*! \fn QmlTypeNode *QDocDatabase::findQmlType(const QString &name)
631 Returns the QML type node identified by the qualified
632 QML type \a name, or \c nullptr if no type was found.
633 */
634
635/*!
636 Returns the QML type node identified by the QML module id
637 \a qmid and QML type \a name, or \c nullptr if no type
638 was found.
639
640 If the QML module id is empty, looks up the QML type by
641 \a name only.
642
643 When \a tree is given, the lookup is restricted to that
644 tree instead of searching the whole forest.
645 */
646QmlTypeNode *QDocDatabase::findQmlType(const QString &qmid, const QString &name,
647 const Node *relative, Tree *tree)
648{
649 if (!qmid.isEmpty()) {
650 QmlTypeNode *qcn = tree
651 ? tree->lookupQmlType(qmid + u"::"_s + name, relative)
652 : m_forest.lookupQmlType(qmid + u"::"_s + name, relative);
653 if (qcn)
654 return qcn;
655 }
656
657 // Try unqualified lookup first (uses context-aware disambiguation)
658 QmlTypeNode *qcn = tree
659 ? tree->lookupQmlType(name, relative)
660 : m_forest.lookupQmlType(name, relative);
661 if (qcn)
662 return qcn;
663
664 // Fallback to path-based search
665 QStringList path(name);
666 Node *node = tree
667 ? tree->findNodeByNameAndType(path, &Node::isQmlType)
668 : findNodeByNameAndType(path, &Node::isQmlType);
669 return static_cast<QmlTypeNode *>(node);
670}
671
672/*!
673 Returns the QML type node identified by the QML module id
674 constructed from the strings in the import \a record and the
675 QML type \a name. Returns \c nullptr if no type was not found.
676 */
677QmlTypeNode *QDocDatabase::findQmlType(const ImportRec &record, const QString &name, const Node *relative)
678{
679 if (record.isEmpty())
680 return nullptr;
681
682 QString type{name};
683
684 // If the import is under a namespace (id) and the type name is not prefixed with that id,
685 // then we know the type is not available under this import.
686 if (!record.m_importId.isEmpty()) {
687 const QString namespacePrefix{"%1."_L1.arg(record.m_importId)};
688 if (!type.startsWith(namespacePrefix))
689 return nullptr;
690 type.remove(0, namespacePrefix.size());
691 }
692
693 const QString qmName = record.m_importUri.isEmpty() ? record.m_moduleName : record.m_importUri;
694 return m_forest.lookupQmlType(qmName + u"::"_s + type, relative);
695}
696
697/*!
698 Returns the QML node identified by the QML module id \a qmid
699 and \a name, searching in the primary tree only. If \a qmid
700 is an empty string, searches for the node using name only.
701
702 Returns \c nullptr if no node was found.
703*/
704QmlTypeNode *QDocDatabase::findQmlTypeInPrimaryTree(const QString &qmid, const QString &name)
705{
706 if (!qmid.isEmpty())
707 return primaryTree()->lookupQmlType(qmid + u"::"_s + name);
708 return static_cast<QmlTypeNode *>(primaryTreeRoot()->findChildNode(name, Genus::QML, TypesOnly));
709}
710
711/*!
712 This function calls a set of functions for each tree in the
713 forest that has not already been analyzed. In this way, when
714 running qdoc in \e singleExec mode, each tree is analyzed in
715 turn, and its classes and types are added to the appropriate
716 node maps.
717 */
719{
720 processForest(&QDocDatabase::findAllClasses);
721 processForest(&QDocDatabase::findAllFunctions);
722 processForest(&QDocDatabase::findAllObsoleteThings);
723 processForest(&QDocDatabase::findAllLegaleseTexts);
724 processForest(&QDocDatabase::findAllSince);
725 processForest(&QDocDatabase::findAllAttributions);
727}
728
729/*!
730 This function calls \a func for each tree in the forest,
731 ensuring that \a func is called only once per tree.
732
733 \sa processForest()
734 */
735void QDocDatabase::processForest(FindFunctionPtr func)
736{
737 Tree *t = m_forest.firstTree();
738 while (t) {
739 if (!m_completedFindFunctions.values(t).contains(func)) {
740 (this->*(func))(t->root());
741 m_completedFindFunctions.insert(t, func);
742 }
743 t = m_forest.nextTree();
744 }
745}
746
747/*!
748 Returns a reference to the collection of legalese texts.
749 */
751{
752 processForest(&QDocDatabase::findAllLegaleseTexts);
753 return m_legaleseTexts;
754}
755
756/*!
757 Returns a reference to the map of C++ classes with obsolete members.
758 */
760{
761 processForest(&QDocDatabase::findAllObsoleteThings);
762 return s_classesWithObsoleteMembers;
763}
764
765/*!
766 Returns a reference to the map of obsolete QML types.
767 */
769{
770 processForest(&QDocDatabase::findAllObsoleteThings);
771 return s_obsoleteQmlTypes;
772}
773
774/*!
775 Returns a reference to the map of QML types with obsolete members.
776 */
778{
779 processForest(&QDocDatabase::findAllObsoleteThings);
780 return s_qmlTypesWithObsoleteMembers;
781}
782
783/*!
784 Returns a reference to the map of QML basic types.
785 */
787{
788 processForest(&QDocDatabase::findAllClasses);
789 return s_qmlBasicTypes;
790}
791
792/*!
793 Returns a reference to the multimap of QML types.
794 */
796{
797 processForest(&QDocDatabase::findAllClasses);
798 return s_qmlTypes;
799}
800
801/*!
802 Returns a reference to the multimap of example nodes.
803 */
805{
806 processForest(&QDocDatabase::findAllClasses);
807 return s_examples;
808}
809
810/*!
811 Returns a reference to the multimap of attribution nodes.
812 */
814{
815 processForest(&QDocDatabase::findAllAttributions);
816 return m_attributions;
817}
818
819/*!
820 Returns a reference to the map of obsolete C++ clases.
821 */
823{
824 processForest(&QDocDatabase::findAllObsoleteThings);
825 return s_obsoleteClasses;
826}
827
828/*!
829 Returns a reference to the map of all C++ classes.
830 */
832{
833 processForest(&QDocDatabase::findAllClasses);
834 return s_cppClasses;
835}
836
837/*!
838 Returns the function index. This data structure is used to
839 output the function index page.
840 */
842{
843 processForest(&QDocDatabase::findAllFunctions);
844 return m_functionIndex;
845}
846
847/*!
848 Finds all the nodes containing legalese text and puts them
849 in a map.
850 */
851void QDocDatabase::findAllLegaleseTexts(Aggregate *node)
852{
853 for (const auto &childNode : node->childNodes()) {
854 if (childNode->isPrivate())
855 continue;
856 if (!childNode->doc().legaleseText().isEmpty())
857 m_legaleseTexts.insert(childNode->doc().legaleseText(), childNode);
858 if (childNode->isAggregate())
859 findAllLegaleseTexts(static_cast<Aggregate *>(childNode));
860 }
861}
862
863/*!
864 \fn void QDocDatabase::findAllObsoleteThings(Aggregate *node)
865
866 Finds all nodes with status = Deprecated and sorts them into
867 maps. They can be C++ classes, QML types, or they can be
868 functions, enum types, typedefs, methods, etc.
869 */
870
871/*!
872 \fn void QDocDatabase::findAllSince(Aggregate *node)
873
874 Finds all the nodes in \a node where a \e{since} command appeared
875 in the qdoc comment and sorts them into maps according to the kind
876 of node.
877
878 This function is used for generating the "New Classes... in x.y"
879 section on the \e{What's New in Qt x.y} page.
880 */
881
882/*!
883 \fn const CollectionNode *QDocDatabase::findConceptNode(const QString &name)
884
885 Non-creating, cross-tree lookup. findConcept()/findCollection() fabricate a
886 placeholder on a miss, which would shadow a dependency-module concept with an
887 empty primary-tree node and emit a dangling local href. getCollectionNode()
888 searches the same forest order without that side effect.
889 */
890
891/*!
892 Find the \a key in the map of new class maps, and return a
893 reference to the value, which is a NodeMap. If \a key is not
894 found, return a reference to an empty NodeMap.
895 */
896const NodeMultiMap &QDocDatabase::getClassMap(const QString &key)
897{
898 processForest(&QDocDatabase::findAllSince);
899 auto it = s_newClassMaps.constFind(key);
900 return (it != s_newClassMaps.constEnd()) ? it.value() : emptyNodeMultiMap_;
901}
902
903/*!
904 Find the \a key in the map of new QML type maps, and return a
905 reference to the value, which is a NodeMap. If the \a key is not
906 found, return a reference to an empty NodeMap.
907 */
908const NodeMultiMap &QDocDatabase::getQmlTypeMap(const QString &key)
909{
910 processForest(&QDocDatabase::findAllSince);
911 auto it = s_newQmlTypeMaps.constFind(key);
912 return (it != s_newQmlTypeMaps.constEnd()) ? it.value() : emptyNodeMultiMap_;
913}
914
915/*!
916 Find the \a key in the map of new \e {since} maps, and return
917 a reference to the value, which is a NodeMultiMap. If \a key
918 is not found, return a reference to an empty NodeMultiMap.
919 */
920const NodeMultiMap &QDocDatabase::getSinceMap(const QString &key)
921{
922 processForest(&QDocDatabase::findAllSince);
923 auto it = s_newSinceMaps.constFind(key);
924 return (it != s_newSinceMaps.constEnd()) ? it.value() : emptyNodeMultiMap_;
925}
926
927/*!
928 Performs several housekeeping tasks prior to generating the
929 documentation. These tasks create required data structures
930 and resolve links.
931
932 The order of operations is important in some cases. For example,
933 the call to removePrivateAndInternalBases must follow the call to
934 markUndocumentedChildrenInternal to ensure correct behavior.
935 */
937{
938 const auto &config = Config::instance();
939 if (config.dualExec() || config.preparing()) {
940 // order matters
941 primaryTree()->resolveBaseClasses(primaryTreeRoot());
942 primaryTree()->resolvePropertyOverriddenFromPtrs(primaryTreeRoot());
947 primaryTree()->validatePropertyDocumentation(primaryTreeRoot());
949 primaryTree()->removePrivateAndInternalBases(primaryTreeRoot());
951 primaryTree()->resolveTargets(primaryTreeRoot());
952 primaryTree()->resolveCppToQmlLinks();
953 primaryTree()->resolveSince(*primaryTreeRoot());
955 }
956 if (config.singleExec() && config.generating()) {
957 primaryTree()->resolveBaseClasses(primaryTreeRoot());
958 primaryTree()->resolvePropertyOverriddenFromPtrs(primaryTreeRoot());
960 primaryTree()->resolveCppToQmlLinks();
961 primaryTree()->resolveSince(*primaryTreeRoot());
963 }
964 if (!config.preparing()) {
969 }
970 if (config.dualExec())
971 QDocIndexFiles::destroyQDocIndexFiles();
972}
973
975{
976 Tree *t = m_forest.firstTree();
977 while (t) {
978 t->resolveBaseClasses(t->root());
979 if (t != primaryTree())
980 t->root()->resolveQmlInheritance();
981 t = m_forest.nextTree();
982 }
983}
984
985/*!
986 Gathers the fully-qualified concept names referenced by \a node.
987 Template-head and direct-concept references live on the optional
988 RelaxedTemplateDeclaration carried by the node; trailing-requires
989 and constrained-auto references are accumulated on the FunctionNode.
990 */
991static void collectConceptReferences(const Node *node, QStringList &refs)
992{
993 if (const auto &td = node->templateDecl(); td.has_value()) {
994 for (const auto &name : td->referenced_concepts)
995 refs.append(QString::fromStdString(name));
996 }
997 if (node->isFunction()) {
998 const auto *fn = static_cast<const FunctionNode *>(node);
999 refs += fn->referencedConcepts();
1000 }
1001}
1002
1003/*!
1004 Walks every documented node under \a parent and registers each constrained
1005 item as a member of the concept's CollectionNode for each concept it
1006 references.
1007
1008 Recurses into aggregates so the entire primary tree is covered.
1009 */
1011{
1012 for (auto *child : std::as_const(parent->childNodes())) {
1013 // A skipped node is not registered as a concept user, but its
1014 // documented descendants still are: a documented class nested in an
1015 // internal namespace, for example, should still appear in its concept's
1016 // "Used by" list. Visibility filtering and recursion are therefore
1017 // independent.
1018 const bool registerChild =
1019 !child->isPrivate() && !child->isInternal() && !child->isDontDocument();
1020
1021 if (registerChild) {
1022 QStringList refs;
1023 collectConceptReferences(child, refs);
1024 refs.sort();
1025 refs.removeDuplicates();
1026
1027 for (const QString &conceptName : std::as_const(refs)) {
1028 // Cross-tree lookup. The forest search order covers the primary
1029 // tree plus every dependency-module index tree. A concept
1030 // declared in module B and referenced from module A can be
1031 // found through the same cross-tree lookup machinery.
1032 // Concepts without a \\concept block anywhere in the corpus
1033 // return \c{nullptr} and are silently skipped; references to
1034 // undocumented concepts (such as std::integral) are common and
1035 // not actionable.
1036 //
1037 // addMember() deduplicates membership centrally, so re-running
1038 // this pass is safe and produces a stable "Used by" listing
1039 // without per-call guard logic.
1040 if (auto *cn = db.findMutableCollectionNode(conceptName, NodeType::Concept))
1041 cn->addMember(child);
1042 }
1043 }
1044
1045 if (child->isAggregate())
1046 registerConceptUsersUnder(static_cast<Aggregate *>(child), db);
1047 }
1048}
1049
1050/*!
1051 Builds the concept-to-users reverse index after parsing finishes
1052 and before any generator runs. The forward direction — which
1053 concepts a constrained declaration references — is captured
1054 during the libclang AST pass; this pass turns those isolated
1055 references into bidirectional collection membership so concept
1056 reference pages can render a \e {Used by} section through the
1057 same scaffolding group and module collection pages already use.
1058 */
1060{
1061 registerConceptUsersUnder(primaryTreeRoot(), *this);
1062}
1063
1064/*!
1065 Returns a reference to the namespace map. Constructs the
1066 namespace map if it hasn't been constructed yet.
1067
1068 \note This function must not be called in the prepare phase.
1069 */
1071{
1073 return m_namespaceIndex;
1074}
1075
1076/*!
1077 Multiple namespace nodes for namespace X can exist in the
1078 qdoc database in different trees. This function first finds
1079 all namespace nodes in all the trees and inserts them into
1080 a multimap. Then it combines all the namespace nodes that
1081 have the same name into a single namespace node of that
1082 name and inserts that combined namespace node into an index.
1083 */
1085{
1086 if (!m_namespaceIndex.isEmpty())
1087 return;
1088
1089 bool linkErrors = !Config::instance().get(CONFIG_NOLINKERRORS).asBool();
1090 NodeMultiMap namespaceMultimap;
1091 Tree *t = m_forest.firstTree();
1092 while (t) {
1093 t->root()->findAllNamespaces(namespaceMultimap);
1094 t = m_forest.nextTree();
1095 }
1096 const QList<QString> keys = namespaceMultimap.uniqueKeys();
1097 for (const QString &key : keys) {
1098 NamespaceNode *ns = nullptr;
1099 NamespaceNode *indexNamespace = nullptr;
1100 const NodeList namespaces = namespaceMultimap.values(key);
1101 qsizetype count = namespaceMultimap.remove(key);
1102 if (count > 0) {
1103 for (auto *node : namespaces) {
1104 ns = static_cast<NamespaceNode *>(node);
1105 if (ns->isDocumentedHere())
1106 break;
1107 else if (ns->hadDoc())
1108 indexNamespace = ns; // namespace was documented but in another tree
1109 ns = nullptr;
1110 }
1111 if (ns) {
1112 for (auto *node : namespaces) {
1113 auto *nsNode = static_cast<NamespaceNode *>(node);
1114 if (nsNode->hadDoc() && nsNode != ns) {
1115 ns->doc().location().warning(
1116 QStringLiteral("Namespace %1 documented more than once")
1117 .arg(nsNode->name()), QStringLiteral("also seen here: %1")
1118 .arg(nsNode->doc().location().toString()));
1119 }
1120 }
1121 } else if (!indexNamespace) {
1122 // Warn about documented children in undocumented namespaces.
1123 // As the namespace can be documented outside this project,
1124 // skip the warning if --no-link-errors is set
1125 if (linkErrors) {
1126 for (auto *node : namespaces) {
1127 if (!node->isIndexNode())
1128 static_cast<NamespaceNode *>(node)->reportDocumentedChildrenInUndocumentedNamespace();
1129 }
1130 }
1131 } else {
1132 for (auto *node : namespaces) {
1133 auto *nsNode = static_cast<NamespaceNode *>(node);
1134 if (nsNode != indexNamespace)
1135 nsNode->setDocNode(indexNamespace);
1136 }
1137 }
1138 }
1139 /*
1140 If there are multiple namespace nodes with the same
1141 name where one of them will be the main reference page
1142 for the namespace, include all nodes in the public
1143 API of the namespace.
1144 */
1145 if (ns && count > 1) {
1146 for (auto *node : namespaces) {
1147 auto *nameSpaceNode = static_cast<NamespaceNode *>(node);
1148 if (nameSpaceNode != ns) {
1149 for (auto it = nameSpaceNode->constBegin(); it != nameSpaceNode->constEnd();
1150 ++it) {
1151 Node *anotherNs = *it;
1152 if (anotherNs && anotherNs->isPublic() && !anotherNs->isInternal())
1153 ns->includeChild(anotherNs);
1154 }
1155 }
1156 }
1157 }
1158 /*
1159 Add the main namespace reference node to index, or the last seen
1160 namespace if the main one was not found.
1161 */
1162 if (!ns)
1163 ns = indexNamespace ? indexNamespace : static_cast<NamespaceNode *>(namespaces.last());
1164 m_namespaceIndex.insert(ns->name(), ns);
1165 }
1166}
1167
1168/*!
1169 Each instance of class Tree that represents an index file
1170 must be traversed to find all instances of class ProxyNode.
1171 For each ProxyNode found, look up the ProxyNode's name in
1172 the primary Tree. If it is found, it means that the proxy
1173 node contains elements (normally just functions) that are
1174 documented in the module represented by the Tree containing
1175 the proxy node but that are related to the node we found in
1176 the primary tree.
1177
1178 Also, for each node in the Tree that is related to an aggregate
1179 in another module with an additional \c relates command, look up
1180 the aggregate in the primary Tree. If it is found, the aggregate
1181 lists the node as related, linking to its documentation in the
1182 module represented by the Tree.
1183
1184 \sa Tree::externalRelates()
1185 */
1187{
1188 // The first tree is the primary tree.
1189 // Skip the primary tree.
1190 Tree *t = m_forest.firstTree();
1191 t = m_forest.nextTree();
1192 while (t) {
1193 const NodeList &proxies = t->proxies();
1194 if (!proxies.isEmpty()) {
1195 for (auto *node : proxies) {
1196 const auto *pn = static_cast<ProxyNode *>(node);
1197 if (pn->count() > 0) {
1198 Aggregate *aggregate = primaryTree()->findAggregate(pn->name());
1199 if (aggregate != nullptr)
1200 aggregate->appendToRelatedByProxy(pn->childNodes());
1201 }
1202 }
1203 }
1204 const auto &externalRelates = t->externalRelates();
1205 for (auto it = externalRelates.cbegin(); it != externalRelates.cend(); ++it) {
1206 Aggregate *aggregate = primaryTree()->findRelatesNode(it.value().split("::"_L1));
1207 if (aggregate && !aggregate->relatedByProxy().contains(it.key()))
1208 aggregate->appendToRelatedByProxy({ it.key() });
1209 }
1210 t = m_forest.nextTree();
1211 }
1212}
1213
1214/*!
1215 Finds the function node for the qualified function path in
1216 \a target and returns a pointer to it. The \a target is a
1217 function signature with or without parameters but without
1218 the return type.
1219
1220 \a relative is the node in the primary tree where the search
1221 begins. It is not used in the other trees, if the node is not
1222 found in the primary tree. \a genus can be used to force the
1223 search to find a C++ function or a QML function.
1224
1225 The entire forest is searched, but the first match is accepted.
1226 */
1227const FunctionNode *QDocDatabase::findFunctionNode(const QString &target, const Node *relative,
1228 Genus genus)
1229{
1230 QString function = target;
1231 const QString signature = Parameters::extractParameters(function);
1232 const Parameters parameters(signature.trimmed());
1233 if (!parameters.isValid())
1234 return nullptr;
1235
1236 const QStringList path = function.split("::"_L1);
1237 return m_forest.findFunctionNode(path, parameters, relative, genus);
1238}
1239
1240/*!
1241 This function is called for autolinking to a \a type,
1242 which could be a function return type or a parameter
1243 type. The tree node that represents the \a type is
1244 returned. All the trees are searched until a match is
1245 found. When searching the primary tree, the search
1246 begins at \a relative and proceeds up the parent chain.
1247 When searching the index trees, the search begins at the
1248 root.
1249 */
1250const Node *QDocDatabase::findTypeNode(const QString &type, const Node *relative, Genus genus)
1251{
1252 // For QML contexts with qualified names containing ".", try import-aware lookup first
1253 if ((genus == Genus::QML || (relative && relative->genus() == Genus::QML)) &&
1254 type.contains('.') && !type.contains("::")) {
1255 if (relative && relative->isQmlType()) {
1256 const QmlTypeNode *qmlType = static_cast<const QmlTypeNode*>(relative);
1257 const ImportList &imports = qmlType->importList();
1258
1259 for (const auto &import : imports) {
1260 if (QmlTypeNode *found = findQmlType(import, type)) {
1261 return found;
1262 }
1263 }
1264 }
1265
1266 // Fall back to regular path-based lookup for QML qualified names
1267 QStringList path = type.split(".");
1268 if ((path.size() == 1) && (path.at(0)[0].isLower() || path.at(0) == QString("T"))) {
1269 auto it = s_typeNodeMap.find(path.at(0));
1270 if (it != s_typeNodeMap.end())
1271 return it.value();
1272 }
1273
1274 // Try the full qualified path first
1275 const Node *node = m_forest.findTypeNode(path, relative, genus);
1276 if (node)
1277 return node;
1278
1279 // If the full path fails and we have multiple segments, try just the last segment
1280 // This handles cases like "TM.BaseType" where "TM" is an alias we can't resolve
1281 // but "BaseType" might be findable as a QML type
1282 if (path.size() > 1) {
1283 const Node *lastSegmentNode = m_forest.findTypeNode(QStringList{path.last()}, relative, genus);
1284 if (lastSegmentNode && lastSegmentNode->isQmlType())
1285 return lastSegmentNode;
1286 }
1287
1288 return nullptr;
1289 }
1290
1291 // For C++ contexts or QML types with "::" notation, use C++ path splitting
1292 QStringList path = type.split("::");
1293 if ((path.size() == 1) && (path.at(0)[0].isLower() || path.at(0) == QString("T"))) {
1294 auto it = s_typeNodeMap.find(path.at(0));
1295 if (it != s_typeNodeMap.end())
1296 return it.value();
1297 }
1298 return m_forest.findTypeNode(path, relative, genus);
1299}
1300
1301/*!
1302 Finds the node that will generate the documentation that
1303 contains the \a target and returns a pointer to it.
1304
1305 Can this be improved by using the target map in Tree?
1306 */
1307const Node *QDocDatabase::findNodeForTarget(const QString &target, const Node *relative)
1308{
1309 const Node *node = nullptr;
1310 if (target.isEmpty())
1311 node = relative;
1312 else if (target.endsWith(".html"))
1313 node = findNodeByNameAndType(QStringList(target), &Node::isPageNode);
1314 else {
1315 QStringList path = target.split("::");
1316 int flags = SearchBaseClasses | SearchEnumValues;
1317 for (const auto *tree : searchOrder()) {
1318 const Node *n = tree->findNode(path, relative, flags, Genus::DontCare);
1319 if (n)
1320 return n;
1321 relative = nullptr;
1322 }
1323 node = findPageNodeByTitle(target);
1324 }
1325 return node;
1326}
1327
1328/*!
1329 Finds the node for \a target relative to \a relative, with genus and
1330 module scoping.
1331
1332 When \a moduleName names a loaded module, the search is restricted
1333 to that module's tree. Targets with a trailing parameter list use
1334 function-specific lookup.
1335
1336 A target written in QML dot-path notation, such as
1337 \c {Type.property} or \c {Module.Type}, resolves through the
1338 import-aware QML lookup when \a origin is \l {LinkReferenceOrigin}
1339 {LinkReferenceOrigin::Explicit} and the \a genus is QML or
1340 DontCare. Automatically produced references keep the historical
1341 interpretation, and an explicit non-QML genus remains a
1342 restriction the QML lookup does not bypass. URL-like targets, HTML
1343 filenames, and titles containing spaces keep their ordinary
1344 interpretation.
1345
1346 QML lookup uses the import list and logical module of the QML type
1347 enclosing \a relative to interpret references in member documentation.
1348 General lookup keeps \a relative as its context. Ordinary QML name
1349 lookup takes precedence over import-alias expansion. Explicit QML genus
1350 links retain type-only lookup as a fallback.
1351
1352 The \a searchFlags preserve link criteria, including restrictions to
1353 attached properties, through both QML and general lookup.
1354
1355 A fragment in a QML dot-path target must exist in the target
1356 documentation. When \a ref is non-null, it receives the fragment's
1357 identifier on success.
1358*/
1359const Node *QDocDatabase::findNodeForTarget(const QString &target, const Node *relative,
1360 Genus genus, const QString &moduleName,
1361 QString *ref, LinkReferenceOrigin origin,
1362 int searchFlags)
1363{
1364 if (target.isEmpty())
1365 return relative;
1366
1367 Tree *domain = moduleName.isEmpty() ? nullptr : findTree(moduleName);
1368 const int flags = SearchBaseClasses | SearchEnumValues | searchFlags;
1369
1370 const Node *qmlContext = relative;
1371 while (qmlContext && !qmlContext->isQmlType()) {
1372 const Node *parent = qmlContext->parent();
1373 if (!parent || parent->genus() != Genus::QML)
1374 break;
1375 qmlContext = parent;
1376 }
1377
1378 QStringList targetPath = Utilities::pathAndFragment(target);
1379 const QString first = targetPath.first().trimmed();
1380 QString qmlName = first;
1381 Parameters::extractParameters(qmlName);
1382
1383 const bool qmlDotPath =
1384 origin == LinkReferenceOrigin::Explicit
1385 && (genus == Genus::DontCare || genus == Genus::QML)
1386 && qmlName.contains('.'_L1)
1387 && !qmlName.contains("::"_L1)
1388 && !qmlName.contains("://"_L1)
1389 && !qmlName.contains(' '_L1)
1390 && !qmlName.endsWith(".html"_L1);
1391
1392 auto withFragment = [targetPath, ref](const Node *node) -> const Node * {
1393 QString localRef;
1394 node = setReferenceFromFragment(targetPath.value(1), node, localRef);
1395 if (node && ref)
1396 *ref = localRef;
1397 return node;
1398 };
1399
1400 auto findQmlDotPathNode = [this, qmlContext, domain, &withFragment, genus, flags](const QString &path)
1401 -> const Node *
1402 {
1403 const Node *node = findQmlNode(path, qmlContext, FindFlags::fromInt(flags), domain);
1404
1405 if (!node && qmlContext && qmlContext->isQmlType()) {
1406 const QmlTypeNode *qmlRelative = static_cast<const QmlTypeNode *>(qmlContext);
1407 const QStringList pieces = path.split('.'_L1);
1408 if (pieces.size() >= 2) {
1409 for (const ImportRec &import : qmlRelative->importList()) {
1410 if (import.m_importId.isEmpty() || import.m_importId != pieces.first())
1411 continue;
1412 const QString qmid = import.m_importUri.isEmpty()
1413 ? import.m_moduleName
1414 : import.m_importUri;
1415 const QString qualifiedPath = qmid + path.mid(pieces.first().size());
1416 node = findQmlNode(qualifiedPath, qmlContext, FindFlags::fromInt(flags),
1417 domain);
1418 if (node)
1419 break;
1420 }
1421 }
1422 }
1423
1424 if (!node && genus == Genus::QML)
1425 node = findTypeNode(path, qmlContext, genus);
1426
1427 // The type-only fallback can return a node from another tree.
1428 if (node && domain && node->tree() != domain)
1429 node = nullptr;
1430 return withFragment(node);
1431 };
1432
1433 if (domain) {
1434 const Node *node = nullptr;
1435 if (target.endsWith(".html"_L1)) {
1436 node = domain->findNodeByNameAndType(QStringList(target), &Node::isPageNode);
1437 } else if (target.endsWith(')'_L1)) {
1438 QString function = target;
1439 const QString signature = Parameters::extractParameters(function);
1440 const Parameters parameters(signature.trimmed());
1441
1442 const QStringList path = function.split("::"_L1);
1443 if (parameters.isValid())
1444 node = domain->findFunctionNode(path, parameters, nullptr, genus);
1445 }
1446 if (node)
1447 return node;
1448
1449 if (qmlDotPath) {
1450 if (const Node *qmlNode = findQmlDotPathNode(first))
1451 return qmlNode;
1452 }
1453
1454 QStringList nodePath = target.split("::"_L1);
1455 if (relative && relative->tree()->physicalModuleName() != domain->physicalModuleName())
1456 relative = nullptr;
1457 QString localRef;
1458 const Node *result =
1459 domain->findNodeForTarget(nodePath, {}, relative, flags, genus, localRef);
1460 if (result && ref)
1461 *ref = localRef;
1462 return result;
1463 }
1464
1465 if (target.endsWith(".html"_L1))
1466 return findNodeByNameAndType(QStringList(target), &Node::isPageNode);
1467
1468 if (target.endsWith(')'_L1)) {
1469 const Node *node = findFunctionNode(target, relative, genus);
1470 if (node)
1471 return node;
1472 }
1473
1474 if (qmlDotPath) {
1475 if (const Node *qmlNode = findQmlDotPathNode(first))
1476 return qmlNode;
1477 }
1478
1479 QString localRef;
1480 const Node *node = findNodeForTarget(targetPath, relative, genus, localRef, flags);
1481 if (node) {
1482 if (ref)
1483 *ref = localRef;
1484 return node;
1485 }
1486
1487 return findPageNodeByTitle(target);
1488}
1489
1491{
1492 QStringList result;
1493 CNMap *m = primaryTree()->getCollectionMap(NodeType::Group);
1494
1495 if (!m)
1496 return result;
1497
1498 for (auto it = m->cbegin(); it != m->cend(); ++it)
1499 if (it.value()->members().contains(node))
1500 result << it.key();
1501
1502 return result;
1503}
1504
1505/*!
1506 Reads and parses the qdoc index files listed in \a indexFiles.
1507 */
1508void QDocDatabase::readIndexes(const QStringList &indexFiles)
1509{
1510 QStringList filesToRead;
1511 for (const QString &file : indexFiles) {
1512 QString fn = file.mid(file.lastIndexOf(QChar('/')) + 1);
1513 if (!isLoaded(fn))
1514 filesToRead << file;
1515 else
1516 qCCritical(lcQdoc) << "Index file" << file << "is already in memory.";
1517 }
1518 QDocIndexFiles::qdocIndexFiles()->readIndexes(filesToRead);
1519}
1520
1521/*!
1522 Generates a qdoc index file and writes it to \a fileName. The
1523 index file is generated with the parameters \a url, \a title,
1524 and \a context, which supplies publication locations and serialization
1525 policy independently of the rendering implementation.
1526 */
1527void QDocDatabase::generateIndex(const QString &fileName, const QString &url, const QString &title,
1528 const IndexSerializationContext &context)
1529{
1530 QString t = fileName.mid(fileName.lastIndexOf(QChar('/')) + 1);
1531 primaryTree()->setIndexFileName(t);
1532 QDocIndexFiles::qdocIndexFiles()->generateIndex(fileName, url, title, context);
1533 QDocIndexFiles::destroyQDocIndexFiles();
1534}
1535
1536/*!
1537 Returns the collection node representing the module that \a relative
1538 node belongs to, or \c nullptr if there is no such module in the
1539 primary tree.
1540*/
1542{
1543 NodeType moduleType{NodeType::Module};
1544 QString moduleName;
1545 switch (relative->genus())
1546 {
1547 case Genus::CPP:
1548 moduleType = NodeType::Module;
1549 moduleName = relative->physicalModuleName();
1550 break;
1551 case Genus::QML:
1552 moduleType = NodeType::QmlModule;
1553 moduleName = relative->logicalModuleName();
1554 break;
1555 default:
1556 return nullptr;
1557 }
1558 if (moduleName.isEmpty())
1559 return nullptr;
1560
1561 return primaryTree()->getCollection(moduleName, moduleType);
1562}
1563
1564/*!
1565 Finds all the collection nodes of the specified \a type
1566 and merges them into the collection node map \a cnm. Nodes
1567 that match the \a relative node are not included.
1568 */
1569void QDocDatabase::mergeCollections(NodeType type, CNMap &cnm, const Node *relative)
1570{
1571 cnm.clear();
1572 CNMultiMap cnmm;
1573 for (auto *tree : searchOrder()) {
1574 CNMap *m = tree->getCollectionMap(type);
1575 if (m && !m->isEmpty()) {
1576 for (auto it = m->cbegin(); it != m->cend(); ++it) {
1577 if (!it.value()->isInternal())
1578 cnmm.insert(it.key(), it.value());
1579 }
1580 }
1581 }
1582 if (cnmm.isEmpty())
1583 return;
1584 static const QRegularExpression singleDigit("\\b([0-9])\\b");
1585 const QStringList keys = cnmm.uniqueKeys();
1586 for (const auto &key : keys) {
1587 const QList<CollectionNode *> values = cnmm.values(key);
1588 CollectionNode *n = nullptr;
1589 for (auto *value : values) {
1590 if (value && value->wasSeen() && value != relative) {
1591 n = value;
1592 break;
1593 }
1594 }
1595 if (n) {
1596 if (values.size() > 1) {
1597 for (CollectionNode *value : values) {
1598 if (value != n) {
1599 // Allow multiple (major) versions of QML modules
1600 if ((n->isQmlModule())
1601 && n->logicalModuleIdentifier() != value->logicalModuleIdentifier()) {
1602 if (value->wasSeen() && value != relative)
1603 cnm.insert(value->fullTitle().toLower(), value);
1604 continue;
1605 }
1606 for (Node *t : value->members())
1607 n->addMember(t);
1608 }
1609 }
1610 }
1611 QString sortKey = n->fullTitle().toLower();
1612 if (sortKey.startsWith("the "))
1613 sortKey.remove(0, 4);
1614 sortKey.replace(singleDigit, "0\\1");
1615 cnm.insert(sortKey, n);
1616 }
1617 }
1618}
1619
1620/*!
1621 Finds all the collection nodes with the same name
1622 and type as \a c and merges their members into the
1623 members list of \a c.
1624
1625 For QML modules, only nodes with matching
1626 module identifiers are merged to avoid merging
1627 modules with different (major) versions.
1628 */
1630{
1631 if (c == nullptr)
1632 return;
1633
1634 // REMARK: This form of merging is usually called during the
1635 // generation phase om-the-fly when a source-of-truth collection
1636 // is required.
1637 // In practice, this means a collection could be merged many, many
1638 // times during the lifetime of a generation.
1639 // To avoid repeating the merging process each time, which could
1640 // be time consuming, we use a small flag that is set directly on
1641 // the collection to bail-out early.
1642 //
1643 // The merging process is only meaningful for collections when the
1644 // collection references are spread troughout multiple projects.
1645 // The part of information that exists in other project is read
1646 // before the generation phase, such that when the generation
1647 // phase comes, we already have all the information we need for
1648 // merging such that we can consider all version of a certain
1649 // collection node immutable, making the caching inherently
1650 // correct at any point of the generation.
1651 //
1652 // This implies that this operation is unsafe if it is performed
1653 // before all the index files are loaded.
1654 // Indeed, this is a prerequisite, with the current structure, to
1655 // perform this optmization.
1656 //
1657 // At the current time, this is true and is expected not to
1658 // change.
1659 //
1660 // Do note that this is not applied to the other overload of
1661 // mergeCollections as we cannot as safely ensure its consistency
1662 // and, as the result of the merging depends on multiple
1663 // parameters, it would require an actual memoization of the call.
1664 //
1665 // Note that this is a defensive optimization and we are assuming
1666 // that it is effective based on heuristical data. As this is
1667 // expected to disappear, at least in its current form, in the
1668 // future, a more thorough analysis was not performed.
1669 if (c->isMerged()) {
1670 return;
1671 }
1672
1673 for (auto *tree : searchOrder()) {
1674 CollectionNode *cn = tree->getCollection(c->name(), c->nodeType());
1675 if (cn && cn != c) {
1676 if ((cn->isQmlModule())
1677 && cn->logicalModuleIdentifier() != c->logicalModuleIdentifier())
1678 continue;
1679
1680 for (auto *node : cn->members())
1681 c->addMember(node);
1682
1683 // REMARK: The merging process is performed to ensure that
1684 // references to the collection in external projects are
1685 // taken into account before consuming the collection.
1686 //
1687 // This works by having QDoc construct empty collections
1688 // as soon as a reference to a collection is encountered
1689 // and filling details later on when its definition is
1690 // found.
1691 //
1692 // This initially-empty collection is always saved to the
1693 // primaryTree and it is the collection that is directly
1694 // accessible to consumers during the generation process.
1695 //
1696 // Nonetheless, when the definition for the collection is
1697 // not in the same project as the one that is being
1698 // compiled, its details will never be filled in.
1699 //
1700 // Indeed, the details will live in the index file for the
1701 // project where the collection is defined, if any, and
1702 // the node for it, which has complete information, will
1703 // live in some non-primaryTree.
1704 //
1705 // The merging process itself is used by consumers during
1706 // the generation process because they access the
1707 // primaryTree version of the collection expecting a
1708 // source-of-truth.
1709 // To ensure that this is the case for usages that
1710 // requires linking, we need to merge not only the members
1711 // of the collection that reside in external versions of
1712 // the collection; but some of the data that reside in the
1713 // definition of the collection intself, namely the title
1714 // and the url.
1715 //
1716 // A collection that contains the data of a definition is
1717 // always marked as seen, hence we use that to discern
1718 // whether we are working with a placeholder node or not,
1719 // and fill in the data if we encounter a node that
1720 // represents a definition.
1721 //
1722 // The way in which QDoc works implies that collection are
1723 // globally scoped between projects.
1724 // The repetition of the definition for the same
1725 // collection is warned for as a duplicate documentation,
1726 // such that we can expect a single valid source of truth
1727 // for a given collection in each project.
1728 // It is currently unknown if this warning is applicable
1729 // when the repeated collection is defined in two
1730 // different projects.
1731 //
1732 // As QDoc implicitly would not correctly support this
1733 // case, we assume that only one declaration exists for
1734 // each collection, such that the first encoutered one
1735 // must be the source of truth and that there is no need
1736 // to copy any data after the first copy is performed.
1737 // KLUDGE: Note that this process is done as a hackish
1738 // solution to QTBUG-104237 and should not be considered
1739 // final or dependable.
1740 if (!c->wasSeen() && cn->wasSeen()) {
1741 c->markSeen();
1742 c->setTitle(cn->title());
1743 c->setUrl(cn->url());
1744 c->setResolvedPhysicalModuleName(cn->tree()->physicalModuleName());
1745 }
1746 }
1747 }
1748
1750}
1751
1752/*!
1753 Returns the node to a piece of QML API documentation that corresponds to
1754 the given \a path, or \c nullptr if the path cannot be resolved.
1755 The \a relative node specifies where the link or reference was used.
1756 The \a flags let the caller specify or restrict the types of nodes to
1757 find or prioritize, such as attached properties instead of regular
1758 properties.
1759
1760 Searches only \a tree when provided, or the whole forest otherwise.
1761
1762 This function doesn't handle the use of fragments to refer to elements in
1763 the target documentation.
1764*/
1765const Node *QDocDatabase::findQmlNode(const QString &path, const Node *relative, FindFlags flags,
1766 Tree *tree)
1767{
1768 QString qmlPath = path;
1769 const QString signature = Parameters::extractParameters(qmlPath);
1770 const bool findFunction = !signature.isNull();
1771 QStringList pieces;
1772 for (const QString &piece : qmlPath.split('.'_L1))
1773 pieces.append(piece.split("::"_L1));
1774
1775 // Try to resolve a leading QML module name.
1776 QString candidateName;
1777 const Node *moduleNode = nullptr;
1778 qsizetype modulePrefixSize = 0;
1779 for (; modulePrefixSize < pieces.size(); ++modulePrefixSize) {
1780 candidateName += pieces.at(modulePrefixSize);
1781 const Node *node = tree
1782 ? tree->findNodeByNameAndType({candidateName}, &Node::isQmlModule)
1783 : findNodeByNameAndType({candidateName}, &Node::isQmlModule);
1784 if (!node)
1785 break;
1786
1787 moduleNode = node;
1788 candidateName += '.'_L1;
1789 }
1790
1791 if (modulePrefixSize == pieces.size())
1792 return findFunction ? nullptr : moduleNode;
1793
1794 QmlTypeNode *qmlType = nullptr;
1795 if (moduleNode) {
1796 pieces.remove(0, modulePrefixSize);
1797 qmlType = findQmlType(moduleNode->name(), pieces.takeFirst(), relative, tree);
1798 } else
1799 qmlType = findQmlType(pieces.takeFirst(), relative, tree);
1800
1801 if (!qmlType || pieces.isEmpty())
1802 return findFunction ? nullptr : qmlType;
1803
1804 const auto searchType = flags.testFlag(QmlAttachedProperties)
1806 const auto findProperty = [searchType](const QmlTypeNode *type, const QString &name)
1807 -> const QmlPropertyNode * {
1808 const QmlPropertyNode *property = type->hasQmlProperty(name, searchType);
1809 if (!property && searchType == Aggregate::UnattachedProperties)
1810 property = type->hasQmlProperty(name, Aggregate::AttachedProperties);
1811 return property;
1812 };
1813
1814 // Consume a property only when its type can be followed. Otherwise the
1815 // remaining name may be a documented group such as "values.integer".
1816 while (pieces.size() > 1) {
1817 const QmlPropertyNode *property = findProperty(qmlType, pieces.first());
1818 if (!property)
1819 break;
1820
1821 QmlTypeNode *const nextType = moduleNode
1822 ? findQmlType(moduleNode->name(), property->dataType(), relative, tree)
1823 : findQmlType(property->dataType(), relative, tree);
1824 if (!nextType)
1825 break;
1826
1827 qmlType = nextType;
1828 pieces.removeFirst();
1829 }
1830
1831 if (findFunction) {
1832 if (flags.testFlag(QmlAttachedProperties) || pieces.size() != 1)
1833 return nullptr;
1834 const Parameters parameters(signature.trimmed());
1835 if (!parameters.isValid())
1836 return nullptr;
1837 return qmlType->findFunctionChild(pieces.first(), parameters);
1838 }
1839
1840 const QString memberName = pieces.join('.'_L1);
1841 if (const QmlPropertyNode *property = findProperty(qmlType, memberName))
1842 return property;
1843
1844 if (flags.testFlag(QmlAttachedProperties))
1845 return nullptr;
1846 return qmlType->findChildNode(memberName, Genus::QML);
1847}
1848
1849/*!
1850 Resolves \a fragment in the documentation of \a node and stores its
1851 reference in \a ref. Returns \c nullptr if the fragment cannot be
1852 resolved. An empty fragment leaves the node unchanged.
1853*/
1854const Node *QDocDatabase::setReferenceFromFragment(const QString &fragment, const Node *node,
1855 QString &ref)
1856{
1857 if (!node || fragment.isEmpty())
1858 return node;
1859
1860 ref = node->tree()->getRef(fragment, node);
1861 return ref.isEmpty() ? nullptr : node;
1862}
1863
1864/*!
1865 Searches for the node that matches the path in \a atom and the
1866 specified \a genus. The \a relative node is used if the first
1867 leg of the path is empty, i.e. if the path begins with '#'.
1868 The function also sets \a ref if there remains an unused leg
1869 in the path after the node is found. The node is returned as
1870 well as the \a ref. If the returned node pointer is null,
1871 \a ref is also not valid.
1872 */
1873const Node *QDocDatabase::findNodeForAtom(const Atom *a, const Node *relative, QString &ref,
1874 Genus genus)
1875{
1876 const Node *node = nullptr;
1877
1878 Atom *atom = const_cast<Atom *>(a);
1879 QStringList targetPath = Utilities::pathAndFragment(atom->string());
1880 QString first = targetPath.first().trimmed();
1881 const QString fragment = targetPath.value(1);
1882
1883 Tree *domain = nullptr;
1884
1885 if (atom->isLinkAtom() || atom->type() == Atom::Link) {
1886 if (auto *atomDomain = atom->domain())
1887 domain = atomDomain;
1888 if (atom->genus() != Genus::DontCare)
1889 genus = atom->genus();
1890
1891 QString qmlName = first;
1892 Parameters::extractParameters(qmlName);
1893 if (!qmlName.contains("://"_L1) && !qmlName.contains(' '_L1)
1894 && !qmlName.endsWith(".html"_L1) && qmlName.contains('.'_L1)) {
1895 const auto flags = FindFlags::fromInt(a->flags());
1896 if (const Node *found = findQmlNode(first, relative, flags))
1897 return setReferenceFromFragment(fragment, found, ref);
1898 }
1899 }
1900
1901 if (first.isEmpty())
1902 node = relative; // search for a target on the current page.
1903 else if (domain) {
1904 if (first.endsWith(".html"))
1905 node = domain->findNodeByNameAndType(QStringList(first), &Node::isPageNode);
1906 else if (first.endsWith(QChar(')'))) {
1907 QString function = first;
1908 const QString signature = Parameters::extractParameters(function);
1909 const Parameters parameters(signature.trimmed());
1910
1911 const QStringList path = function.split("::"_L1);
1912 if (parameters.isValid())
1913 node = domain->findFunctionNode(path, parameters, nullptr, genus);
1914 }
1915 if (node == nullptr) {
1916 int flags = SearchBaseClasses | SearchEnumValues;
1917 QStringList nodePath = first.split("::");
1918 QString target;
1919 targetPath.removeFirst();
1920 if (!targetPath.isEmpty())
1921 target = targetPath.takeFirst();
1922 if (relative && relative->tree()->physicalModuleName() != domain->physicalModuleName())
1923 relative = nullptr;
1924 return domain->findNodeForTarget(nodePath, target, relative, flags, genus, ref);
1925 }
1926 } else {
1927 if (first.endsWith(".html"))
1928 node = findNodeByNameAndType(QStringList(first), &Node::isPageNode);
1929 else if (first.endsWith(QChar(')')))
1930 node = findFunctionNode(first, relative, genus);
1931 if (node == nullptr) {
1932 // For QML contexts with qualified names containing ".", use the same logic as findTypeNode
1933 if (genus == Genus::QML && first.contains('.') && !first.contains("::")) {
1934 // Try import-aware lookup using findTypeNode logic
1935 node = findTypeNode(first, relative, genus);
1936 if (node)
1937 return setReferenceFromFragment(fragment, node, ref);
1938 }
1939 return findNodeForTarget(targetPath, relative, genus, ref, atom->flags());
1940 }
1941 }
1942
1943 if (node != nullptr && ref.isEmpty()) {
1944 if (!node->url().isEmpty())
1945 return node;
1946 targetPath.removeFirst();
1947 if (!targetPath.isEmpty()) {
1948 ref = node->root()->tree()->getRef(targetPath.first(), node);
1949 if (ref.isEmpty())
1950 node = nullptr;
1951 }
1952 }
1953 return node;
1954}
1955
1956/*!
1957 Updates navigation (previous/next page links and the navigation parent)
1958 for pages listed in the TOC, specified by the \c navigation.toctitles
1959 configuration variable.
1960
1961 if \c navigation.toctitles.inclusive is \c true, include also the TOC
1962 page(s) themselves as a 'root' item in the navigation bar (breadcrumbs)
1963 that are generated for HTML output.
1964*/
1966{
1967 // Restrict searching only to the local (primary) tree
1968 QList<Tree *> searchOrder = this->searchOrder();
1970
1971 const QString configVar = CONFIG_NAVIGATION +
1972 Config::dot +
1974
1975 // TODO: [direct-configuration-access]
1976 // The configuration is currently a singleton with some generally
1977 // global mutable state.
1978 //
1979 // Accessing the data in this form complicates testing and
1980 // requires tests that inhibit any test parallelization, as the
1981 // tests are not self contained.
1982 //
1983 // This should be generally avoived. Possibly, we should strive
1984 // for Config to be a POD type that generally is scoped to
1985 // main and whose data is destructured into dependencies when
1986 // the dependencies are constructed.
1987 bool inclusive{Config::instance().get(
1988 configVar + Config::dot + CONFIG_INCLUSIVE).asBool()};
1989
1990 // TODO: [direct-configuration-access]
1991 const auto tocTitles{Config::instance().get(configVar).asStringList()};
1992
1993 for (const auto &tocTitle : tocTitles) {
1994 if (const auto candidateTarget = findNodeForTarget(tocTitle, nullptr); candidateTarget && candidateTarget->isPageNode()) {
1995 auto tocPage{static_cast<const PageNode*>(candidateTarget)};
1996
1997 Text body = tocPage->doc().body();
1998
1999 auto *atom = body.firstAtom();
2000
2001 std::pair<PageNode *, QString> prev { nullptr, QString() };
2002
2003 std::stack<const PageNode *> tocStack;
2004 tocStack.push(inclusive ? tocPage : nullptr);
2005
2006 bool inItem = false;
2007
2008 // TODO: Understand how much we use this form of looping over atoms.
2009 // If it is used a few times we might consider providing
2010 // an iterator for Text to make use of a simpler
2011 // range-for loop.
2012 while (atom) {
2013 switch (atom->type()) {
2014 case Atom::ListItemLeft:
2015 // Not known if we're going to have a link, push a temporary
2016 tocStack.push(nullptr);
2017 inItem = true;
2018 break;
2019 case Atom::ListItemRight:
2020 tocStack.pop();
2021 inItem = false;
2022 break;
2023 case Atom::Link: {
2024 if (!inItem)
2025 break;
2026
2027 // TODO: [unnecessary-output-parameter]
2028 // We currently need an lvalue string to
2029 // pass to findNodeForAtom, as the
2030 // outparameter ref.
2031 //
2032 // Apart from the general problems with output
2033 // parameters, we shouldn't be forced to
2034 // instanciate an unnecessary object at call
2035 // site.
2036 //
2037 // Understand what the correct way to avoid this is.
2038 // This requires changes to findNodeForAtom
2039 // and should be addressed in the context of
2040 // revising that method.
2041 QString unused{};
2042 // TODO: Having to const cast is really a code
2043 // smell and could result in undefined
2044 // behavior in some specific cases (e.g point
2045 // to something that is actually const).
2046 //
2047 // We should understand how to sequence the
2048 // code so that we have access to mutable data
2049 // when we need it and "freeze" the data
2050 // afterwards.
2051 //
2052 // If it we expect this form of mutability at
2053 // this point we should expose a non-const API
2054 // for the database, possibly limited to a
2055 // very specific scope of execution.
2056 //
2057 // Understand what the correct sequencing for
2058 // this processing is and revise this part.
2059 auto candidatePage = const_cast<Node *>(findNodeForAtom(atom, nullptr, unused));
2060 if (!candidatePage || !candidatePage->isPageNode()) break;
2061
2062 auto page{static_cast<PageNode*>(candidatePage)};
2063
2064 // ignore self-references
2065 if (page == prev.first) break;
2066
2067 if (prev.first) {
2068 prev.first->setLink(
2069 Node::NextLink,
2070 page->title(),
2071 // TODO: [possible-assertion-failure][imprecise-types][atoms-link]
2072 // As with other structures in QDoc we
2073 // are able to call methods that are
2074 // valid only on very specific states.
2075 //
2076 // For some of those calls we have
2077 // some defensive programming measures
2078 // that allow us to at least identify
2079 // the error during debugging, while
2080 // for others this may currently hide
2081 // some logic error.
2082 //
2083 // To avoid those cases, we should
2084 // strive to move those cases to a
2085 // compilation error, requiring a
2086 // statically analyzable state that
2087 // represents the current model.
2088 //
2089 // This would ensure that those
2090 // lingering class of bugs are
2091 // eliminated completely, forces a
2092 // more explicit codebase where the
2093 // current capabilities do not depend
2094 // on runtime values might not be
2095 // generally visible, and does not
2096 // require us to incur into the
2097 // required state, which may be rare,
2098 // simplifying our abilities to
2099 // evaluate all possible states.
2100 //
2101 // For linking atoms, LinkAtom is
2102 // available and might be a good
2103 // enough solution to move linkText
2104 // to.
2105 atom->linkText()
2106 );
2107 page->setLink(
2108 Node::PreviousLink,
2109 prev.first->title(),
2110 prev.second
2111 );
2112 }
2113
2114 if (page == tocPage)
2115 break;
2116
2117 // Find the navigation parent from the stack; we may have null pointers
2118 // for non-link list items, so skip those.
2119 qsizetype popped = 0;
2120 while (tocStack.size() > 1 && !tocStack.top()) {
2121 tocStack.pop();
2122 ++popped;
2123 }
2124
2125 page->setNavigationParent(tocStack.empty() ? nullptr : tocStack.top());
2126
2127 while (--popped > 0)
2128 tocStack.push(nullptr);
2129
2130 tocStack.push(page);
2131 // TODO: [possible-assertion-failure][imprecise-types][atoms-link]
2132 prev = { page, atom->linkText() };
2133 }
2134 break;
2135
2136 case Atom::AnnotatedList:
2137 case Atom::GeneratedList: {
2138 if (const auto *cn = getCollectionNode(atom->string(), NodeType::Group)) {
2139 const auto sortOrder{Generator::sortOrder(atom->strings().last())};
2140 NodeList members{cn->members()};
2141 // Drop non-page nodes and index nodes so that we do not generate navigational
2142 // links pointing outside of this documentation set.
2143 members.erase(std::remove_if(members.begin(), members.end(),
2144 [](const Node *n) {
2145 return n->isIndexNode() || !n->isPageNode() || n->isExternalPage();
2146 }), members.end());
2147 if (members.isEmpty())
2148 break;
2149
2150 if (sortOrder == Qt::DescendingOrder)
2151 std::sort(members.rbegin(), members.rend(), Node::nodeSortKeyOrNameLessThan);
2152 else
2153 std::sort(members.begin(), members.end(), Node::nodeSortKeyOrNameLessThan);
2154
2155 // `members` now has local PageNode pointers, adjust prev/next links for each.
2156 // Do not set a navigation parent node as group members use the group node as
2157 // their nav. parent.
2158 for (auto *m : members) {
2159 auto *page = static_cast<PageNode *>(m);
2160 if (prev.first) {
2161 prev.first->setLink(Node::NextLink, page->title(), page->fullName());
2162 page->setLink(Node::PreviousLink, prev.first->title(), prev.second);
2163 }
2164 prev = { page, page->fullName() };
2165 }
2166 }
2167 }
2168 break;
2169
2170 default:
2171 break;
2172 }
2173
2174 atom = atom->next();
2175 }
2176 } else {
2177 Config::instance().get(configVar).location()
2178 .warning(QStringLiteral("Failed to find table of contents with title '%1'")
2179 .arg(tocTitle));
2180 }
2181 }
2182
2183 // Restore search order
2184 setSearchOrder(searchOrder);
2185}
2186
2187QT_END_NAMESPACE
void appendToRelatedByProxy(const NodeList &t)
Appends the list of node pointers to the list of elements that are related to this Aggregate but are ...
Definition aggregate.h:75
void resolveRelates()
Adopts each non-aggregate C++ node (function/macro, typedef, enum, variable, or a shared comment node...
void resolveQmlInheritance()
Resolves the inheritance information for all QML type children of this aggregate.
void normalizeOverloads()
Sorts the lists of overloads in the function map and assigns overload numbers.
NodeList & relatedByProxy()
Definition aggregate.h:76
@ AttachedProperties
Definition aggregate.h:27
@ UnattachedProperties
Definition aggregate.h:26
void findAllNamespaces(NodeMultiMap &namespaces)
For each child of this node, if the child is a namespace node, insert the child into the namespaces m...
void markUndocumentedChildrenInternal()
Mark all child nodes that have no documentation as having internal status.
FunctionNode * findFunctionChild(const FunctionNode *clone)
Returns the function node that is a child of this node, such that the function described has the same...
The Atom class is the fundamental unit for representing documents internally.
Definition atom.h:19
AtomType type() const
Return the type of this atom.
Definition atom.h:146
@ Link
Definition atom.h:65
virtual bool isLinkAtom() const
Definition atom.h:154
virtual Tree * domain()
Definition atom.h:156
virtual Genus genus()
Definition atom.h:155
A class for holding the members of a collection of doc pages.
This node is used to represent any kind of function being documented.
This class represents a C++ namespace.
This class provides exclusive access to the qdoc database, which consists of a forrest of trees and a...
const Node * findTypeNode(const QString &type, const Node *relative, Genus genus)
This function is called for autolinking to a type, which could be a function return type or a paramet...
NodeMapMap & getFunctionIndex()
Returns the function index.
const NodeMultiMap & getClassMap(const QString &key)
Find the key in the map of new class maps, and return a reference to the value, which is a NodeMap.
QmlTypeNode * findQmlType(const QString &qmid, const QString &name, const Node *relative=nullptr, Tree *tree=nullptr)
Returns the QML type node identified by the QML module id qmid and QML type name, or nullptr if no ty...
const Node * findQmlNode(const QString &path, const Node *relative, FindFlags flags, Tree *tree=nullptr)
Returns the node to a piece of QML API documentation that corresponds to the given path,...
const NodeMultiMap & getQmlTypeMap(const QString &key)
Find the key in the map of new QML type maps, and return a reference to the value,...
void resolveNamespaces()
Multiple namespace nodes for namespace X can exist in the qdoc database in different trees.
TextToNodeMap & getLegaleseTexts()
Returns a reference to the collection of legalese texts.
const Node * findNodeForTarget(const QString &target, const Node *relative, Genus genus, const QString &moduleName, QString *ref=nullptr, LinkReferenceOrigin origin=LinkReferenceOrigin::Auto, int searchFlags=0)
Finds the node for target relative to relative, with genus and module scoping.
NodeMultiMap & getAttributions()
Returns a reference to the multimap of attribution nodes.
static void destroyQdocDB()
Destroys the singleton.
NodeMultiMap & getQmlTypesWithObsoleteMembers()
Returns a reference to the map of QML types with obsolete members.
NodeMultiMap & getObsoleteQmlTypes()
Returns a reference to the map of obsolete QML types.
QmlTypeNode * findQmlType(const ImportRec &import, const QString &name, const Node *relative=nullptr)
const FunctionNode * findFunctionNode(const QString &target, const Node *relative, Genus genus)
Finds the function node for the qualified function path in target and returns a pointer to it.
static QDocDatabase * qdocDB()
Creates the singleton.
void generateIndex(const QString &fileName, const QString &url, const QString &title, const IndexSerializationContext &context)
Generates a qdoc index file and writes it to fileName.
void resolveBaseClasses()
NodeMultiMap & getQmlTypes()
Returns a reference to the multimap of QML types.
NodeMultiMap & getClassesWithObsoleteMembers()
Returns a reference to the map of C++ classes with obsolete members.
NodeMultiMap & getQmlValueTypes()
Returns a reference to the map of QML basic types.
NodeMultiMap & getCppClasses()
Returns a reference to the map of all C++ classes.
QStringList groupNamesForNode(Node *node)
NamespaceNode * primaryTreeRoot()
Returns a pointer to the root node of the primary tree.
void readIndexes(const QStringList &indexFiles)
Reads and parses the qdoc index files listed in indexFiles.
void resolveConceptUsers()
Builds the concept-to-users reverse index after parsing finishes and before any generator runs.
const Node * findNodeForTarget(const QString &target, const Node *relative)
Finds the node that will generate the documentation that contains the target and returns a pointer to...
const Node * findNodeForAtom(const Atom *atom, const Node *relative, QString &ref, Genus genus=Genus::DontCare)
Searches for the node that matches the path in atom and the specified genus.
void mergeCollections(NodeType type, CNMap &cnm, const Node *relative)
Finds all the collection nodes of the specified type and merges them into the collection node map cnm...
NodeMultiMap & getNamespaces()
Returns a reference to the namespace map.
QmlTypeNode * findQmlTypeInPrimaryTree(const QString &qmid, const QString &name)
Returns the QML node identified by the QML module id qmid and name, searching in the primary tree onl...
const NodeMultiMap & getSinceMap(const QString &key)
Find the key in the map of new {since} maps, and return a reference to the value, which is a NodeMult...
NodeMultiMap & getExamples()
Returns a reference to the multimap of example nodes.
void processForest()
This function calls a set of functions for each tree in the forest that has not already been analyzed...
void(QDocDatabase::*)(Aggregate *) FindFunctionPtr
void updateNavigation()
Updates navigation (previous/next page links and the navigation parent) for pages listed in the TOC,...
void resolveStuff()
Performs several housekeeping tasks prior to generating the documentation.
Tree * primaryTree()
NodeMultiMap & getObsoleteClasses()
Returns a reference to the map of obsolete C++ clases.
const CollectionNode * getModuleNode(const Node *relative)
Returns the collection node representing the module that relative node belongs to,...
void resolveProxies()
Each instance of class Tree that represents an index file must be traversed to find all instances of ...
void mergeCollections(CollectionNode *c)
Finds all the collection nodes with the same name and type as c and merges their members into the mem...
void setLocalSearch()
A class representing a forest of Tree objects.
This class imports QDoc index files and serializes index sections for module indexes and WebXML outpu...
const ImportList & importList() const
Definition qmltypenode.h:51
This class constructs and maintains a tree of instances of the subclasses of Node.
Definition tree.h:59
void markDontDocumentNodes()
The {don't document} map has been loaded with the names of classes and structs in the current module ...
Definition tree.cpp:1677
NodeList & proxies()
Definition tree.h:80
void resolveProperties()
Resolves access functions associated with each PropertyNode stored in m_unresolvedPropertyMap,...
Definition tree.cpp:288
#define CONFIG_TOCTITLES
Definition config.h:466
#define CONFIG_NOLINKERRORS
Definition config.h:435
#define CONFIG_NAVIGATION
Definition config.h:434
#define CONFIG_INCLUSIVE
Definition config.h:421
NodeType
Definition genustypes.h:165
QMultiMap< QString, CollectionNode * > CNMultiMap
Definition node.h:53
QList< Node * > NodeList
Definition node.h:45
QMap< QString, NodeMultiMap > NodeMultiMapMap
Definition node.h:51
QMap< QString, Node * > NodeMap
Definition node.h:48
QMap< QString, NodeMap > NodeMapMap
Definition node.h:49
QMap< QString, CollectionNode * > CNMap
Definition node.h:52
static void collectConceptReferences(const Node *node, QStringList &refs)
Gathers the fully-qualified concept names referenced by node.
static void registerConceptUsersUnder(Aggregate *parent, QDocDatabase &db)
Walks every documented node under parent and registers each constrained item as a member of the conce...
static NodeMultiMap emptyNodeMultiMap_
QT_BEGIN_NAMESPACE typedef QMultiMap< Text, const Node * > TextToNodeMap
@ QmlAttachedProperties
@ SearchBaseClasses
@ SearchEnumValues
@ TypesOnly
QList< ImportRec > ImportList
Definition qmltypenode.h:20
QMultiMap< QString, Node * > NodeMultiMap
Definition generator.h:36
bool isEmpty() const
Definition importrec.h:30
The Node class is the base class for all the nodes in QDoc's parse tree.
bool isQmlType() const
Returns true if the node type is QmlType or QmlValueType.
Definition node.h:123
Genus genus() const override
Returns this node's Genus.
Definition node.h:85
virtual bool isPageNode() const
Returns true if this node represents something that generates a documentation page.
Definition node.h:150
Aggregate * parent() const
Returns the node's parent pointer, that is, the aggregate under which the node is documented.
Definition node.h:211
const std::optional< RelaxedTemplateDeclaration > & templateDecl() const
Definition node.h:247
bool isFunction(Genus g=Genus::DontCare) const
Returns true if this is a FunctionNode and its Genus is set to g.
Definition node.h:101
Aggregate * root() const
virtual Tree * tree() const
Returns a pointer to the Tree this node is in.
Definition node.cpp:899
A class for parsing and managing a function parameter list.
Definition main.cpp:28
bool isValid() const
Definition parameters.h:33
A record of a linkable target within the documentation.
Definition tree.h:28
TargetType
A type of a linkable target record.
Definition tree.h:30
@ Unknown
Definition tree.h:30