Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
8
#
include
"collectionnode.h"
9
#
include
"config.h"
10
#
include
"inclusionfilter.h"
11
#
include
"namespacenode.h"
12
#
include
"node.h"
13
#
include
"tree.h"
14
15
QT_BEGIN_NAMESPACE
16
17
namespace
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
*/
40
QString
computeFileBase
(
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();
73
const
NodeContext
context = node
->
logicalModule
(
)
->
createContext
();
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
106
QT_END_NAMESPACE
InclusionFilter
Definition
inclusionfilter.h:14
InclusionFilter::isIncluded
static bool isIncluded(const InclusionPolicy &policy, const NodeContext &context)
Definition
inclusionfilter.h:16
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
Utilities
This namespace holds QDoc-internal utility methods.
Definition
utilities.h:21
Utilities::computeFileBase
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
NodeContext
Definition
nodecontext.h:17
Node
The Node class is the base class for all the nodes in QDoc's parse tree.
Definition
src_corelib_text_qstring.cpp:10
Node::isNamespace
bool isNamespace() const
Returns true if the node type is Namespace.
Definition
node.h:110
Node::isQmlBasicType
bool isQmlBasicType() const
Returns true if the node type is QmlBasicType.
Definition
node.h:119
Node::isQmlType
bool isQmlType() const
Returns true if the node type is QmlType or QmlValueType.
Definition
node.h:123
Node::isTextPageNode
virtual bool isTextPageNode() const
Returns true if the node is a PageNode but not an Aggregate.
Definition
node.h:155
Node::parent
Aggregate * parent() const
Returns the node's parent pointer, that is, the aggregate under which the node is documented.
Definition
node.h:211
Node::isProxyNode
bool isProxyNode() const
Returns true if the node type is Proxy.
Definition
node.h:115
Node::createContext
NodeContext createContext() const
Definition
node.cpp:175
Node::isModule
bool isModule() const
Returns true if the node type is Module.
Definition
node.h:108
Node::logicalModule
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:262
Node::isCollectionNode
virtual bool isCollectionNode() const
Returns true if this is an instance of CollectionNode.
Definition
node.h:146
Node::isQmlModule
bool isQmlModule() const
Returns true if the node type is QmlModule.
Definition
node.h:120
Node::isExample
bool isExample() const
Returns true if the node type is Example.
Definition
node.h:99
qttools
src
qdoc
qdoc
src
qdoc
filebase.cpp
Generated on
for Qt by
1.18.0