1// Copyright (C) 2015 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 "qopcuasimpleattributeoperand.h"
5#include "qopcuaqualifiedname.h"
6
7QT_BEGIN_NAMESPACE
8
9using namespace Qt::Literals::StringLiterals;
10
11/*!
12 \class QOpcUaSimpleAttributeOperand
13 \inmodule QtOpcUa
14 \brief The OPC UA SimpleAttributeOperand type.
15
16 The SimpleAttributeOperand is specified in OPC UA 1.05 part 4, 7.7.4.5.
17 It is used when a node attribute is required as operand.
18
19 For example, the following simple attribute operand represents the value
20 of the "Severity" field of the base event type:
21 \code
22 QOpcUaSimpleAttributeOperand("Severity");
23 \endcode
24*/
25class QOpcUaSimpleAttributeOperandData : public QSharedData
26{
27public:
28 QString typeId{u"ns=0;i=2041"_s}; // BaseEventType
29 QList<QOpcUaQualifiedName> browsePath;
30 QOpcUa::NodeAttribute attributeId {QOpcUa::NodeAttribute::Value};
31 QString indexRange;
32};
33
34/*!
35 Default constructs a simple attribute operand with no parameters set.
36*/
37QOpcUaSimpleAttributeOperand::QOpcUaSimpleAttributeOperand()
38 : data(new QOpcUaSimpleAttributeOperandData)
39{
40}
41
42/*!
43 Constructs a simple attribute operand from \a rhs.
44*/
45QOpcUaSimpleAttributeOperand::QOpcUaSimpleAttributeOperand(const QOpcUaSimpleAttributeOperand &rhs)
46 : data(rhs.data)
47{
48}
49
50/*!
51 Constructs a simple attribute operand for attribute \a attributeId of the direct child with the browse name
52 \a name in namespace \a namespaceIndex. \a typeId is the node id of a type definition node. The operand will
53 be restricted to instances of type \a typeId or a subtype.
54*/
55QOpcUaSimpleAttributeOperand::QOpcUaSimpleAttributeOperand(const QString &name, quint16 namespaceIndex, const QString &typeId, QOpcUa::NodeAttribute attributeId)
56 : data(new QOpcUaSimpleAttributeOperandData)
57{
58 browsePathRef().append(t: QOpcUaQualifiedName(namespaceIndex, name));
59 setTypeId(typeId);
60 setAttributeId(attributeId);
61}
62
63/*!
64 Constructs a simple attribute operand for the attribute \a attributeId of an object or variable of type \a typeId.
65 This can be used for requesting the ConditionId in an event filter as described in OPC UA 1.05 part 9, 5.5.2.
66*/
67QOpcUaSimpleAttributeOperand::QOpcUaSimpleAttributeOperand(QOpcUa::NodeAttribute attributeId, const QString &typeId)
68 : data(new QOpcUaSimpleAttributeOperandData)
69{
70 setTypeId(typeId);
71 setAttributeId(attributeId);
72}
73
74/*!
75 Sets the values from \a rhs in this simple attribute operand.
76*/
77QOpcUaSimpleAttributeOperand &QOpcUaSimpleAttributeOperand::operator=(const QOpcUaSimpleAttributeOperand &rhs)
78{
79 if (this != &rhs)
80 data.operator=(o: rhs.data);
81 return *this;
82}
83
84/*!
85 \fn bool QOpcUaSimpleAttributeOperand::operator==(const QOpcUaSimpleAttributeOperand &lhs,
86 const QOpcUaSimpleAttributeOperand &rhs)
87
88 Returns \c true if \a lhs has the same value as \a rhs.
89*/
90bool comparesEqual(const QOpcUaSimpleAttributeOperand &lhs,
91 const QOpcUaSimpleAttributeOperand &rhs) noexcept
92{
93 return lhs.attributeId() == rhs.attributeId() && rhs.browsePath() == rhs.browsePath() &&
94 lhs.indexRange() == rhs.indexRange() && lhs.typeId() == rhs.typeId();
95}
96
97/*!
98 Converts this simple attribute operand to \l QVariant.
99*/
100QOpcUaSimpleAttributeOperand::operator QVariant() const
101{
102 return QVariant::fromValue(value: *this);
103}
104
105QOpcUaSimpleAttributeOperand::~QOpcUaSimpleAttributeOperand()
106{
107}
108
109/*!
110 Returns the index range string.
111*/
112QString QOpcUaSimpleAttributeOperand::indexRange() const
113{
114 return data->indexRange;
115}
116
117/*!
118 Sets the index range string used to identify a single value or subset of the attribute's value to \a indexRange.
119*/
120void QOpcUaSimpleAttributeOperand::setIndexRange(const QString &indexRange)
121{
122 data->indexRange = indexRange;
123}
124
125/*!
126 Returns the attribute of the node \l browsePath is pointing to.
127*/
128QOpcUa::NodeAttribute QOpcUaSimpleAttributeOperand::attributeId() const
129{
130 return data->attributeId;
131}
132
133/*!
134 Sets the attribute id to \a attributeId.
135*/
136void QOpcUaSimpleAttributeOperand::setAttributeId(QOpcUa::NodeAttribute attributeId)
137{
138 data->attributeId = attributeId;
139}
140
141/*!
142 Returns the relative path to a node starting from \l typeId.
143*/
144QList<QOpcUaQualifiedName> QOpcUaSimpleAttributeOperand::browsePath() const
145{
146 return data->browsePath;
147}
148
149/*!
150 Returns a reference to the browse path.
151
152 \sa browsePath()
153*/
154QList<QOpcUaQualifiedName> &QOpcUaSimpleAttributeOperand::browsePathRef()
155{
156 return data->browsePath;
157}
158
159/*!
160 Sets the browse path to the node holding the attribute to \a browsePath.
161*/
162void QOpcUaSimpleAttributeOperand::setBrowsePath(const QList<QOpcUaQualifiedName> &browsePath)
163{
164 data->browsePath = browsePath;
165}
166
167/*!
168 Returns the node id of a type definition node.
169*/
170QString QOpcUaSimpleAttributeOperand::typeId() const
171{
172 return data->typeId;
173}
174
175/*!
176 Sets the node id of the type definition node to \a typeId. The operand will be of the type or one of its subtypes.
177*/
178void QOpcUaSimpleAttributeOperand::setTypeId(const QString &typeId)
179{
180 data->typeId = typeId;
181}
182
183/*!
184 \fn bool QOpcUaSimpleAttributeOperand::operator!=(const QOpcUaSimpleAttributeOperand &lhs,
185 const QOpcUaSimpleAttributeOperand &rhs)
186 \since 6.7
187
188 Returns \c true if \a lhs has a different value than \a rhs.
189*/
190
191QT_END_NAMESPACE
192

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