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
nodedescription.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
5
6#include "functionnode.h"
7#include "genustypes.h"
8#include "node.h"
10
12
13using namespace Qt::StringLiterals;
14
15/*!
16 \namespace NodeText
17 \internal
18 \brief Provides human-readable descriptions of QDoc nodes.
19*/
20namespace NodeText {
21
22/*!
23 \enum NodeText::GrammaticalNumber
24 \brief Specifies the singular or plural form of a node type description.
25
26 \value Singular Use the singular form.
27 \value Plural Use the plural form.
28*/
29
30/*!
31 \internal
32
33 Returns a human-readable description of \a node's type in the specified
34 grammatical \a number. The default is Singular because most callers
35 describe one node.
36
37 \sa NodeText::GrammaticalNumber
38*/
40{
41 switch (node->nodeType()) {
42 case NodeType::Namespace:
43 return number == GrammaticalNumber::Singular ? "namespace"_L1 : "namespaces"_L1;
44 case NodeType::Class:
45 return number == GrammaticalNumber::Singular ? "class"_L1 : "classes"_L1;
46 case NodeType::Struct:
47 return number == GrammaticalNumber::Singular ? "struct"_L1 : "structs"_L1;
48 case NodeType::Union:
49 return number == GrammaticalNumber::Singular ? "union"_L1 : "unions"_L1;
50 case NodeType::QmlType:
51 case NodeType::QmlValueType:
52 return number == GrammaticalNumber::Singular ? "type"_L1 : "types"_L1;
53 case NodeType::Page:
54 return "documentation"_L1;
55 case NodeType::Enum:
56 return number == GrammaticalNumber::Singular ? "enum"_L1 : "enums"_L1;
57 case NodeType::Typedef:
58 case NodeType::TypeAlias:
59 return number == GrammaticalNumber::Singular ? "typedef"_L1 : "typedefs"_L1;
60 case NodeType::Function: {
61 const auto fn = static_cast<const FunctionNode *>(node);
62 switch (fn->metaness()) {
63 case Metaness::QmlSignal:
64 return number == GrammaticalNumber::Singular ? "signal"_L1 : "signals"_L1;
65 case Metaness::QmlSignalHandler:
66 return number == GrammaticalNumber::Singular ? "signal handler"_L1 : "signal handlers"_L1;
67 case Metaness::QmlMethod:
68 return number == GrammaticalNumber::Singular ? "method"_L1 : "methods"_L1;
69 case Metaness::MacroWithParams:
70 case Metaness::MacroWithoutParams:
71 return number == GrammaticalNumber::Singular ? "macro"_L1 : "macros"_L1;
72 default:
73 break;
74 }
75 return number == GrammaticalNumber::Singular ? "function"_L1 : "functions"_L1;
76 }
77 case NodeType::QmlEnum:
78 return number == GrammaticalNumber::Singular ? "enumeration"_L1 : "enumerations"_L1;
79 case NodeType::Property:
80 case NodeType::QmlProperty:
81 return number == GrammaticalNumber::Singular ? "property"_L1 : "properties"_L1;
82 case NodeType::Module:
83 case NodeType::QmlModule:
84 return number == GrammaticalNumber::Singular ? "module"_L1 : "modules"_L1;
85 case NodeType::Variable:
86 return number == GrammaticalNumber::Singular ? "variable"_L1 : "variables"_L1;
87 case NodeType::Concept:
88 return number == GrammaticalNumber::Singular ? "concept"_L1 : "concepts"_L1;
90 const auto *shared = static_cast<const SharedCommentNode *>(node);
91 if (shared->isPropertyGroup())
92 return number == GrammaticalNumber::Singular ? "property group"_L1 : "property groups"_L1;
93 const auto &collective = shared->collective();
94 return collective.first()->nodeTypeString();
95 }
96 default:
97 return "documentation"_L1;
98 }
99}
100
101} // namespace NodeText
102
103QT_END_NAMESPACE
NodeType
Definition genustypes.h:165
@ SharedComment
Definition genustypes.h:188
Provides human-readable descriptions of QDoc nodes.
QString nodeTypeDescription(const Node *node, GrammaticalNumber number=GrammaticalNumber::Singular)
Combined button and popup list for selecting options.
The Node class is the base class for all the nodes in QDoc's parse tree.
NodeType nodeType() const override
Returns this node's type.
Definition node.h:82