| 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 "qopcuacontentfilterelement.h" |
| 5 | #include "qopcuasimpleattributeoperand.h" |
| 6 | #include "qopcuaattributeoperand.h" |
| 7 | #include "qopcualiteraloperand.h" |
| 8 | #include "qopcuaelementoperand.h" |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | /*! |
| 13 | \class QOpcUaContentFilterElement |
| 14 | \inmodule QtOpcUa |
| 15 | \brief The OPC UA ContentFilterElement. |
| 16 | |
| 17 | A content filter element contains an operator and a list of operands. |
| 18 | There are four different operator types which contain literal values, references to |
| 19 | attributes of nodes or to other content filter elements. |
| 20 | |
| 21 | A combination of one or more content filter elements makes a content filter which is used |
| 22 | by the server to filter data for the criteria defined by the content filter elements. |
| 23 | For example, the \c where clause of an event filter is a content filter which is used to decide |
| 24 | if a notification is generated for an event. |
| 25 | */ |
| 26 | |
| 27 | /*! |
| 28 | \enum QOpcUaContentFilterElement::FilterOperator |
| 29 | |
| 30 | FilterOperator enumerates all possible operators for a ContentFilterElement that are specified in |
| 31 | OPC UA 1.05 part 4, 7.7.3. |
| 32 | |
| 33 | \value Equals |
| 34 | \value IsNull |
| 35 | \value GreaterThan |
| 36 | \value LessThan |
| 37 | \value GreaterThanOrEqual |
| 38 | \value LessThanOrEqual |
| 39 | \value Like |
| 40 | \value Not |
| 41 | \value Between |
| 42 | \value InList |
| 43 | \value And |
| 44 | \value Or |
| 45 | \value Cast |
| 46 | \value InView |
| 47 | \value OfType |
| 48 | \value RelatedTo |
| 49 | \value BitwiseAnd |
| 50 | \value BitwiseOr |
| 51 | */ |
| 52 | |
| 53 | class QOpcUaContentFilterElementData : public QSharedData |
| 54 | { |
| 55 | public: |
| 56 | QOpcUaContentFilterElement::FilterOperator filterOperator; |
| 57 | QList<QVariant> filterOperands; |
| 58 | }; |
| 59 | |
| 60 | /*! |
| 61 | Default constructs a content filter element with no parameters set. |
| 62 | */ |
| 63 | QOpcUaContentFilterElement::QOpcUaContentFilterElement() |
| 64 | : data(new QOpcUaContentFilterElementData) |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | /*! |
| 69 | Constructs a content filter element from \a rhs. |
| 70 | */ |
| 71 | QOpcUaContentFilterElement::QOpcUaContentFilterElement(const QOpcUaContentFilterElement &rhs) |
| 72 | : data(rhs.data) |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | QOpcUaContentFilterElement::~QOpcUaContentFilterElement() = default; |
| 77 | |
| 78 | /*! |
| 79 | Sets the values from \a rhs in this content filter element. |
| 80 | */ |
| 81 | QOpcUaContentFilterElement &QOpcUaContentFilterElement::operator=(const QOpcUaContentFilterElement &rhs) |
| 82 | { |
| 83 | if (this != &rhs) |
| 84 | data.operator=(o: rhs.data); |
| 85 | return *this; |
| 86 | } |
| 87 | |
| 88 | /*! |
| 89 | \fn bool QOpcUaContentFilterElement::operator==(const QOpcUaContentFilterElement &lhs, |
| 90 | const QOpcUaContentFilterElement &rhs) |
| 91 | |
| 92 | Returns \c true if \a lhs has the same value as \a rhs. |
| 93 | */ |
| 94 | bool comparesEqual(const QOpcUaContentFilterElement &lhs, |
| 95 | const QOpcUaContentFilterElement &rhs) noexcept |
| 96 | { |
| 97 | return lhs.filterOperator() == rhs.filterOperator() |
| 98 | && lhs.filterOperands() == rhs.filterOperands(); |
| 99 | } |
| 100 | |
| 101 | /*! |
| 102 | Converts this content filter element to \l QVariant. |
| 103 | */ |
| 104 | QOpcUaContentFilterElement::operator QVariant() const |
| 105 | { |
| 106 | return QVariant::fromValue(value: *this); |
| 107 | } |
| 108 | |
| 109 | /*! |
| 110 | Returns the operands of the filter element. |
| 111 | */ |
| 112 | QList<QVariant> QOpcUaContentFilterElement::filterOperands() const |
| 113 | { |
| 114 | return data->filterOperands; |
| 115 | } |
| 116 | |
| 117 | /*! |
| 118 | Returns a reference to the filter operands. |
| 119 | |
| 120 | \sa filterOperands() |
| 121 | */ |
| 122 | QList<QVariant> &QOpcUaContentFilterElement::filterOperandsRef() |
| 123 | { |
| 124 | return data->filterOperands; |
| 125 | } |
| 126 | |
| 127 | /*! |
| 128 | Sets the filter operands for this content filter element to \a filterOperands. |
| 129 | Supported classes are \l QOpcUaElementOperand, \l QOpcUaLiteralOperand, |
| 130 | \l QOpcUaSimpleAttributeOperand and \l QOpcUaAttributeOperand. |
| 131 | */ |
| 132 | void QOpcUaContentFilterElement::setFilterOperands(const QList<QVariant> &filterOperands) |
| 133 | { |
| 134 | data->filterOperands = filterOperands; |
| 135 | } |
| 136 | |
| 137 | /*! |
| 138 | Returns the filter operator. |
| 139 | */ |
| 140 | QOpcUaContentFilterElement::FilterOperator QOpcUaContentFilterElement::filterOperator() const |
| 141 | { |
| 142 | return data->filterOperator; |
| 143 | } |
| 144 | |
| 145 | /*! |
| 146 | Sets the operator that is applied to the filter operands to \a filterOperator. |
| 147 | */ |
| 148 | void QOpcUaContentFilterElement::setFilterOperator(QOpcUaContentFilterElement::FilterOperator filterOperator) |
| 149 | { |
| 150 | data->filterOperator = filterOperator; |
| 151 | } |
| 152 | |
| 153 | /*! |
| 154 | Sets filter operator \a op in this content filter element. |
| 155 | If multiple operators are streamed into one content filter element, only the last operator is used. |
| 156 | All others are discarded. |
| 157 | */ |
| 158 | QOpcUaContentFilterElement &QOpcUaContentFilterElement::operator<<(QOpcUaContentFilterElement::FilterOperator op) |
| 159 | { |
| 160 | setFilterOperator(op); |
| 161 | return *this; |
| 162 | } |
| 163 | |
| 164 | /*! |
| 165 | Adds the simple attribute operand \a op to the operands list of this content filter element. |
| 166 | */ |
| 167 | QOpcUaContentFilterElement &QOpcUaContentFilterElement::operator<<(const QOpcUaSimpleAttributeOperand &op) |
| 168 | { |
| 169 | filterOperandsRef().append(t: op); |
| 170 | return *this; |
| 171 | } |
| 172 | |
| 173 | /*! |
| 174 | Adds the attribute operand \a op to the operands list of this content filter element. |
| 175 | */ |
| 176 | QOpcUaContentFilterElement &QOpcUaContentFilterElement::operator<<(const QOpcUaAttributeOperand &op) |
| 177 | { |
| 178 | filterOperandsRef().append(t: op); |
| 179 | return *this; |
| 180 | } |
| 181 | |
| 182 | /*! |
| 183 | Adds the literal operand \a op to the operands list of this content filter element. |
| 184 | */ |
| 185 | QOpcUaContentFilterElement &QOpcUaContentFilterElement::operator<<(const QOpcUaLiteralOperand &op) |
| 186 | { |
| 187 | filterOperandsRef().append(t: op); |
| 188 | return *this; |
| 189 | } |
| 190 | |
| 191 | /*! |
| 192 | Adds the element operand \a op to the operands list of this content filter element. |
| 193 | */ |
| 194 | QOpcUaContentFilterElement &QOpcUaContentFilterElement::operator<<(const QOpcUaElementOperand &op) |
| 195 | { |
| 196 | filterOperandsRef().append(t: op); |
| 197 | return *this; |
| 198 | } |
| 199 | |
| 200 | /*! |
| 201 | \fn bool QOpcUaContentFilterElement::operator!=(const QOpcUaContentFilterElement &lhs, |
| 202 | const QOpcUaContentFilterElement &rhs) |
| 203 | \since 6.7 |
| 204 | |
| 205 | Returns \c true if \a lhs has a different value than \a rhs. |
| 206 | */ |
| 207 | |
| 208 | QT_END_NAMESPACE |
| 209 | |