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