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 "qopcuaelementoperand.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | /*! |
9 | \class QOpcUaElementOperand |
10 | \inmodule QtOpcUa |
11 | \brief The OPC UA ElementOperand type. |
12 | |
13 | The ElementOperand is defined in OPC UA 1.05 part 4, 7.7.4.2. |
14 | It is used to identify another element in the filter by its index |
15 | (the first element has the index 0). |
16 | |
17 | This is required to create complex filters, for example to reference |
18 | the two operands of the AND operation in ((Severity > 500) AND (Message == "TestString")). |
19 | The first step is to create content filter elements for the two conditions (Severity > 500) |
20 | and (Message == "TestString"). A third content filter element is required to create an AND |
21 | combination of the two conditions. It consists of the AND operator and two element operands |
22 | with the indices of the two conditions created before: |
23 | |
24 | \code |
25 | QOpcUaMonitoringParameters::EventFilter filter; |
26 | ... |
27 | // setup select clauses |
28 | ... |
29 | QOpcUaContentFilterElement condition1; |
30 | QOpcUaContentFilterElement condition2; |
31 | QOpcUaContentFilterElement condition3; |
32 | condition1 << QOpcUaContentFilterElement::FilterOperator::GreaterThan << QOpcUaSimpleAttributeOperand("Severity") << |
33 | QOpcUaLiteralOperand(quint16(500), QOpcUa::Types::UInt16); |
34 | condition2 << QOpcUaContentFilterElement::FilterOperator::Equals << QOpcUaSimpleAttributeOperand("Message") << |
35 | QOpcUaLiteralOperand("TestString", QOpcUa::Types::String); |
36 | condition3 << QOpcUaContentFilterElement::FilterOperator::And << QOpcUaElementOperand(0) << QOpcUaElementOperand(1); |
37 | filter << condition1 << condition2 << condition3; |
38 | \endcode |
39 | */ |
40 | |
41 | class QOpcUaElementOperandData : public QSharedData |
42 | { |
43 | public: |
44 | quint32 index{0}; |
45 | }; |
46 | |
47 | /*! |
48 | Default constructs an element operand with no parameters set. |
49 | */ |
50 | QOpcUaElementOperand::QOpcUaElementOperand() |
51 | : data(new QOpcUaElementOperandData) |
52 | { |
53 | } |
54 | |
55 | /*! |
56 | Constructs an element operand from \a rhs. |
57 | */ |
58 | QOpcUaElementOperand::QOpcUaElementOperand(const QOpcUaElementOperand &rhs) |
59 | : data(rhs.data) |
60 | { |
61 | } |
62 | |
63 | /*! |
64 | Constructs an element operand with index \a index. |
65 | */ |
66 | QOpcUaElementOperand::QOpcUaElementOperand(quint32 index) |
67 | : data(new QOpcUaElementOperandData) |
68 | { |
69 | setIndex(index); |
70 | } |
71 | |
72 | /*! |
73 | Sets the values from \a rhs in this element operand. |
74 | */ |
75 | QOpcUaElementOperand &QOpcUaElementOperand::operator=(const QOpcUaElementOperand &rhs) |
76 | { |
77 | if (this != &rhs) |
78 | data.operator=(o: rhs.data); |
79 | return *this; |
80 | } |
81 | |
82 | /*! |
83 | Converts this element operand to \l QVariant. |
84 | */ |
85 | QOpcUaElementOperand::operator QVariant() const |
86 | { |
87 | return QVariant::fromValue(value: *this); |
88 | } |
89 | |
90 | QOpcUaElementOperand::~QOpcUaElementOperand() |
91 | { |
92 | } |
93 | |
94 | /*! |
95 | Returns the index of the filter element that is going to be used as operand. |
96 | */ |
97 | quint32 QOpcUaElementOperand::index() const |
98 | { |
99 | return data->index; |
100 | } |
101 | |
102 | /*! |
103 | Sets the index of the filter element that is going to be used as operand to \a index. |
104 | */ |
105 | void QOpcUaElementOperand::setIndex(quint32 index) |
106 | { |
107 | data->index = index; |
108 | } |
109 | |
110 | /*! |
111 | \fn bool QOpcUaElementOperand::operator==(const QOpcUaElementOperand &lhs, |
112 | const QOpcUaElementOperand &rhs) |
113 | \since 6.7 |
114 | |
115 | Returns \c true if \a lhs has the same value as \a rhs. |
116 | */ |
117 | bool comparesEqual(const QOpcUaElementOperand &lhs, const QOpcUaElementOperand &rhs) noexcept |
118 | { |
119 | return lhs.index() == rhs.index(); |
120 | } |
121 | |
122 | /*! |
123 | \fn bool QOpcUaElementOperand::operator!=(const QOpcUaElementOperand &lhs, |
124 | const QOpcUaElementOperand &rhs) |
125 | \since 6.7 |
126 | |
127 | Returns \c true if \a lhs a different value than \a rhs. |
128 | */ |
129 | |
130 | QT_END_NAMESPACE |
131 | |