1
+ %MappedType QList<QgsSearchWidgetWrapper::FilterFlag>
2
+ {
3
+ %TypeHeaderCode
4
+ #include <QList>
5
+ %End
6
+
7
+ %ConvertFromTypeCode
8
+ // Create the list.
9
+ PyObject *l;
10
+
11
+ if ((l = PyList_New(sipCpp->size())) == NULL)
12
+ return NULL;
13
+
14
+ // Set the list elements.
15
+ QList<QgsSearchWidgetWrapper::FilterFlag>::iterator it = sipCpp->begin();
16
+ for (int i = 0; it != sipCpp->end(); ++it, ++i)
17
+ {
18
+ PyObject *tobj;
19
+
20
+ if ((tobj = sipConvertFromEnum(*it, sipType_QgsSearchWidgetWrapper_FilterFlag)) == NULL)
21
+ {
22
+ Py_DECREF(l);
23
+ return NULL;
24
+ }
25
+ PyList_SET_ITEM(l, i, tobj);
26
+ }
27
+
28
+ return l;
29
+ %End
30
+
31
+ %ConvertToTypeCode
32
+ // Check the type if that is all that is required.
33
+ if (sipIsErr == NULL)
34
+ return PyList_Check(sipPy);
35
+
36
+ QList<QgsSearchWidgetWrapper::FilterFlag> *qlist = new QList<QgsSearchWidgetWrapper::FilterFlag>;
37
+
38
+ for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
39
+ {
40
+ *qlist << (QgsSearchWidgetWrapper::FilterFlag)SIPLong_AsLong(PyList_GET_ITEM(sipPy, i));
41
+ }
42
+
43
+ *sipCppPtr = qlist;
44
+ return sipGetState(sipTransferObj);
45
+ %End
46
+ };
47
+
1
48
/**
2
49
* Manages an editor widget
3
50
* Widget and wrapper share the same parent
@@ -14,6 +61,43 @@ class QgsSearchWidgetWrapper : QgsWidgetWrapper
14
61
#include <qgssearchwidgetwrapper.h>
15
62
%End
16
63
public:
64
+
65
+ //! Flags which indicate what types of filtering and searching is possible using the widget
66
+ //! @note added in QGIS 2.16
67
+ enum FilterFlag
68
+ {
69
+ EqualTo, /*!< Supports equal to */
70
+ NotEqualTo, /*!< Supports not equal to */
71
+ GreaterThan, /*!< Supports greater than */
72
+ LessThan, /*!< Supports less than */
73
+ GreaterThanOrEqualTo, /*!< Supports >= */
74
+ LessThanOrEqualTo, /*!< Supports <= */
75
+ Between, /*!< Supports searches between two values */
76
+ CaseInsensitive, /*!< Supports case insensitive searching */
77
+ Contains, /*!< Supports value "contains" searching */
78
+ DoesNotContain, /*!< Supports value does not contain searching */
79
+ IsNull, /*!< Supports searching for null values */
80
+ };
81
+ typedef QFlags<QgsSearchWidgetWrapper::FilterFlag> FilterFlags;
82
+
83
+ /** Returns a list of exclusive filter flags, which cannot be combined with other flags (eg EqualTo/NotEqualTo)
84
+ * @note added in QGIS 2.16
85
+ * @see nonExclusiveFilterFlags()
86
+ */
87
+ static QList< QgsSearchWidgetWrapper::FilterFlag > exclusiveFilterFlags();
88
+
89
+ /** Returns a list of non-exclusive filter flags, which can be combined with other flags (eg CaseInsensitive)
90
+ * @note added in QGIS 2.16
91
+ * @see exclusiveFilterFlags()
92
+ */
93
+ static QList< QgsSearchWidgetWrapper::FilterFlag > nonExclusiveFilterFlags();
94
+
95
+ /** Returns a translated string representing a filter flag.
96
+ * @param flag flag to convert to string
97
+ * @note added in QGIS 2.16
98
+ */
99
+ static QString toString( FilterFlag flag );
100
+
17
101
/**
18
102
* Create a new widget wrapper
19
103
*
@@ -23,6 +107,18 @@ class QgsSearchWidgetWrapper : QgsWidgetWrapper
23
107
*/
24
108
explicit QgsSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* parent /TransferThis/ = nullptr );
25
109
110
+ /** Returns filter flags supported by the search widget.
111
+ * @note added in QGIS 2.16
112
+ * @see defaultFlags()
113
+ */
114
+ virtual FilterFlags supportedFlags() const;
115
+
116
+ /** Returns the filter flags which should be set by default for the search widget.
117
+ * @note added in QGIS 2.16
118
+ * @see supportedFlags()
119
+ */
120
+ virtual FilterFlags defaultFlags() const;
121
+
26
122
/**
27
123
* Will be used to access the widget's value. Read the value from the widget and
28
124
* return it properly formatted to be saved in the attribute.
@@ -39,6 +135,28 @@ class QgsSearchWidgetWrapper : QgsWidgetWrapper
39
135
*/
40
136
virtual bool applyDirectly() = 0;
41
137
138
+ /** Creates a filter expression based on the current state of the search widget
139
+ * and the specified filter flags.
140
+ * @param flags filter flags
141
+ * @returns filter expression
142
+ * @note added in QGIS 2.16
143
+ */
144
+ // TODO QGIS 3.0 - make pure virtual
145
+ virtual QString createExpression( FilterFlags flags ) const;
146
+
147
+ public slots:
148
+
149
+ /** Clears the widget's current value and resets it back to the default state
150
+ * @note added in QGIS 2.16
151
+ */
152
+ virtual void clearWidget();
153
+
154
+ /** Toggles whether the search widget is enabled or disabled.
155
+ * @param enabled set to true to enable widget
156
+ * @note added in QGIS 2.16
157
+ */
158
+ virtual void setEnabled( bool enabled );
159
+
42
160
signals:
43
161
44
162
/**
@@ -47,6 +165,17 @@ class QgsSearchWidgetWrapper : QgsWidgetWrapper
47
165
*/
48
166
void expressionChanged( const QString& exp );
49
167
168
+ /** Emitted when a user changes the value of the search widget.
169
+ * @note added in QGIS 2.16
170
+ */
171
+ void valueChanged();
172
+
173
+ /** Emitted when a user changes the value of the search widget back
174
+ * to an empty, default state.
175
+ * @note added in QGIS 2.16
176
+ */
177
+ void valueCleared();
178
+
50
179
protected slots:
51
180
52
181
virtual void setExpression( QString value ) = 0;
@@ -57,3 +186,5 @@ class QgsSearchWidgetWrapper : QgsWidgetWrapper
57
186
void clearExpression();
58
187
59
188
};
189
+
190
+ QFlags<QgsSearchWidgetWrapper::FilterFlag> operator|(QgsSearchWidgetWrapper::FilterFlag f1, QFlags<QgsSearchWidgetWrapper::FilterFlag> f2);
0 commit comments