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 "qopcuastructurefield.h"
5
6#include <QtOpcUa/qopcualocalizedtext.h>
7
8#include <QtCore/qvariant.h>
9
10QT_BEGIN_NAMESPACE
11
12/*!
13 \class QOpcUaStructureField
14 \inmodule QtOpcUa
15 \since 6.7
16 \brief The OPC UA StructureField type.
17
18 This is the Qt OPC UA representation for the OPC UA StructureField type defined in OPC UA part 3.
19 It describes a field of a structured type.
20*/
21
22class QOpcUaStructureFieldData : public QSharedData
23{
24public:
25 QString name;
26 QOpcUaLocalizedText description;
27 QString dataType;
28 qint32 valueRank = 0;
29 QList<quint32> arrayDimensions;
30 quint32 maxStringLength = 0;
31 bool isOptional = false;
32};
33
34QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QOpcUaStructureFieldData);
35
36/*!
37 Constructs a structure field with \a valueRank.
38*/
39QOpcUaStructureField::QOpcUaStructureField(qint32 valueRank)
40 : data(new QOpcUaStructureFieldData)
41{
42 data->valueRank = valueRank;
43}
44
45/*!
46 Constructs a structure field from \a other.
47*/
48QOpcUaStructureField::QOpcUaStructureField(const QOpcUaStructureField &other)
49 : data(other.data)
50{
51}
52
53/*!
54 Sets the values from \a other in this structure field.
55*/
56QOpcUaStructureField &QOpcUaStructureField::operator=(const QOpcUaStructureField &other)
57{
58 if (this != &other)
59 data.operator=(o: other.data);
60 return *this;
61}
62
63/*!
64 \fn QOpcUaStructureField::QOpcUaStructureField(QOpcUaStructureField &&other)
65
66 Move-constructs a new structure field from \a other.
67
68 \note The moved-from object \a other is placed in a
69 partially-formed state, in which the only valid operations are
70 destruction and assignment of a new value.
71*/
72
73/*!
74 \fn QOpcUaStructureField &QOpcUaStructureField::operator=(QOpcUaStructureField &&other)
75
76 Move-assigns \a other to this QOpcUaStructureField instance.
77
78 \note The moved-from object \a other is placed in a
79 partially-formed state, in which the only valid operations are
80 destruction and assignment of a new value.
81*/
82
83/*!
84 \fn void QOpcUaStructureField::swap(QOpcUaStructureField &other)
85
86 Swaps structure field object \a other with this structure field
87 object. This operation is very fast and never fails.
88*/
89
90/*!
91 \fn bool QOpcUaStructureField::operator!=(const QOpcUaStructureField &lhs, const QOpcUaStructureField &rhs)
92
93 Returns \c true \a lhs is not equal to \a rhs.
94*/
95
96/*!
97 \fn bool QOpcUaStructureField::operator==(const QOpcUaStructureField &lhs, const QOpcUaStructureField &rhs)
98
99 Returns \c true \a lhs is equal to \a rhs.
100*/
101bool comparesEqual(const QOpcUaStructureField &lhs, const QOpcUaStructureField &rhs) noexcept
102{
103 return lhs.data->name == rhs.name() &&
104 lhs.data->description == rhs.description() &&
105 lhs.data->dataType == rhs.dataType() &&
106 lhs.data->valueRank == rhs.valueRank() &&
107 lhs.data->arrayDimensions == rhs.arrayDimensions() &&
108 lhs.data->maxStringLength == rhs.maxStringLength() &&
109 lhs.data->isOptional == rhs.isOptional();
110}
111
112/*!
113 Converts this structure field to \l QVariant.
114*/
115QOpcUaStructureField::operator QVariant() const
116{
117 return QVariant::fromValue(value: *this);
118}
119
120/*!
121 Destroys this structure field object.
122*/
123QOpcUaStructureField::~QOpcUaStructureField()
124{
125}
126
127/*!
128 Returns the name of the struct field.
129*/
130QString QOpcUaStructureField::name() const
131{
132 return data->name;
133}
134
135/*!
136 Sets the name of the struct field to \a name.
137*/
138void QOpcUaStructureField::setName(const QString &name)
139{
140 if (name != data->name) {
141 data.detach();
142 data->name = name;
143 }
144}
145
146/*!
147 Returns the description of the struct field.
148*/
149QOpcUaLocalizedText QOpcUaStructureField::description() const
150{
151 return data->description;
152}
153
154/*!
155 Sets the description of the struct field to \a description.
156*/
157void QOpcUaStructureField::setDescription(const QOpcUaLocalizedText &description)
158{
159 if (!(description == data->description)) {
160 data.detach();
161 data->description = description;
162 }
163}
164
165/*!
166 Returns the data type node ID of the struct field.
167*/
168QString QOpcUaStructureField::dataType() const
169{
170 return data->dataType;
171}
172
173/*!
174 Sets the data type node ID of the struct field to \a dataTypeId.
175*/
176void QOpcUaStructureField::setDataType(const QString &dataTypeId)
177{
178 if (dataTypeId != data->dataType) {
179 data.detach();
180 data->dataType = dataTypeId;
181 }
182}
183
184/*!
185 Returns the value rank of the struct field.
186*/
187qint32 QOpcUaStructureField::valueRank() const
188{
189 return data->valueRank;
190}
191
192/*!
193 Sets the value rank of the struct field to \a valueRank.
194*/
195void QOpcUaStructureField::setValueRank(qint32 valueRank)
196{
197 if (valueRank != data->valueRank) {
198 data.detach();
199 data->valueRank = valueRank;
200 }
201}
202
203/*!
204 Returns the array dimenstions of the struct field.
205*/
206QList<quint32> QOpcUaStructureField::arrayDimensions() const
207{
208 return data->arrayDimensions;
209}
210
211/*!
212 Sets the array dimensions of the struct field to \a arrayDimensions.
213*/
214void QOpcUaStructureField::setArrayDimensions(const QList<quint32> &arrayDimensions)
215{
216 if (arrayDimensions != data->arrayDimensions) {
217 data.detach();
218 data->arrayDimensions = arrayDimensions;
219 }
220}
221
222/*!
223 Returns the maximum string length of the struct field.
224*/
225quint32 QOpcUaStructureField::maxStringLength() const
226{
227 return data->maxStringLength;
228}
229
230/*!
231 Sets the maximum string length of the struct field to \a maxStringLength.
232*/
233void QOpcUaStructureField::setMaxStringLength(quint32 maxStringLength)
234{
235 if (maxStringLength != data->maxStringLength) {
236 data.detach();
237 data->maxStringLength = maxStringLength;
238 }
239}
240
241/*!
242 Returns \c true if the struct field is optional.
243*/
244bool QOpcUaStructureField::isOptional() const
245{
246 return data->isOptional;
247}
248
249/*!
250 Sets the optional flag of the struct field to \a isOptional.
251*/
252void QOpcUaStructureField::setIsOptional(bool isOptional)
253{
254 if (isOptional != data->isOptional) {
255 data.detach();
256 data->isOptional = isOptional;
257 }
258}
259
260QT_END_NAMESPACE
261

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtopcua/src/opcua/client/qopcuastructurefield.cpp