1 | // Copyright (C) 2023 basysKom GmbH, opensource@basyskom.com |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qopcuaenumfield.h" |
5 | |
6 | #include <QtOpcUa/qopcualocalizedtext.h> |
7 | |
8 | #include <QtCore/qvariant.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | /*! |
13 | \class QOpcUaEnumField |
14 | \inmodule QtOpcUa |
15 | \since 6.7 |
16 | \brief The OPC UA StructureDefinition type. |
17 | |
18 | This is the Qt OPC UA representation for the OPC UA EnumField type defined in OPC UA part 3. |
19 | It describes a field of an enum type. |
20 | */ |
21 | |
22 | class QOpcUaEnumFieldData : public QSharedData |
23 | { |
24 | public: |
25 | qint64 value = 0; |
26 | QOpcUaLocalizedText displayName; |
27 | QOpcUaLocalizedText description; |
28 | QString name; |
29 | }; |
30 | |
31 | QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QOpcUaEnumFieldData); |
32 | |
33 | /*! |
34 | Default constructs an enum field with no parameters set. |
35 | */ |
36 | QOpcUaEnumField::QOpcUaEnumField() |
37 | : data(new QOpcUaEnumFieldData) |
38 | { |
39 | } |
40 | |
41 | /*! |
42 | Constructs an enum field from \a other. |
43 | */ |
44 | QOpcUaEnumField::QOpcUaEnumField(const QOpcUaEnumField &other) |
45 | : data(other.data) |
46 | { |
47 | } |
48 | |
49 | /*! |
50 | Sets the values from \a rhs in this enum field. |
51 | */ |
52 | QOpcUaEnumField &QOpcUaEnumField::operator=(const QOpcUaEnumField &rhs) |
53 | { |
54 | if (this != &rhs) |
55 | data.operator=(o: rhs.data); |
56 | return *this; |
57 | } |
58 | |
59 | /*! |
60 | \fn QOpcUaEnumField::QOpcUaEnumField(QOpcUaEnumField &&other) |
61 | |
62 | Move-constructs a new enum field from \a other. |
63 | |
64 | \note The moved-from object \a other is placed in a |
65 | partially-formed state, in which the only valid operations are |
66 | destruction and assignment of a new value. |
67 | */ |
68 | |
69 | /*! |
70 | \fn QOpcUaEnumField &QOpcUaEnumField::operator=(QOpcUaEnumField &&other) |
71 | |
72 | Move-assigns \a other to this QOpcUaEnumField instance. |
73 | |
74 | \note The moved-from object \a other is placed in a |
75 | partially-formed state, in which the only valid operations are |
76 | destruction and assignment of a new value. |
77 | */ |
78 | |
79 | /*! |
80 | \fn void QOpcUaEnumField::swap(QOpcUaEnumField &other) |
81 | |
82 | Swaps enum field object \a other with this enum field |
83 | object. This operation is very fast and never fails. |
84 | */ |
85 | |
86 | /*! |
87 | \fn bool QOpcUaEnumField::operator!=(const QOpcUaEnumField &lhs, const QOpcUaEnumField &rhs) noexcept |
88 | |
89 | Returns \c true if \a lhs is not equal to \a rhs. |
90 | */ |
91 | |
92 | /*! |
93 | \fn bool QOpcUaEnumField::operator==(const QOpcUaEnumField &lhs, const QOpcUaEnumField &rhs) noexcept |
94 | |
95 | Returns \c true if \a lhs is equal to \a rhs. |
96 | */ |
97 | bool comparesEqual(const QOpcUaEnumField &lhs, const QOpcUaEnumField &rhs) noexcept |
98 | { |
99 | return lhs.data->name == rhs.name(); |
100 | } |
101 | |
102 | /*! |
103 | Converts this enum field to \l QVariant. |
104 | */ |
105 | QOpcUaEnumField::operator QVariant() const |
106 | { |
107 | return QVariant::fromValue(value: *this); |
108 | } |
109 | |
110 | /*! |
111 | Destroy this enum definition object. |
112 | */ |
113 | QOpcUaEnumField::~QOpcUaEnumField() |
114 | { |
115 | } |
116 | |
117 | /*! |
118 | Returns the enum value of the enum field. |
119 | */ |
120 | qint64 QOpcUaEnumField::value() const |
121 | { |
122 | return data->value; |
123 | } |
124 | |
125 | /*! |
126 | Sets the enum value of the enum field to \a value. |
127 | */ |
128 | void QOpcUaEnumField::setValue(qint64 value) |
129 | { |
130 | if (value != data->value) { |
131 | data.detach(); |
132 | data->value = value; |
133 | } |
134 | } |
135 | |
136 | /*! |
137 | Returns the display name of the enum field. |
138 | */ |
139 | QOpcUaLocalizedText QOpcUaEnumField::displayName() const |
140 | { |
141 | return data->displayName; |
142 | } |
143 | |
144 | /*! |
145 | Sets the display name of the enum field to \a displayName. |
146 | */ |
147 | void QOpcUaEnumField::setDisplayName(const QOpcUaLocalizedText &displayName) |
148 | { |
149 | if (!(displayName == data->displayName)) { |
150 | data.detach(); |
151 | data->displayName = displayName; |
152 | } |
153 | } |
154 | |
155 | /*! |
156 | Returns the description of the enum field. |
157 | */ |
158 | QOpcUaLocalizedText QOpcUaEnumField::description() const |
159 | { |
160 | return data->description; |
161 | } |
162 | |
163 | /*! |
164 | Sets the description of the enum field to \a description. |
165 | */ |
166 | void QOpcUaEnumField::setDescription(const QOpcUaLocalizedText &description) |
167 | { |
168 | if (!(description == data->description)) { |
169 | data.detach(); |
170 | data->description = description; |
171 | } |
172 | } |
173 | |
174 | /*! |
175 | Returns the name of the enum field. |
176 | */ |
177 | QString QOpcUaEnumField::name() const |
178 | { |
179 | return data->name; |
180 | } |
181 | |
182 | /*! |
183 | Sets the name of the enum field to \a name. |
184 | */ |
185 | void QOpcUaEnumField::setName(const QString &name) |
186 | { |
187 | if (name != data->name) { |
188 | data.detach(); |
189 | data->name = name; |
190 | } |
191 | } |
192 | |
193 | QT_END_NAMESPACE |
194 | |