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
enumnode.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 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 "enumnode.h"
5
6#include "aggregate.h"
7#include "nativeenum.h"
8#include "typedefnode.h"
9
10#include <QtCore/QStringList>
11
13
14using namespace Qt::StringLiterals;
15
16/*!
17 \class EnumNode
18 */
19
20/*!
21 Add \a item to the enum type's item list.
22 */
23void EnumNode::addItem(const EnumItem &item)
24{
25 m_items.append(item);
26 m_names.insert(item.name());
27}
28
29/*!
30 Returns the access level of the enumeration item named \a name.
31 Apparently it is private if it has been omitted by qdoc's
32 omitvalue command. Otherwise it is public.
33 */
34Access EnumNode::itemAccess(const QString &name) const
35{
36 if (doc().omitEnumItemNames().contains(name))
37 return Access::Private;
38 return Access::Public;
39}
40
41/*!
42 Returns the enum value associated with the enum \a name.
43 */
44QString EnumNode::itemValue(const QString &name) const
45{
46 for (const auto &item : std::as_const(m_items)) {
47 if (item.name() == name)
48 return item.value();
49 }
50 return QString();
51}
52
53/*!
54 Sets \a since information to a named enum \a value, if it
55 exists in this enum.
56*/
57void EnumNode::setSince(const QString &value, const QString &since)
58{
59 auto it = std::find_if(m_items.begin(), m_items.end(), [value](EnumItem ev) {
60 return ev.name() == value;
61 });
62 if (it != m_items.end())
63 it->setSince(since);
64}
65
66/*!
67 Clone this node on the heap and make the clone a child of
68 \a parent.
69
70 Returns a pointer to the clone.
71 */
73{
74 auto *en = new EnumNode(*this); // shallow copy
75 en->setParent(nullptr);
76 parent->addChild(en);
77
78 return en;
79}
80
82{
83 m_flagsType = typedefNode;
84 typedefNode->setAssociatedEnum(this);
85}
86
87/*!
88 Returns the display name of the enumeration value \a enumValue for use in
89 the constant column of a value table: the value as documented, qualified
90 with the scope in which this enum was declared. A related nonmember is
91 documented under the related class, but its values keep the C++ scope in
92 which the enum was declared, so the scope walk starts from the
93 declaration parent. This mirrors the naming of
94 CppCodeMarker::markedUpEnumValue (HTML, WebXML) and
95 DocBookGenerator::generateEnumValue (DocBook), minus the markup, so that
96 the template generators show the same constant names.
97*/
98QString EnumNode::qualifiedValueName(const QString &enumValue) const
99{
100 const auto *node = declarationParent() ? declarationParent() : parent();
101
102 const NativeEnum *nativeEnum{nullptr};
103 if (auto *ne_if = dynamic_cast<const NativeEnumInterface *>(this))
104 nativeEnum = ne_if->nativeEnum();
105
106 if (nativeEnum && nativeEnum->enumNode()
107 && !enumValue.startsWith("%1."_L1.arg(nativeEnum->prefix())))
108 return "%1.%2"_L1.arg(nativeEnum->prefix(), enumValue);
109
110 // Respect existing prefixes in \value arguments of \qmlenum topics.
111 if (isEnumType(Genus::QML)
112 && enumValue.section(' ', 0, 0).contains('.'_L1))
113 return enumValue;
114
115 QStringList parts;
116 const auto *self = static_cast<const Node *>(this);
117 while (!node->isHeader() && node->parent()) {
118 parts.prepend(node->name());
119 if (node->parent() == self || node->parent()->name().isEmpty())
120 break;
121 node = node->parent();
122 }
123 if (isScoped())
124 parts.append(name());
125
126 parts.append(enumValue);
127 const auto &delim = (genus() == Genus::QML) ? "."_L1 : "::"_L1;
128 return parts.join(delim);
129}
130
131QT_END_NAMESPACE
void addChild(Node *child)
Adds the child to this node's child list and sets the child's parent pointer to this Aggregate.
Node * clone(Aggregate *parent) override
Clone this node on the heap and make the clone a child of parent.
Definition enumnode.cpp:72
void setFlagsType(TypedefNode *typedefNode)
Definition enumnode.cpp:81
void addItem(const EnumItem &item)
Add item to the enum type's item list.
Definition enumnode.cpp:23
QString itemValue(const QString &name) const
Returns the enum value associated with the enum name.
Definition enumnode.cpp:44
QString qualifiedValueName(const QString &enumValue) const
Returns the display name of the enumeration value enumValue for use in the constant column of a value...
Definition enumnode.cpp:98
void setSince(const QString &value, const QString &since)
Sets since information to a named enum value, if it exists in this enum.
Definition enumnode.cpp:57
Access itemAccess(const QString &name) const
Returns the access level of the enumeration item named name.
Definition enumnode.cpp:34
bool isScoped() const
Definition enumnode.h:33
Interface implemented by Node subclasses that can refer to a C++ enum.
Definition nativeenum.h:28
virtual const NativeEnum * nativeEnum() const =0
Encapsulates information about native (C++) enum values.
Definition nativeenum.h:14
Combined button and popup list for selecting options.
The Node class is the base class for all the nodes in QDoc's parse tree.
const Doc & doc() const
Returns a reference to the node's Doc data member.
Definition node.h:239
Aggregate * parent() const
Returns the node's parent pointer, that is, the aggregate under which the node is documented.
Definition node.h:211
void setParent(Aggregate *n)
Sets the node's parent pointer to n.
Definition node.h:182
Aggregate * declarationParent() const
Returns the aggregate in whose C++ scope the node was declared, or null if the node was not adopted b...
Definition node.h:212