QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgssearchwidgetwrapper.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssearchwidgetwrapper.h
3 --------------------------------------
4 Date : 31.5.2015
5 Copyright : (C) 2015 Karolina Alexiou (carolinux)
6 Email : carolinegr at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSSEARCHWIDGETWRAPPER_H
17#define QGSSEARCHWIDGETWRAPPER_H
18
19#include <QObject>
20#include "qgis_sip.h"
21#include <QMap>
22#include <QVariant>
23
24class QgsVectorLayer;
25class QgsField;
26
28#include "qgswidgetwrapper.h"
29#include "qgis_gui.h"
30
31#ifdef SIP_RUN
32//%MappedType QList<QgsSearchWidgetWrapper::FilterFlag>
33{
34 //%TypeHeaderCode
35#include <QList>
36 //%End
37
38 //%ConvertFromTypeCode
39 // Create the list.
40 PyObject *l;
41
42 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
43 return NULL;
44
45 // Set the list elements.
46 QList<QgsSearchWidgetWrapper::FilterFlag>::iterator it = sipCpp->begin();
47 for ( int i = 0; it != sipCpp->end(); ++it, ++i )
48 {
49 PyObject *tobj;
50
51 if ( ( tobj = sipConvertFromEnum( *it, sipType_QgsSearchWidgetWrapper_FilterFlag ) ) == NULL )
52 {
53 Py_DECREF( l );
54 return NULL;
55 }
56 PyList_SET_ITEM( l, i, tobj );
57 }
58
59 return l;
60 //%End
61
62 //%ConvertToTypeCode
63 // Check the type if that is all that is required.
64 if ( sipIsErr == NULL )
65 return PyList_Check( sipPy );
66
67 QList<QgsSearchWidgetWrapper::FilterFlag> *qlist = new QList<QgsSearchWidgetWrapper::FilterFlag>;
68
69 for ( int i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
70 {
71 *qlist << ( QgsSearchWidgetWrapper::FilterFlag ) SIPLong_AsLong( PyList_GET_ITEM( sipPy, i ) );
72 }
73
74 *sipCppPtr = qlist;
75 return sipGetState( sipTransferObj );
76 //%End
77};
78#endif
79
86{
87 Q_OBJECT
88 public:
93 {
94 EqualTo = 1 << 1,
95 NotEqualTo = 1 << 2,
96 GreaterThan = 1 << 3,
97 LessThan = 1 << 4,
98 GreaterThanOrEqualTo = 1 << 5,
99 LessThanOrEqualTo = 1 << 6,
100 Between = 1 << 7,
101 CaseInsensitive = 1 << 8,
102 Contains = 1 << 9,
103 DoesNotContain = 1 << 10,
104 IsNull = 1 << 11,
105 IsNotBetween = 1 << 12,
106 IsNotNull = 1 << 13,
107 StartsWith = 1 << 14,
108 EndsWith = 1 << 15,
109 };
110 Q_DECLARE_FLAGS( FilterFlags, FilterFlag )
111
112
116 static QList<QgsSearchWidgetWrapper::FilterFlag> exclusiveFilterFlags();
117
122 static QList<QgsSearchWidgetWrapper::FilterFlag> nonExclusiveFilterFlags();
123
128 static QString toString( QgsSearchWidgetWrapper::FilterFlag flag );
129
137 explicit QgsSearchWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *parent SIP_TRANSFERTHIS = nullptr );
138
143 virtual FilterFlags supportedFlags() const;
144
149 virtual FilterFlags defaultFlags() const;
150
160 virtual QString expression() const = 0;
161
166 virtual bool applyDirectly() = 0;
167
168 // TODO QGIS 4.0 - make pure virtual
169
176 virtual QString createExpression( FilterFlags flags ) const
177 {
178 Q_UNUSED( flags )
179 return QStringLiteral( "TRUE" );
180 }
181
188 QString createFieldIdentifier() const;
189
195 QString aggregate() const;
196
202 void setAggregate( const QString &aggregate );
203
208 int fieldIndex() const;
209
210 public slots:
211
215 virtual void clearWidget() {}
216
221 void setEnabled( bool enabled ) override { Q_UNUSED( enabled ) }
222
223 signals:
224
229 void expressionChanged( const QString &exp );
230
235
241
242 protected slots:
243
247 virtual void setExpression( const QString &expression ) = 0;
248
249 void setFeature( const QgsFeature &feature ) override;
250
251 protected:
253 void clearExpression();
254
255 QString mExpression;
257
258 private:
259 QString mAggregate;
260 QgsRelation mAggregateRelation;
261};
262// We'll use this class inside a QVariant in the widgets properties
264
266
267#endif // QGSSEARCHWIDGETWRAPPER_H
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
Represents a relationship between two vector layers.
Definition qgsrelation.h:44
Shows a search widget on a filter form.
FilterFlag
Flags which indicate what types of filtering and searching is possible using the widget.
void setEnabled(bool enabled) override
Toggles whether the search widget is enabled or disabled.
virtual QString createExpression(FilterFlags flags) const
Creates a filter expression based on the current state of the search widget and the specified filter ...
virtual QString expression() const =0
Will be used to access the widget's value.
void valueChanged()
Emitted when a user changes the value of the search widget.
void valueCleared()
Emitted when a user changes the value of the search widget back to an empty, default state.
void expressionChanged(const QString &exp)
Emitted whenever the expression changes.
virtual void setExpression(const QString &expression)=0
Set the expression which is currently used as filter for this widget.
virtual bool applyDirectly()=0
If this is true, then this search widget should take effect directly when its expression changes.
virtual void clearWidget()
Clears the widget's current value and resets it back to the default state.
QFlags< FilterFlag > FilterFlags
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.
virtual void setFeature(const QgsFeature &feature)=0
Is called when the value of the widget needs to be changed.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)