QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
16 #include "qgssearchwidgetwrapper.h"
17 #include "qgsvectorlayer.h"
18 #include "qgsvectordataprovider.h"
19 #include "qgsfields.h"
20 #include "qgsapplication.h"
21 
22 #include <QWidget>
23 
24 QList<QgsSearchWidgetWrapper::FilterFlag> QgsSearchWidgetWrapper::exclusiveFilterFlags()
25 {
26  return QList<FilterFlag>()
27  << EqualTo
28  << NotEqualTo
29  << GreaterThan
30  << LessThan
33  << Between
34  << IsNotBetween
35  << Contains
37  << IsNull
38  << IsNotNull
39  << StartsWith
40  << EndsWith;
41 }
42 
43 QList<QgsSearchWidgetWrapper::FilterFlag> QgsSearchWidgetWrapper::nonExclusiveFilterFlags()
44 {
45  return QList<FilterFlag>()
46  << CaseInsensitive;
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 (≥)" );
63  case LessThanOrEqualTo:
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 
94 QgsSearchWidgetWrapper::FilterFlags QgsSearchWidgetWrapper::supportedFlags() const
95 {
96  return EqualTo;
97 }
98 
99 QgsSearchWidgetWrapper::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 
128 void QgsSearchWidgetWrapper::setAggregate( const QString &aggregate )
129 {
130  mAggregate = aggregate;
131 }
132 
134 {
135  return mFieldIdx;
136 }
137 
qgsfields.h
QgsWidgetWrapper
Manages an editor widget Widget and wrapper share the same parent.
Definition: qgswidgetwrapper.h:53
QgsSearchWidgetWrapper::Between
@ Between
Supports searches between two values.
Definition: qgssearchwidgetwrapper.h:102
QgsSearchWidgetWrapper::NotEqualTo
@ NotEqualTo
Supports not equal to.
Definition: qgssearchwidgetwrapper.h:97
QgsSearchWidgetWrapper::setFeature
void setFeature(const QgsFeature &feature) override
Definition: qgssearchwidgetwrapper.cpp:113
field
const QgsField & field
Definition: qgsfield.h:456
QgsSearchWidgetWrapper::GreaterThanOrEqualTo
@ GreaterThanOrEqualTo
Supports >=.
Definition: qgssearchwidgetwrapper.h:100
QgsWidgetWrapper::context
const QgsAttributeEditorContext & context() const
Returns information about the context in which this widget is shown.
Definition: qgswidgetwrapper.cpp:86
QgsSearchWidgetWrapper::supportedFlags
virtual FilterFlags supportedFlags() const
Returns filter flags supported by the search widget.
Definition: qgssearchwidgetwrapper.cpp:94
QgsSearchWidgetWrapper::QgsSearchWidgetWrapper
QgsSearchWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
Create a new widget wrapper.
Definition: qgssearchwidgetwrapper.cpp:87
QgsSearchWidgetWrapper::setAggregate
void setAggregate(const QString &aggregate)
If in AggregateSearch mode, which aggregate should be used to construct the filter expression.
Definition: qgssearchwidgetwrapper.cpp:128
QgsSearchWidgetWrapper::StartsWith
@ StartsWith
Supports searching for strings that start with.
Definition: qgssearchwidgetwrapper.h:109
qgsapplication.h
QgsSearchWidgetWrapper::DoesNotContain
@ DoesNotContain
Supports value does not contain searching.
Definition: qgssearchwidgetwrapper.h:105
QgsSearchWidgetWrapper::aggregate
QString aggregate() const
If in AggregateSearch mode, which aggregate should be used to construct the filter expression.
Definition: qgssearchwidgetwrapper.cpp:123
QgsWidgetWrapper::layer
QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
Definition: qgswidgetwrapper.cpp:91
QgsSearchWidgetWrapper::mFieldIdx
int mFieldIdx
Definition: qgssearchwidgetwrapper.h:266
QgsSearchWidgetWrapper::EndsWith
@ EndsWith
Supports searching for strings that end with.
Definition: qgssearchwidgetwrapper.h:110
QgsSearchWidgetWrapper::defaultFlags
virtual FilterFlags defaultFlags() const
Returns the filter flags which should be set by default for the search widget.
Definition: qgssearchwidgetwrapper.cpp:99
qgssearchwidgetwrapper.h
QgsSearchWidgetWrapper::nonExclusiveFilterFlags
static QList< QgsSearchWidgetWrapper::FilterFlag > nonExclusiveFilterFlags()
Returns a list of non-exclusive filter flags, which can be combined with other flags (e....
Definition: qgssearchwidgetwrapper.cpp:43
qgsvectordataprovider.h
QgsSearchWidgetWrapper::IsNotBetween
@ IsNotBetween
Supports searching for values outside of a set range.
Definition: qgssearchwidgetwrapper.h:107
QgsSearchWidgetWrapper::Contains
@ Contains
Supports value "contains" searching.
Definition: qgssearchwidgetwrapper.h:104
QgsSearchWidgetWrapper::mExpression
QString mExpression
Definition: qgssearchwidgetwrapper.h:265
QgsSearchWidgetWrapper::GreaterThan
@ GreaterThan
Supports greater than.
Definition: qgssearchwidgetwrapper.h:98
QgsSearchWidgetWrapper::IsNull
@ IsNull
Supports searching for null values.
Definition: qgssearchwidgetwrapper.h:106
qgsvectorlayer.h
QgsSearchWidgetWrapper::fieldIndex
int fieldIndex() const
Returns the field index.
Definition: qgssearchwidgetwrapper.cpp:133
QgsSearchWidgetWrapper::exclusiveFilterFlags
static QList< QgsSearchWidgetWrapper::FilterFlag > exclusiveFilterFlags()
Returns a list of exclusive filter flags, which cannot be combined with other flags (e....
Definition: qgssearchwidgetwrapper.cpp:24
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsSearchWidgetWrapper::LessThanOrEqualTo
@ LessThanOrEqualTo
Supports <=.
Definition: qgssearchwidgetwrapper.h:101
QgsExpression::quotedColumnRef
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
Definition: qgsexpression.cpp:65
QgsSearchWidgetWrapper::FilterFlag
FilterFlag
Flags which indicate what types of filtering and searching is possible using the widget.
Definition: qgssearchwidgetwrapper.h:95
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsSearchWidgetWrapper::LessThan
@ LessThan
Supports less than.
Definition: qgssearchwidgetwrapper.h:99
QgsSearchWidgetWrapper::createFieldIdentifier
QString createFieldIdentifier() const
Gets a field name or expression to use as field comparison.
Definition: qgssearchwidgetwrapper.cpp:104
QgsSearchWidgetWrapper::EqualTo
@ EqualTo
Supports equal to.
Definition: qgssearchwidgetwrapper.h:96
QgsSearchWidgetWrapper::CaseInsensitive
@ CaseInsensitive
Supports case insensitive searching.
Definition: qgssearchwidgetwrapper.h:103
QgsSearchWidgetWrapper::clearExpression
void clearExpression()
clears the expression to search for all features
Definition: qgssearchwidgetwrapper.cpp:118
QgsSearchWidgetWrapper::toString
static QString toString(QgsSearchWidgetWrapper::FilterFlag flag)
Returns a translated string representing a filter flag.
Definition: qgssearchwidgetwrapper.cpp:49
QgsSearchWidgetWrapper::IsNotNull
@ IsNotNull
Supports searching for non-null values.
Definition: qgssearchwidgetwrapper.h:108