QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
21 #include <QWidget>
22 
23 QList<QgsSearchWidgetWrapper::FilterFlag> QgsSearchWidgetWrapper::exclusiveFilterFlags()
24 {
25  return QList<FilterFlag>()
26  << EqualTo
27  << NotEqualTo
28  << GreaterThan
29  << LessThan
32  << Between
33  << IsNotBetween
34  << Contains
36  << IsNull
37  << IsNotNull
38  << StartsWith
39  << EndsWith;
40 }
41 
42 QList<QgsSearchWidgetWrapper::FilterFlag> QgsSearchWidgetWrapper::nonExclusiveFilterFlags()
43 {
44  return QList<FilterFlag>()
45  << CaseInsensitive;
46 }
47 
49 {
50  switch ( flag )
51  {
52  case EqualTo:
53  return QObject::tr( "Equal to (=)" );
54  case NotEqualTo:
55  return QObject::tr( "Not equal to (≠)" );
56  case GreaterThan:
57  return QObject::tr( "Greater than (>)" );
58  case LessThan:
59  return QObject::tr( "Less than (<)" );
61  return QObject::tr( "Greater than or equal to (≥)" );
62  case LessThanOrEqualTo:
63  return QObject::tr( "Less than or equal to (≤)" );
64  case Between:
65  return QObject::tr( "Between (inclusive)" );
66  case IsNotBetween:
67  return QObject::tr( "Not between (inclusive)" );
68  case CaseInsensitive:
69  return QObject::tr( "Case insensitive" );
70  case Contains:
71  return QObject::tr( "Contains" );
72  case DoesNotContain:
73  return QObject::tr( "Does not contain" );
74  case IsNull:
75  return QObject::tr( "Is missing (null)" );
76  case IsNotNull:
77  return QObject::tr( "Is not missing (not null)" );
78  case StartsWith:
79  return QObject::tr( "Starts with" );
80  case EndsWith:
81  return QObject::tr( "Ends with" );
82  }
83  return QString();
84 }
85 
87  : QgsWidgetWrapper( vl, nullptr, parent )
88  , mExpression( QString() )
89  , mFieldIdx( fieldIdx )
90 {
91 }
92 
93 QgsSearchWidgetWrapper::FilterFlags QgsSearchWidgetWrapper::supportedFlags() const
94 {
95  return EqualTo;
96 }
97 
98 QgsSearchWidgetWrapper::FilterFlags QgsSearchWidgetWrapper::defaultFlags() const
99 {
100  return FilterFlags();
101 }
102 
104 {
105  QString field = QgsExpression::quotedColumnRef( layer()->fields().at( mFieldIdx ).name() );
106  if ( mAggregate.isEmpty() )
107  return field;
108  else
109  return QStringLiteral( "relation_aggregate('%1','%2',%3)" ).arg( context().relation().id(), mAggregate, field );
110 }
111 
113 {
114  Q_UNUSED( feature )
115 }
116 
118 {
119  mExpression = QStringLiteral( "TRUE" );
120 }
121 
123 {
124  return mAggregate;
125 }
126 
128 {
129  mAggregate = aggregate;
130 }
131 
QString aggregate() const
If in AggregateSearch mode, which aggregate should be used to construct the filter expression...
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
Supports value "contains" searching.
Supports case insensitive searching.
Supports searching for non-null values.
Supports searching for values outside of a set range.
void clearExpression()
clears the expression to search for all features
static QList< QgsSearchWidgetWrapper::FilterFlag > exclusiveFilterFlags()
Returns a list of exclusive filter flags, which cannot be combined with other flags (e...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
FilterFlag
Flags which indicate what types of filtering and searching is possible using the widget.
Supports searching for strings that end with.
QString createFieldIdentifier() const
Gets a field name or expression to use as field comparison.
Supports searching for null values.
static QString toString(QgsSearchWidgetWrapper::FilterFlag flag)
Returns a translated string representing a filter flag.
Supports searching for strings that start with.
Supports value does not contain searching.
const QgsAttributeEditorContext & context() const
Returns information about the context in which this widget is shown.
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...
QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.
virtual FilterFlags supportedFlags() const
Returns filter flags supported by the search widget.
void setAggregate(const QString &aggregate)
If in AggregateSearch mode, which aggregate should be used to construct the filter expression...
Supports searches between two values.