1// Copyright (C) 2019 The Qt Company Ltd.
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 <private/opcuasimpleattributeoperand_p.h>
5#include <private/opcuanodeid_p.h>
6#include <private/universalnode_p.h>
7
8#include <QOpcUaQualifiedName>
9
10QT_BEGIN_NAMESPACE
11
12/*!
13 \qmltype SimpleAttributeOperand
14 \inqmlmodule QtOpcUa
15 \brief The OPC UA SimpleAttributeOperand type.
16 \since QtOpcUa 5.13
17
18 The SimpleAttributeOperand is specified in OPC-UA part 4, 7.4.4.5.
19 It is used when a node attribute is required as operand.
20
21 For example, the following simple attribute operand represents the value
22 of the "Severity" field of the base event type:
23
24 \code
25 import QtOpcUa as QtOpcUa
26
27 QtOpcUa.SimpleAttributeOperand {
28 identifier: "Severity"
29 ns: "http://opcfoundation.org/UA/"
30 }
31 \endcode
32*/
33
34/*!
35 \qmlproperty list<OpcUaNodeId> SimpleAttributeOperand::browsePath
36
37 Browse path to the node holding the attribute.
38
39 \code
40 import QtOpcUa as QtOpcUa
41
42 QtOpcUa.SimpleAttributeOperand {
43 ...
44 browsePath: [
45 QtOpcUa.NodeId {
46 identifier: "Message"
47 ns: "http://opcfoundation.org/UA/"
48 }
49 ...
50 ]
51 }
52 \endcode
53*/
54
55/*!
56 \qmlproperty string SimpleAttributeOperand::indexRange
57
58 Index range string used to identify a single value or subset of the attribute's value.
59
60 \code
61 import QtOpcUa as QtOpcUa
62
63 QtOpcUa.SimpleAttributeOperand {
64 ...
65 indexRange: "0:2"
66 }
67 \endcode
68*/
69
70/*!
71 \qmlproperty Constants.NodeAttribute SimpleAttributeOperand::nodeAttribute
72
73 Attribute of the node \l browsePath is pointing to.
74 The default value is \c Constants.NodeAttribute.Value.
75
76 \code
77 import QtOpcUa as QtOpcUa
78
79 QtOpcUa.SimpleAttributeOperand {
80 ...
81 nodeAttribute: QtOpcUa.Constants.NodeAttribute.Value
82 }
83 \endcode
84*/
85
86/*!
87 \qmlproperty string SimpleAttributeOperand::typeId
88
89 Node id of the type definition node. The operand will be of the type or one of its subtypes.
90 The default value is \c "ns=0;i=2041".
91
92 \code
93 import QtOpcUa as QtOpcUa
94
95 QtOpcUa.SimpleAttributeOperand {
96 ...
97 typeId: "ns=0;i=2041"
98 }
99 \endcode
100*/
101
102OpcUaSimpleAttributeOperand::OpcUaSimpleAttributeOperand(QObject *parent)
103 : OpcUaOperandBase(parent)
104{
105 QOpcUaSimpleAttributeOperand::setTypeId(QStringLiteral("ns=0;i=2041"));
106 QOpcUaSimpleAttributeOperand::setAttributeId(QOpcUa::NodeAttribute::Value);
107}
108
109OpcUaSimpleAttributeOperand::~OpcUaSimpleAttributeOperand() = default;
110
111QOpcUaSimpleAttributeOperand OpcUaSimpleAttributeOperand::toSimpleAttributeOperand(QOpcUaClient *client) const
112{
113 QOpcUaSimpleAttributeOperand value(*this);
114 for (UniversalNode i : m_browsePath) {
115 i.resolveNamespaceNameToIndex(client);
116 value.browsePathRef().append(t: i.toQualifiedName());
117 }
118 return value;
119}
120
121QVariant OpcUaSimpleAttributeOperand::toCppVariant(QOpcUaClient *client) const
122{
123 return toSimpleAttributeOperand(client);
124}
125
126QString OpcUaSimpleAttributeOperand::indexRange() const
127{
128 return QOpcUaSimpleAttributeOperand::indexRange();
129}
130
131void OpcUaSimpleAttributeOperand::setIndexRange(const QString &indexRange)
132{
133 if (indexRange != QOpcUaSimpleAttributeOperand::indexRange()) {
134 QOpcUaSimpleAttributeOperand::setIndexRange(indexRange);
135 emit dataChanged();
136 }
137}
138
139QOpcUa::NodeAttribute OpcUaSimpleAttributeOperand::nodeAttribute() const
140{
141 return QOpcUaSimpleAttributeOperand::attributeId();
142}
143
144void OpcUaSimpleAttributeOperand::setNodeAttribute(QOpcUa::NodeAttribute nodeAttribute)
145{
146 if (nodeAttribute != QOpcUaSimpleAttributeOperand::attributeId()) {
147 QOpcUaSimpleAttributeOperand::setAttributeId(nodeAttribute);
148 emit dataChanged();
149 }
150}
151
152QString OpcUaSimpleAttributeOperand::typeId() const
153{
154 return QOpcUaSimpleAttributeOperand::typeId();
155}
156
157void OpcUaSimpleAttributeOperand::setTypeId(const QString &typeId)
158{
159 if (typeId != QOpcUaSimpleAttributeOperand::typeId()) {
160 QOpcUaSimpleAttributeOperand::setTypeId(typeId);
161 emit dataChanged();
162 }
163}
164
165QQmlListProperty<OpcUaNodeId> OpcUaSimpleAttributeOperand::browsePath()
166{
167 return QQmlListProperty<OpcUaNodeId>(this, this,
168 &OpcUaSimpleAttributeOperand::appendBrowsePathElement,
169 &OpcUaSimpleAttributeOperand::browsePathSize,
170 &OpcUaSimpleAttributeOperand::browsePathElement,
171 &OpcUaSimpleAttributeOperand::clearBrowsePath);
172}
173
174void OpcUaSimpleAttributeOperand::appendBrowsePathElement(OpcUaNodeId *nodeId)
175{
176 m_browsePath.append(t: nodeId);
177 emit dataChanged();
178}
179
180int OpcUaSimpleAttributeOperand::browsePathSize() const
181{
182 return m_browsePath.size();
183}
184
185OpcUaNodeId *OpcUaSimpleAttributeOperand::browsePathElement(int index) const
186{
187 return m_browsePath.at(i: index);
188}
189
190void OpcUaSimpleAttributeOperand::clearBrowsePath()
191{
192 m_browsePath.clear();
193 emit dataChanged();
194}
195
196void OpcUaSimpleAttributeOperand::appendBrowsePathElement(QQmlListProperty<OpcUaNodeId> *list, OpcUaNodeId *nodeId)
197{
198 reinterpret_cast<OpcUaSimpleAttributeOperand*>(list->data)->appendBrowsePathElement(nodeId);
199}
200
201qsizetype OpcUaSimpleAttributeOperand::browsePathSize(QQmlListProperty<OpcUaNodeId> *list)
202{
203 return reinterpret_cast<OpcUaSimpleAttributeOperand*>(list->data)->browsePathSize();
204}
205
206OpcUaNodeId *OpcUaSimpleAttributeOperand::browsePathElement(QQmlListProperty<OpcUaNodeId> *list, qsizetype index)
207{
208 return reinterpret_cast<OpcUaSimpleAttributeOperand*>(list->data)->browsePathElement(index);
209}
210
211void OpcUaSimpleAttributeOperand::clearBrowsePath(QQmlListProperty<OpcUaNodeId> *list)
212{
213 reinterpret_cast<OpcUaSimpleAttributeOperand*>(list->data)->clearBrowsePath();
214}
215
216QT_END_NAMESPACE
217

source code of qtopcua/src/declarative_opcua/opcuasimpleattributeoperand.cpp