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

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