QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "qgis_sip.h"
20
21#include <QMap>
22#include <QObject>
23#include <QVariant>
24
25class QgsVectorLayer;
26class QgsField;
27
29#include "qgswidgetwrapper.h"
30#include "qgis_gui.h"
31
32#ifdef SIP_RUN // should not be required, but mingw workflow needs it..
34#endif
35
42{
43 Q_OBJECT
44 public:
49 {
50 EqualTo = 1 << 1,
51 NotEqualTo = 1 << 2,
52 GreaterThan = 1 << 3,
53 LessThan = 1 << 4,
56 Between = 1 << 7,
57 CaseInsensitive = 1 << 8,
58 Contains = 1 << 9,
59 DoesNotContain = 1 << 10,
60 IsNull = 1 << 11,
61 IsNotBetween = 1 << 12,
62 IsNotNull = 1 << 13,
63 StartsWith = 1 << 14,
64 EndsWith = 1 << 15,
65 };
66 Q_DECLARE_FLAGS( FilterFlags, FilterFlag )
67
68
72 static QList<QgsSearchWidgetWrapper::FilterFlag> exclusiveFilterFlags();
73
78 static QList<QgsSearchWidgetWrapper::FilterFlag> nonExclusiveFilterFlags();
79
84 static QString toString( QgsSearchWidgetWrapper::FilterFlag flag );
85
93 explicit QgsSearchWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *parent SIP_TRANSFERTHIS = nullptr );
94
99 virtual FilterFlags supportedFlags() const;
100
105 virtual FilterFlags defaultFlags() const;
106
116 virtual QString expression() const = 0;
117
122 virtual bool applyDirectly() = 0;
123
124 // TODO QGIS 4.0 - make pure virtual
125
132 virtual QString createExpression( FilterFlags flags ) const
133 {
134 Q_UNUSED( flags )
135 return QStringLiteral( "TRUE" );
136 }
137
144 QString createFieldIdentifier() const;
145
151 QString aggregate() const;
152
158 void setAggregate( const QString &aggregate );
159
164 int fieldIndex() const;
165
166 public slots:
167
171 virtual void clearWidget() {}
172
177 void setEnabled( bool enabled ) override { Q_UNUSED( enabled ) }
178
179 signals:
180
185 void expressionChanged( const QString &exp );
186
191
197
198 protected slots:
199
203 virtual void setExpression( const QString &expression ) = 0;
204
205 void setFeature( const QgsFeature &feature ) override;
206
207 protected:
209 void clearExpression();
210
211 QString mExpression;
213
214 private:
215 QString mAggregate;
216 QgsRelation mAggregateRelation;
217};
218// We'll use this class inside a QVariant in the widgets properties
220
222
223#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:54
Represents a relationship between two vector layers.
Definition qgsrelation.h:42
Shows a search widget on a filter form.
FilterFlag
Flags which indicate what types of filtering and searching is possible using the widget.
@ CaseInsensitive
Supports case insensitive searching.
@ Contains
Supports value "contains" searching.
@ IsNotBetween
Supports searching for values outside of a set range.
@ StartsWith
Supports searching for strings that start with.
@ LessThan
Supports less than.
@ IsNull
Supports searching for null values.
@ EndsWith
Supports searching for strings that end with.
@ GreaterThan
Supports greater than.
@ IsNotNull
Supports searching for non-null values.
@ DoesNotContain
Supports value does not contain searching.
@ Between
Supports searches between two values.
@ NotEqualTo
Supports not equal to.
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.
QgsSearchWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
Create a new widget wrapper.
void valueCleared()
Emitted when a user changes the value of the search widget back to an empty, default state.
virtual FilterFlags defaultFlags() const
Returns the filter flags which should be set by default for the search widget.
void expressionChanged(const QString &exp)
Emitted whenever the expression changes.
static QList< QgsSearchWidgetWrapper::FilterFlag > nonExclusiveFilterFlags()
Returns a list of non-exclusive filter flags, which can be combined with other flags (e....
virtual void setExpression(const QString &expression)=0
Set the expression which is currently used as filter for this widget.
virtual FilterFlags supportedFlags() const
Returns filter flags supported by the search 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.
static QList< QgsSearchWidgetWrapper::FilterFlag > exclusiveFilterFlags()
Returns a list of exclusive filter flags, which cannot be combined with other flags (e....
void clearExpression()
clears the expression to search for all features
QFlags< FilterFlag > FilterFlags
static QString toString(QgsSearchWidgetWrapper::FilterFlag flag)
Returns a translated string representing a filter flag.
Represents a vector layer which manages a vector based dataset.
virtual void setFeature(const QgsFeature &feature)=0
Is called when the value of the widget needs to be changed.
QgsWidgetWrapper(QgsVectorLayer *vl, QWidget *editor=nullptr, QWidget *parent=nullptr)
Create a new widget wrapper.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
#define SIP_INSERT_QLIST_ENUM_CONVERSION_CODE(class_name,...)
Definition qgis_sip.h:297
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)