| 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/opcuaelementoperand_p.h> | 
| 5 |  | 
| 6 | QT_BEGIN_NAMESPACE | 
| 7 |  | 
| 8 | /*! | 
| 9 |     \qmltype ElementOperand | 
| 10 |     \inqmlmodule QtOpcUa | 
| 11 |     \brief The OPC UA ElementOperand type. | 
| 12 |     \since QtOpcUa 5.13 | 
| 13 |  | 
| 14 |     The ElementOperand is defined in OPC UA 1.05 part 4, 7.7.4.2. | 
| 15 |     It is used to identify another element in the filter by its index | 
| 16 |     (the first element has the index 0). | 
| 17 |  | 
| 18 |     This is required to create complex filters, for example to reference | 
| 19 |     the two operands of the AND operation in ((Severity > 500) AND (Message == "TestString")). | 
| 20 |     The first step is to create content filter elements for the two conditions (Severity > 500) | 
| 21 |     and (Message == "TestString"). A third content filter element is required to create an AND | 
| 22 |     combination of the two conditions. It consists of the AND operator and two element operands | 
| 23 |     with the indices of the two conditions created before: | 
| 24 |  | 
| 25 |     \code | 
| 26 |     import QtOpcUa as QtOpcUa | 
| 27 |  | 
| 28 |     QtOpcUa.EventFilter { | 
| 29 |         select : [ ... ] | 
| 30 |         where: [ | 
| 31 |             QtOpcUa.FilterElement { | 
| 32 |                 operator: QtOpcUa.FilterElement.GreaterThan | 
| 33 |                 firstOperand: QtOpcUa.SimpleAttributeOperand { | 
| 34 |                     browsePath: [ | 
| 35 |                         QtOpcUa.NodeId { | 
| 36 |                             identifier: "Severity" | 
| 37 |                             ns: "http://opcfoundation.org/UA/" | 
| 38 |                         } | 
| 39 |                     ] | 
| 40 |                 } | 
| 41 |                 secondOperand: QtOpcUa.LiteralOperand { | 
| 42 |                     value: 500 | 
| 43 |                     type: QtOpcUa.Constants.UInt16 | 
| 44 |                 } | 
| 45 |             } | 
| 46 |             QtOpcUa.FilterElement { | 
| 47 |                 operator: QtOpcUa.FilterElement.Equals | 
| 48 |                 firstOperand: QtOpcUa.SimpleAttributeOperand { | 
| 49 |                     browsePath: [ | 
| 50 |                         QtOpcUa.NodeId { | 
| 51 |                             identifier: "Message" | 
| 52 |                             ns: "http://opcfoundation.org/UA/" | 
| 53 |                         } | 
| 54 |                     ] | 
| 55 |                 } | 
| 56 |                 secondOperand: QtOpcUa.LiteralOperand { | 
| 57 |                     value: "TestString" | 
| 58 |                     type: QtOpcUa.Constants.String | 
| 59 |                 } | 
| 60 |             } | 
| 61 |             QtOpcUa.FilterElement { | 
| 62 |                 operator: QtOpcUa.FilterElement.And | 
| 63 |                 firstOperand: QtOpcUa.ElementOperand { | 
| 64 |                     index: 0 | 
| 65 |                 } | 
| 66 |                 secondOperand: QtOpcUa.ElementOperand { | 
| 67 |                     index: 1 | 
| 68 |                 } | 
| 69 |             } | 
| 70 |         ] | 
| 71 |     } | 
| 72 |     \endcode | 
| 73 | */ | 
| 74 |  | 
| 75 | /*! | 
| 76 |     \qmlproperty int ElementOperand::index | 
| 77 |  | 
| 78 |     Index of the filter element that is going to be used as operand. | 
| 79 | */ | 
| 80 |  | 
| 81 | OpcUaElementOperand::OpcUaElementOperand(QObject *parent) | 
| 82 |     : OpcUaOperandBase(parent) | 
| 83 | { | 
| 84 | } | 
| 85 |  | 
| 86 | OpcUaElementOperand::~OpcUaElementOperand() = default; | 
| 87 |  | 
| 88 | QVariant OpcUaElementOperand::toCppVariant(QOpcUaClient* client) const | 
| 89 | { | 
| 90 |     Q_UNUSED(client); | 
| 91 |     QOpcUaElementOperand value(*this); | 
| 92 |     return value; | 
| 93 | } | 
| 94 |  | 
| 95 | quint32 OpcUaElementOperand::index() const | 
| 96 | { | 
| 97 |     return QOpcUaElementOperand::index(); | 
| 98 | } | 
| 99 |  | 
| 100 | void OpcUaElementOperand::setIndex(quint32 index) | 
| 101 | { | 
| 102 |     if (index != QOpcUaElementOperand::index()) { | 
| 103 |         QOpcUaElementOperand::setIndex(index); | 
| 104 |         emit dataChanged(); | 
| 105 |     } | 
| 106 | } | 
| 107 |  | 
| 108 | QT_END_NAMESPACE | 
| 109 |  |