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