QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgssearchwidgetwrapper.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssearchwidgetwrapper.cpp
3 --------------------------------------
4 Date : 10.6.2015
5 Copyright : (C) 2015 Karolina Alexiou
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
17#include "qgsvectorlayer.h"
19#include "qgsfields.h"
20#include "qgsapplication.h"
21
22#include <QWidget>
23
24QList<QgsSearchWidgetWrapper::FilterFlag> QgsSearchWidgetWrapper::exclusiveFilterFlags()
25{
26 return QList<FilterFlag>()
27 << EqualTo
28 << NotEqualTo
30 << LessThan
33 << Between
35 << Contains
37 << IsNull
38 << IsNotNull
39 << StartsWith
40 << EndsWith;
41}
42
43QList<QgsSearchWidgetWrapper::FilterFlag> QgsSearchWidgetWrapper::nonExclusiveFilterFlags()
44{
45 return QList<FilterFlag>()
47}
48
50{
51 switch ( flag )
52 {
53 case EqualTo:
54 return QObject::tr( "Equal to (=)" );
55 case NotEqualTo:
56 return QObject::tr( "Not equal to (≠)" );
57 case GreaterThan:
58 return QObject::tr( "Greater than (>)" );
59 case LessThan:
60 return QObject::tr( "Less than (<)" );
62 return QObject::tr( "Greater than or equal to (≥)" );
64 return QObject::tr( "Less than or equal to (≤)" );
65 case Between:
66 return QObject::tr( "Between (inclusive)" );
67 case IsNotBetween:
68 return QObject::tr( "Not between (inclusive)" );
69 case CaseInsensitive:
70 return QObject::tr( "Case insensitive" );
71 case Contains:
72 return QObject::tr( "Contains" );
73 case DoesNotContain:
74 return QObject::tr( "Does not contain" );
75 case IsNull:
76 return QObject::tr( "Is missing (null)" );
77 case IsNotNull:
78 return QObject::tr( "Is not missing (not null)" );
79 case StartsWith:
80 return QObject::tr( "Starts with" );
81 case EndsWith:
82 return QObject::tr( "Ends with" );
83 }
84 return QString();
85}
86
88 : QgsWidgetWrapper( vl, nullptr, parent )
89 , mExpression( QString() )
90 , mFieldIdx( fieldIdx )
91{
92}
93
94QgsSearchWidgetWrapper::FilterFlags QgsSearchWidgetWrapper::supportedFlags() const
95{
96 return EqualTo;
97}
98
99QgsSearchWidgetWrapper::FilterFlags QgsSearchWidgetWrapper::defaultFlags() const
100{
101 return FilterFlags();
102}
103
105{
106 QString field = QgsExpression::quotedColumnRef( layer()->fields().at( mFieldIdx ).name() );
107 if ( mAggregate.isEmpty() )
108 return field;
109 else
110 return QStringLiteral( "relation_aggregate('%1','%2',%3)" ).arg( context().relation().id(), mAggregate, field );
111}
112
114{
115 Q_UNUSED( feature )
116}
117
119{
120 mExpression = QStringLiteral( "TRUE" );
121}
122
124{
125 return mAggregate;
126}
127
128void QgsSearchWidgetWrapper::setAggregate( const QString &aggregate )
129{
130 mAggregate = aggregate;
131}
132
134{
135 return mFieldIdx;
136}
137
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
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.
@ EqualTo
Supports equal to.
@ DoesNotContain
Supports value does not contain searching.
@ Between
Supports searches between two values.
@ NotEqualTo
Supports not equal to.
int fieldIndex() const
Returns the field index.
QgsSearchWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
Create a new widget wrapper.
void setFeature(const QgsFeature &feature) override
virtual FilterFlags defaultFlags() const
Returns the filter flags which should be set by default for the search widget.
static QList< QgsSearchWidgetWrapper::FilterFlag > nonExclusiveFilterFlags()
Returns a list of non-exclusive filter flags, which can be combined with other flags (e....
virtual FilterFlags supportedFlags() const
Returns filter flags supported by the search widget.
QString aggregate() const
If in AggregateSearch mode, which aggregate should be used to construct the filter expression.
QString createFieldIdentifier() const
Gets a field name or expression to use as field comparison.
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
void setAggregate(const QString &aggregate)
If in AggregateSearch mode, which aggregate should be used to construct the filter expression.
static QString toString(QgsSearchWidgetWrapper::FilterFlag flag)
Returns a translated string representing a filter flag.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.
const QgsAttributeEditorContext & context() const
Returns information about the context in which this widget is shown.
QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
const QgsField & field
Definition: qgsfield.h:554