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
namespacenode.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
5
6#include "codeparser.h"
7#include "tree.h"
8
10
11/*!
12 \class NamespaceNode
13 \brief This class represents a C++ namespace.
14
15 A namespace can be used in multiple C++ modules, so there
16 can be a NamespaceNode for namespace Xxx in more than one
17 Node tree.
18 */
19
20/*! \fn NamespaceNode(Aggregate *parent, const QString &name)
21 Constructs a NamespaceNode with the specified \a parent and \a name.
22 The node type is Node::Namespace.
23 */
24
25/*!
26 Returns true if this namespace is to be documented in the
27 current module. There can be elements declared in this
28 namespace spread over multiple modules. Those elements are
29 documented in the modules where they are declared, but they
30 are linked to from the namespace page in the module where
31 the namespace itself is documented.
32 */
34{
35 return m_whereDocumented == tree()->camelCaseModuleName();
36}
37
38/*!
39 Report qdoc warning for each documented child in a namespace
40 that is not documented. This function should only be called
41 when the namespace is not documented.
42 */
44{
45 for (const auto *node : std::as_const(m_children)) {
46 if (node->isInAPI()) {
47 QString msg1 = node->name();
48 if (node->isFunction())
49 msg1 += "()";
50 msg1 += QStringLiteral(
51 " is documented, but namespace %1 is not documented in any module.")
52 .arg(name());
53 QString msg2 =
54 QStringLiteral(
55 "Add /*! '\\%1 %2' ... */ or remove the qdoc comment marker (!) at "
56 "that line number.")
57 .arg(COMMAND_NAMESPACE, name());
58
59 node->doc().location().warning(msg1, msg2);
60 }
61 }
62}
63
64/*!
65 Returns \c true if QDoc must generate documentation for this
66 namespace node; that is, it matches the inclusion policy
67 and is documented, OR has children that match that same criteria.
68*/
70{
71 if (isInAPI())
72 return true;
73
74 return std::any_of(m_children.cbegin(), m_children.cend(),
75 [](Node *child) { return child->isInAPI(); });
76}
77
78/*!
79 Returns a const reference to the namespace node's list of
80 included children, which contains pointers to all the child
81 nodes of other namespace nodes that have the same name as
82 this namespace node. The list is built after the prepare
83 phase has been run but just before the generate phase. It
84 is buils by QDocDatabase::resolveNamespaces().
85
86 \sa QDocDatabase::resolveNamespaces()
87 */
89{
90 return m_includedChildren;
91}
92
93/*!
94 This function is only called from QDocDatabase::resolveNamespaces().
95
96 \sa includedChildren(), QDocDatabase::resolveNamespaces()
97 */
99{
100 m_includedChildren.append(child);
101}
102
103/*! \fn Tree* NamespaceNode::tree() const
104 Returns a pointer to the Tree that contains this NamespaceNode.
105 This requires traversing the parent() pointers to the root of
106 the Tree, which is the unnamed NamespaceNode.
107 */
108
109/*! \fn bool NamespaceNode::isFirstClassAggregate() const
110 Returns \c true.
111 */
112
113/*! \fn bool NamespaceNode::isRelatableType() const
114 Returns \c true.
115 */
116
117/*! \fn bool NamespaceNode::wasSeen() const
118 Returns \c true if the \c {\\namespace} command that this NamespaceNode
119 represents has been parsed by qdoc. When \c false is returned, it means
120 that only \c {\\relates} commands have been seen that relate elements to
121 this namespace.
122 */
123
124/*! \fn void NamespaceNode::markSeen()
125 Sets the data member that indicates that the \c {\\namespace} command this
126 NamespaceNode represents has been parsed by qdoc.
127 */
128
129/*! \fn void NamespaceNode::markNotSeen()
130 Clears the data member that indicates that the \c {\\namespace} command this
131 NamespaceNode represents has been parsed by qdoc.
132 */
133
134/*! \fn void NamespaceNode::setTree(Tree* t)
135 Sets the Tree pointer to \a t, which means this NamespaceNode is in the Tree \a t.
136 */
137
138/*! \fn QString NamespaceNode::whereDocumented() const
139 Returns the camel case name of the module where this namespace is documented.
140
141 \sa setWhereDocumented()
142 */
143
144/*! \fn void NamespaceNode::setWhereDocumented(const QString &t)
145 Sets the camel case name of the module where this namespace is documented to
146 the module named \a t.
147
148 This function is called when the \c {\\namespace} command is processed to let
149 qdoc know that this namespace is documented in the current module, so that
150 when something in another module is marked as related to this namespace, it
151 can be documented there with a ProxyNode for this namespace.
152
153 \sa whereDocumented()
154 */
155
156/*! \fn void NamespaceNode::setDocumented()
157 Sets the flag indicating that the \c {\\namespace} command for this
158 namespace was seen.
159 */
160
161/*! \fn bool NamespaceNode::wasDocumented() const
162 Returns \c true if a \c {\\namespace} command for this namespace was seen.
163 Otherwise returns \c false.
164 */
165
166/*! \fn void NamespaceNode::setDocNode(NamespaceNode *ns)
167 Called in QDocDatabase::resolveNamespaces() to set the pointer to the
168 NamespaceNode in which this namespace is documented.
169
170 \sa QDocDatabase::resolveNamespaces()
171 */
172
173/*! \fn NamespaceNode *NamespaceNode::docNode() const
174 Returns a pointer to the NamespaceNode that represents where the namespace
175 documentation is actually generated. API elements in many different modules
176 can be included in a single namespace. That namespace is only documented in
177 one module. The namespace is documented in the module where the \c {\\namespace}
178 command for the namespace appears.
179
180 \sa QDocDatabase::resolveNamespaces()
181 */
182
183QT_END_NAMESPACE
This class represents a C++ namespace.
void includeChild(Node *child)
This function is only called from QDocDatabase::resolveNamespaces().
bool docMustBeGenerated() const override
Returns true if QDoc must generate documentation for this namespace node; that is,...
void reportDocumentedChildrenInUndocumentedNamespace() const
Report qdoc warning for each documented child in a namespace that is not documented.
bool isDocumentedHere() const
Returns true if this namespace is to be documented in the current module.
const NodeList & includedChildren() const
Returns a const reference to the namespace node's list of included children, which contains pointers ...
#define COMMAND_NAMESPACE
Definition codeparser.h:38
Combined button and popup list for selecting options.
QList< Node * > NodeList
Definition node.h:45
The Node class is the base class for all the nodes in QDoc's parse tree.
virtual bool isInAPI() const
Returns true if this node is considered to be part of the API as per the InclusionPolicy retrieved fr...
Definition node.cpp:917