QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
129 {
130  mAggregate = aggregate;
131 }
132 
134 {
135  return mFieldIdx;
136 }
137 
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.
int fieldIndex() const
Returns the field index.
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:55
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.