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/opcuafilterelement_p.h> |
5 | #include <private/opcuaoperandbase_p.h> |
6 | |
7 | #include <QOpcUaContentFilterElement> |
8 | #include <QLoggingCategory> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | /*! |
13 | \qmltype FilterElement |
14 | \inqmlmodule QtOpcUa |
15 | \brief The OPC UA ContentFilterElement. |
16 | \since QtOpcUa 5.13 |
17 | |
18 | A content filter element contains an operator and operands. |
19 | There are four different operator types which contain literal values, references to |
20 | attributes of nodes or to other content filter elements. |
21 | |
22 | A combination of one or more content filter elements makes a content filter which is used |
23 | by the server to filter data for the criteria defined by the content filter elements. |
24 | For example, the \c where clause of an event filter is a content filter which is used to decide |
25 | if a notification is generated for an event. |
26 | |
27 | \code |
28 | QtOpcUa.FilterElement { |
29 | operator: QtOpcUa.FilterElement.GreaterThanOrEqual |
30 | firstOperand: QtOpcUa.SimpleAttributeOperand { ... } |
31 | secondOperand: QtOpcUa.LiteralOperand { ... } |
32 | } |
33 | \endcode |
34 | |
35 | \sa EventFilter |
36 | */ |
37 | |
38 | /*! |
39 | \qmlproperty enumeration FilterElement::operatorType |
40 | |
41 | The filter operator. |
42 | |
43 | Possible operators for a FilterElement that are specified in |
44 | OPC-UA part 4, Tables 115 and 116. |
45 | |
46 | \value FilterElement.Equals |
47 | \value FilterElement.IsNull |
48 | \value FilterElement.GreaterThan |
49 | \value FilterElement.LessThan |
50 | \value FilterElement.GreaterThanOrEqual |
51 | \value FilterElement.LessThanOrEqual |
52 | \value FilterElement.Like |
53 | \value FilterElement.Not |
54 | \value FilterElement.Between |
55 | \value FilterElement.InList |
56 | \value FilterElement.And |
57 | \value FilterElement.Or |
58 | \value FilterElement.Cast |
59 | \value FilterElement.InView |
60 | \value FilterElement.OfType |
61 | \value FilterElement.RelatedTo |
62 | \value FilterElement.BitwiseAnd |
63 | \value FilterElement.BitwiseOr |
64 | */ |
65 | |
66 | /*! |
67 | \qmlproperty variant FilterElement::firstOperand |
68 | |
69 | First operand to be used with the operator. |
70 | This can be one of \l SimpleAttributeOperand, \l AttributeOperand, |
71 | \l LiteralOperand or \l ElementOperand. |
72 | */ |
73 | |
74 | /*! |
75 | \qmlproperty variant FilterElement::secondOperand |
76 | |
77 | Second operand to be used with the operator. |
78 | This can be one of \l SimpleAttributeOperand, \l AttributeOperand, |
79 | \l LiteralOperand or \l ElementOperand. |
80 | */ |
81 | |
82 | |
83 | Q_DECLARE_LOGGING_CATEGORY(QT_OPCUA_PLUGINS_QML) |
84 | |
85 | OpcUaFilterElement::OpcUaFilterElement(QObject *parent) |
86 | : QObject(parent) |
87 | { |
88 | } |
89 | |
90 | OpcUaFilterElement::~OpcUaFilterElement() = default; |
91 | |
92 | QOpcUaContentFilterElement OpcUaFilterElement::toFilterElement(QOpcUaClient *client) |
93 | { |
94 | QOpcUaContentFilterElement value; |
95 | value.setFilterOperator(static_cast<QOpcUaContentFilterElement::FilterOperator>(operatorType())); |
96 | value.filterOperandsRef().append(t: m_firstOperand->toCppVariant(client)); |
97 | value.filterOperandsRef().append(t: m_secondOperand->toCppVariant(client)); |
98 | return value; |
99 | } |
100 | |
101 | OpcUaFilterElement::FilterOperator OpcUaFilterElement::operatorType() const |
102 | { |
103 | return m_filterOperator; |
104 | } |
105 | |
106 | void OpcUaFilterElement::setOperatorType(OpcUaFilterElement::FilterOperator filterOperator) |
107 | { |
108 | m_filterOperator = filterOperator; |
109 | } |
110 | |
111 | OpcUaOperandBase *OpcUaFilterElement::firstOperand() const |
112 | { |
113 | return m_firstOperand; |
114 | } |
115 | |
116 | void OpcUaFilterElement::setFirstOperand(OpcUaOperandBase *operand) |
117 | { |
118 | if (m_firstOperand != operand) { |
119 | m_firstOperand = operand; |
120 | emit dataChanged(); |
121 | } |
122 | } |
123 | |
124 | OpcUaOperandBase *OpcUaFilterElement::secondOperand() const |
125 | { |
126 | return m_secondOperand; |
127 | } |
128 | |
129 | void OpcUaFilterElement::setSecondOperand(OpcUaOperandBase *operand) |
130 | { |
131 | if (m_secondOperand != operand) { |
132 | m_secondOperand = operand; |
133 | emit dataChanged(); |
134 | } |
135 | } |
136 | |
137 | QT_END_NAMESPACE |
138 |