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
filebase.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 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 "utilities.h"
5
7#include "config.h"
10#include "node.h"
11#include "tree.h"
12
14
15namespace Utilities {
16
17/*!
18 \internal
19 Computes the base filename for a documentation page node.
20
21 This is the shared implementation used by both Generator::fileBase() and
22 TemplateGenerator::fileBase(). The caller is responsible for navigating
23 to the page/collection node and for caching the result; this function
24 performs only the pure filename computation.
25
26 The \a node must already be a page node or collection node.
27 The \a project string is used for example page prefixes.
28 The \a prefixFn and \a suffixFn callbacks supply the caller-specific
29 output prefix and suffix (which differ between Generator and
30 TemplateGenerator due to their different configuration mechanisms).
31
32 \note This function lives in its own compilation unit (filebase.cpp)
33 rather than utilities.cpp because it depends on Node, Config, and other
34 heavyweight QDoc types. Keeping utilities.cpp free of these dependencies
35 allows lightweight test targets to compile it without pulling in the
36 full QDoc infrastructure.
37*/
39 const Node *node,
40 const QString &project,
41 const std::function<QString(const Node *)> &prefixFn,
42 const std::function<QString(const Node *)> &suffixFn)
43{
44 QString base{node->name()};
45 if (base.endsWith(".html"_L1))
46 base.truncate(base.size() - 5);
47
48 if (node->isCollectionNode()) {
49 if (node->isQmlModule())
50 base.append("-qmlmodule"_L1);
51 else if (node->isModule())
52 base.append("-module"_L1);
53 base.append(suffixFn(node));
54 } else if (node->isTextPageNode()) {
55 if (node->isExample()) {
56 base.prepend("%1-"_L1.arg(project.toLower()));
57 base.append("-example"_L1);
58 }
59 } else if (node->isQmlType()) {
60 /*
61 To avoid file name conflicts in the html directory,
62 we prepend a prefix (by default, "qml-") and an optional suffix
63 to the file name. The suffix, if one exists, is appended to the
64 module name.
65
66 For historical reasons, skip the module name qualifier for QML value types
67 in order to avoid excess redirects in the online docs. TODO: re-assess
68 */
69 if (!node->logicalModuleName().isEmpty() && !node->isQmlBasicType()) {
70 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
72 if (InclusionFilter::isIncluded(policy, context))
73 base.prepend("%1%2-"_L1.arg(node->logicalModuleName(), suffixFn(node)));
74 }
75 } else if (node->isProxyNode()) {
76 base.append("-%1-proxy"_L1.arg(node->tree()->physicalModuleName()));
77 } else {
78 base.clear();
79 const Node *p = node;
80 forever {
81 const Node *pp = p->parent();
82 base.prepend(p->name());
83 if (pp == nullptr || pp->name().isEmpty() || pp->isTextPageNode())
84 break;
85 base.prepend('-'_L1);
86 p = pp;
87 }
88 if (node->isNamespace() && !node->name().isEmpty()) {
89 const auto *ns = static_cast<const NamespaceNode *>(node);
90 if (!ns->isDocumentedHere()) {
91 base.append("-sub-"_L1);
92 base.append(ns->tree()->camelCaseModuleName());
93 }
94 }
95 base.append(suffixFn(node));
96 }
97
98 base.prepend(prefixFn(node));
99 return asAsciiPrintable(base);
100}
101
102} // namespace Utilities
103
104QT_END_NAMESPACE
static bool isIncluded(const InclusionPolicy &policy, const NodeContext &context)
Combined button and popup list for selecting options.
This namespace holds QDoc-internal utility methods.
Definition utilities.h:23
QString computeFileBase(const Node *node, const QString &project, const std::function< QString(const Node *)> &prefixFn, const std::function< QString(const Node *)> &suffixFn)
Definition filebase.cpp:38
The Node class is the base class for all the nodes in QDoc's parse tree.
bool isQmlBasicType() const
Returns true if the node type is QmlBasicType.
Definition node.h:117
bool isQmlType() const
Returns true if the node type is QmlType or QmlValueType.
Definition node.h:121
virtual bool isTextPageNode() const
Returns true if the node is a PageNode but not an Aggregate.
Definition node.h:153
bool isProxyNode() const
Returns true if the node type is Proxy.
Definition node.h:113
NodeContext createContext() const
Definition node.cpp:174
bool isModule() const
Returns true if the node type is Module.
Definition node.h:107
virtual CollectionNode * logicalModule() const
If this is a QmlTypeNode, a pointer to its QML module is returned, which is a pointer to a Collection...
Definition node.h:258
virtual bool isCollectionNode() const
Returns true if this is an instance of CollectionNode.
Definition node.h:144
bool isQmlModule() const
Returns true if the node type is QmlModule.
Definition node.h:118
bool isExample() const
Returns true if the node type is Example.
Definition node.h:98