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 "typedefnode.h"
8
10
11/*!
12 \class EnumNode
13 */
14
15/*!
16 Add \a item to the enum type's item list.
17 */
18void EnumNode::addItem(const EnumItem &item)
19{
20 m_items.append(item);
21 m_names.insert(item.name());
22}
23
24/*!
25 Returns the access level of the enumeration item named \a name.
26 Apparently it is private if it has been omitted by qdoc's
27 omitvalue command. Otherwise it is public.
28 */
29Access EnumNode::itemAccess(const QString &name) const
30{
31 if (doc().omitEnumItemNames().contains(name))
32 return Access::Private;
33 return Access::Public;
34}
35
36/*!
37 Returns the enum value associated with the enum \a name.
38 */
39QString EnumNode::itemValue(const QString &name) const
40{
41 for (const auto &item : std::as_const(m_items)) {
42 if (item.name() == name)
43 return item.value();
44 }
45 return QString();
46}
47
48/*!
49 Sets \a since information to a named enum \a value, if it
50 exists in this enum.
51*/
52void EnumNode::setSince(const QString &value, const QString &since)
53{
54 auto it = std::find_if(m_items.begin(), m_items.end(), [value](EnumItem ev) {
55 return ev.name() == value;
56 });
57 if (it != m_items.end())
58 it->setSince(since);
59}
60
61/*!
62 Clone this node on the heap and make the clone a child of
63 \a parent.
64
65 Returns a pointer to the clone.
66 */
68{
69 auto *en = new EnumNode(*this); // shallow copy
70 en->setParent(nullptr);
71 parent->addChild(en);
72
73 return en;
74}
75
77{
78 m_flagsType = typedefNode;
79 typedefNode->setAssociatedEnum(this);
80}
81
82QT_END_NAMESPACE
Access
Definition access.h:11
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:67
void setFlagsType(TypedefNode *typedefNode)
Definition enumnode.cpp:76
void addItem(const EnumItem &item)
Add item to the enum type's item list.
Definition enumnode.cpp:18
QString itemValue(const QString &name) const
Returns the enum value associated with the enum name.
Definition enumnode.cpp:39
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:52
Access itemAccess(const QString &name) const
Returns the access level of the enumeration item named name.
Definition enumnode.cpp:29
@ Public
Definition access.h:11
@ Private
Definition access.h:11
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:242
void setParent(Aggregate *n)
Sets the node's parent pointer to n.
Definition node.h:187