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

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