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
9QT_BEGIN_NAMESPACE
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(t: item);
21 m_names.insert(value: 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(str: 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(t: 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(first: m_items.begin(), last: m_items.end(), pred: [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 */
67Node *EnumNode::clone(Aggregate *parent)
68{
69 auto *en = new EnumNode(*this); // shallow copy
70 en->setParent(nullptr);
71 parent->addChild(child: en);
72
73 return en;
74}
75
76void EnumNode::setFlagsType(TypedefNode *typedefNode)
77{
78 m_flagsType = typedefNode;
79 typedefNode->setAssociatedEnum(this);
80}
81
82QT_END_NAMESPACE
83

source code of qttools/src/qdoc/qdoc/enumnode.cpp