QGIS API Documentation 3.99.0-Master (d270888f95f)
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 <QString>
24#include <QVariant>
25
26using namespace Qt::StringLiterals;
27
28class QgsVectorLayer;
29class QgsField;
30
32#include "qgswidgetwrapper.h"
33#include "qgis_gui.h"
34
35#ifdef SIP_RUN // should not be required, but mingw workflow needs it..
37#endif
38
45{
46 Q_OBJECT
47 public:
52 {
53 EqualTo = 1 << 1,
54 NotEqualTo = 1 << 2,
55 GreaterThan = 1 << 3,
56 LessThan = 1 << 4,
59 Between = 1 << 7,
60 CaseInsensitive = 1 << 8,
61 Contains = 1 << 9,
62 DoesNotContain = 1 << 10,
63 IsNull = 1 << 11,
64 IsNotBetween = 1 << 12,
65 IsNotNull = 1 << 13,
66 StartsWith = 1 << 14,
67 EndsWith = 1 << 15,
68 };
69 Q_DECLARE_FLAGS( FilterFlags, FilterFlag )
70
71
75 static QList<QgsSearchWidgetWrapper::FilterFlag> exclusiveFilterFlags();
76
81 static QList<QgsSearchWidgetWrapper::FilterFlag> nonExclusiveFilterFlags();
82
87 static QString toString( QgsSearchWidgetWrapper::FilterFlag flag );
88
96 explicit QgsSearchWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *parent SIP_TRANSFERTHIS = nullptr );
97
102 virtual FilterFlags supportedFlags() const;
103
108 virtual FilterFlags defaultFlags() const;
109
119 virtual QString expression() const = 0;
120
125 virtual bool applyDirectly() = 0;
126
127 // TODO QGIS 5.0 - make pure virtual
128
135 virtual QString createExpression( FilterFlags flags ) const
136 {
137 Q_UNUSED( flags )
138 return u"TRUE"_s;
139 }
140
147 QString createFieldIdentifier() const;
148
154 QString aggregate() const;
155
161 void setAggregate( const QString &aggregate );
162
167 int fieldIndex() const;
168
169 public slots:
170
174 virtual void clearWidget() {}
175
180 void setEnabled( bool enabled ) override { Q_UNUSED( enabled ) }
181
182 signals:
183
188 void expressionChanged( const QString &exp );
189
194
200
201 protected slots:
202
206 virtual void setExpression( const QString &expression ) = 0;
207
208 void setFeature( const QgsFeature &feature ) override;
209
210 protected:
212 void clearExpression();
213
214 QString mExpression;
216
217 private:
218 QString mAggregate;
219 QgsRelation mAggregateRelation;
220};
221// We'll use this class inside a QVariant in the widgets properties
223
225
226#endif // QGSSEARCHWIDGETWRAPPER_H
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
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)