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