QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgssearchwidgetwrapper.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssearchwidgetwrapper.h
3  --------------------------------------
4  Date : 31.5.2015
5  Copyright : (C) 2015 Karolina Alexiou (carolinux)
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 #ifndef QGSSEARCHWIDGETWRAPPER_H
17 #define QGSSEARCHWIDGETWRAPPER_H
18 
19 #include <QObject>
20 #include "qgis_sip.h"
21 #include <QMap>
22 #include <QVariant>
23 
24 class QgsVectorLayer;
25 class QgsField;
26 
28 #include "qgswidgetwrapper.h"
29 #include "qgis_gui.h"
30 
31 #ifdef SIP_RUN
32 % MappedType QList<QgsSearchWidgetWrapper::FilterFlag>
33 {
34  % TypeHeaderCode
35 #include <QList>
36  % End
37 
38  % ConvertFromTypeCode
39  // Create the list.
40  PyObject *l;
41 
42  if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
43  return NULL;
44 
45  // Set the list elements.
46  QList<QgsSearchWidgetWrapper::FilterFlag>::iterator it = sipCpp->begin();
47  for ( int i = 0; it != sipCpp->end(); ++it, ++i )
48  {
49  PyObject *tobj;
50 
51  if ( ( tobj = sipConvertFromEnum( *it, sipType_QgsSearchWidgetWrapper_FilterFlag ) ) == NULL )
52  {
53  Py_DECREF( l );
54  return NULL;
55  }
56  PyList_SET_ITEM( l, i, tobj );
57  }
58 
59  return l;
60  % End
61 
62  % ConvertToTypeCode
63  // Check the type if that is all that is required.
64  if ( sipIsErr == NULL )
65  return PyList_Check( sipPy );
66 
67  QList<QgsSearchWidgetWrapper::FilterFlag> *qlist = new QList<QgsSearchWidgetWrapper::FilterFlag>;
68 
69  for ( int i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
70  {
71  *qlist << ( QgsSearchWidgetWrapper::FilterFlag )SIPLong_AsLong( PyList_GET_ITEM( sipPy, i ) );
72  }
73 
74  *sipCppPtr = qlist;
75  return sipGetState( sipTransferObj );
76  % End
77 };
78 #endif
79 
85 class GUI_EXPORT QgsSearchWidgetWrapper : public QgsWidgetWrapper
86 {
87  Q_OBJECT
88  public:
89 
95  {
96  EqualTo = 1 << 1,
97  NotEqualTo = 1 << 2,
98  GreaterThan = 1 << 3,
99  LessThan = 1 << 4,
100  GreaterThanOrEqualTo = 1 << 5,
101  LessThanOrEqualTo = 1 << 6,
102  Between = 1 << 7,
103  CaseInsensitive = 1 << 8,
104  Contains = 1 << 9,
105  DoesNotContain = 1 << 10,
106  IsNull = 1 << 11,
107  IsNotBetween = 1 << 12,
108  IsNotNull = 1 << 13,
109  StartsWith = 1 << 14,
110  EndsWith = 1 << 15,
111  };
112  Q_DECLARE_FLAGS( FilterFlags, FilterFlag )
113 
114 
119  static QList< QgsSearchWidgetWrapper::FilterFlag > exclusiveFilterFlags();
120 
126  static QList< QgsSearchWidgetWrapper::FilterFlag > nonExclusiveFilterFlags();
127 
133  static QString toString( QgsSearchWidgetWrapper::FilterFlag flag );
134 
142  explicit QgsSearchWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *parent SIP_TRANSFERTHIS = nullptr );
143 
149  virtual FilterFlags supportedFlags() const;
150 
156  virtual FilterFlags defaultFlags() const;
157 
167  virtual QString expression() const = 0;
168 
173  virtual bool applyDirectly() = 0;
174 
182  // TODO QGIS 4.0 - make pure virtual
183  virtual QString createExpression( FilterFlags flags ) const { Q_UNUSED( flags ) return QStringLiteral( "TRUE" ); }
184 
192  QString createFieldIdentifier() const;
193 
200  QString aggregate() const;
201 
208  void setAggregate( const QString &aggregate );
209 
214  int fieldIndex() const;
215 
216  public slots:
217 
222  virtual void clearWidget() {}
223 
228  void setEnabled( bool enabled ) override { Q_UNUSED( enabled ) }
229 
230  signals:
231 
236  void expressionChanged( const QString &exp );
237 
242  void valueChanged();
243 
249  void valueCleared();
250 
251  protected slots:
252 
256  virtual void setExpression( const QString &expression ) = 0;
257 
258  void setFeature( const QgsFeature &feature ) override;
259 
260  protected:
262  void clearExpression();
263 
264  QString mExpression;
266 
267  private:
268  QString mAggregate;
269  QgsRelation mAggregateRelation;
270 };
271 // We'll use this class inside a QVariant in the widgets properties
273 
274 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSearchWidgetWrapper::FilterFlags )
275 
276 #endif // QGSSEARCHWIDGETWRAPPER_H
QgsSearchWidgetWrapper::clearWidget
virtual void clearWidget()
Clears the widget's current value and resets it back to the default state.
Definition: qgssearchwidgetwrapper.h:222
QgsWidgetWrapper
Definition: qgswidgetwrapper.h:52
QgsSearchWidgetWrapper
Definition: qgssearchwidgetwrapper.h:85
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
QgsSearchWidgetWrapper::mFieldIdx
int mFieldIdx
Definition: qgssearchwidgetwrapper.h:265
qgis_sip.h
qgsattributeeditorcontext.h
QgsSearchWidgetWrapper::mExpression
QString mExpression
Definition: qgssearchwidgetwrapper.h:264
QgsWidgetWrapper::setFeature
virtual void setFeature(const QgsFeature &feature)=0
Is called, when the value of the widget needs to be changed.
QgsSearchWidgetWrapper::createExpression
virtual QString createExpression(FilterFlags flags) const
Creates a filter expression based on the current state of the search widget and the specified filter ...
Definition: qgssearchwidgetwrapper.h:183
QgsVectorLayer
Definition: qgsvectorlayer.h:385
qgswidgetwrapper.h
QgsSearchWidgetWrapper::setEnabled
void setEnabled(bool enabled) override
Toggles whether the search widget is enabled or disabled.
Definition: qgssearchwidgetwrapper.h:228
QgsRelation
Definition: qgsrelation.h:41
QgsSearchWidgetWrapper::FilterFlag
FilterFlag
Flags which indicate what types of filtering and searching is possible using the widget.
Definition: qgssearchwidgetwrapper.h:94
QgsFeature
Definition: qgsfeature.h:55
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsField
Definition: qgsfield.h:49