QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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 "moc_qgssearchwidgetwrapper.cpp"
18#include "qgsvectorlayer.h"
20#include "qgsfields.h"
21#include "qgsapplication.h"
22
23#include <QWidget>
24
25QList<QgsSearchWidgetWrapper::FilterFlag> QgsSearchWidgetWrapper::exclusiveFilterFlags()
26{
27 return QList<FilterFlag>()
28 << EqualTo
29 << NotEqualTo
31 << LessThan
34 << Between
36 << Contains
38 << IsNull
39 << IsNotNull
40 << StartsWith
41 << EndsWith;
42}
43
44QList<QgsSearchWidgetWrapper::FilterFlag> QgsSearchWidgetWrapper::nonExclusiveFilterFlags()
45{
46 return QList<FilterFlag>()
48}
49
51{
52 switch ( flag )
53 {
54 case EqualTo:
55 return QObject::tr( "Equal to (=)" );
56 case NotEqualTo:
57 return QObject::tr( "Not equal to (≠)" );
58 case GreaterThan:
59 return QObject::tr( "Greater than (>)" );
60 case LessThan:
61 return QObject::tr( "Less than (<)" );
63 return QObject::tr( "Greater than or equal to (≥)" );
65 return QObject::tr( "Less than or equal to (≤)" );
66 case Between:
67 return QObject::tr( "Between (inclusive)" );
68 case IsNotBetween:
69 return QObject::tr( "Not between (inclusive)" );
70 case CaseInsensitive:
71 return QObject::tr( "Case insensitive" );
72 case Contains:
73 return QObject::tr( "Contains" );
74 case DoesNotContain:
75 return QObject::tr( "Does not contain" );
76 case IsNull:
77 return QObject::tr( "Is missing (null)" );
78 case IsNotNull:
79 return QObject::tr( "Is not missing (not null)" );
80 case StartsWith:
81 return QObject::tr( "Starts with" );
82 case EndsWith:
83 return QObject::tr( "Ends with" );
84 }
85 return QString();
86}
87
89 : QgsWidgetWrapper( vl, nullptr, parent )
90 , mExpression( QString() )
91 , mFieldIdx( fieldIdx )
92{
93}
94
99
104
106{
107 QString field = QgsExpression::quotedColumnRef( layer()->fields().at( mFieldIdx ).name() );
108 if ( mAggregate.isEmpty() )
109 return field;
110 else
111 return QStringLiteral( "relation_aggregate('%1','%2',%3)" ).arg( context().relation().id(), mAggregate, field );
112}
113
115{
116 Q_UNUSED( feature )
117}
118
120{
121 mExpression = QStringLiteral( "TRUE" );
122}
123
125{
126 return mAggregate;
127}
128
129void QgsSearchWidgetWrapper::setAggregate( const QString &aggregate )
130{
131 mAggregate = aggregate;
132}
133
135{
136 return mFieldIdx;
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:58
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.
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
QFlags< FilterFlag > FilterFlags
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.