QGIS API Documentation  2.99.0-Master (b058df7)
qgsfieldexpressionwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfieldexpressionwidget.h
3  --------------------------------------
4  Date : 01.04.2014
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : denis.rouzaud@gmail.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 QGSFIELDEXPRESSIONWIDGET_H
17 #define QGSFIELDEXPRESSIONWIDGET_H
18 
19 #include <QColor>
20 #include <QComboBox>
21 #include <QToolButton>
22 #include <QWidget>
23 #include <memory>
24 
25 #include "qgis_gui.h"
26 #include "qgis.h"
27 #include "qgsdistancearea.h"
29 #include "qgsexpressioncontext.h"
30 #include "qgsfieldproxymodel.h"
31 
32 
33 class QgsMapLayer;
34 class QgsVectorLayer;
35 
36 
46 class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
47 {
48  Q_OBJECT
49  Q_PROPERTY( QString expressionDialogTitle READ expressionDialogTitle WRITE setExpressionDialogTitle )
50  Q_FLAGS( QgsFieldProxyModel::Filters )
51  Q_PROPERTY( QgsFieldProxyModel::Filters filters READ filters WRITE setFilters )
52 
53  public:
54 
58  explicit QgsFieldExpressionWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
59 
61  void setExpressionDialogTitle( const QString &title );
62 
64  const QString expressionDialogTitle() { return mExpressionDialogTitle; }
65 
67  void setFilters( QgsFieldProxyModel::Filters filters );
68 
69  void setLeftHandButtonStyle( bool isLeft );
70 
72  QgsFieldProxyModel::Filters filters() const { return mFieldProxyModel->filters(); }
73 
75  void setGeomCalculator( const QgsDistanceArea &da );
76 
82  QString currentField( bool *isExpression = nullptr, bool *isValid = nullptr ) const;
83 
87  bool isValidExpression( QString *expressionError = nullptr ) const;
88 
92  bool isExpression() const;
93 
97  QString currentText() const;
98 
105  QString asExpression() const;
106 
116  QString expression() const;
117 
122  QgsVectorLayer *layer() const;
123 
131  void registerExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
132 
133  signals:
135  void fieldChanged( const QString &fieldName );
136 
138  void fieldChanged( const QString &fieldName, bool isValid );
139 
140  public slots:
141 
146  void setLayer( QgsMapLayer *layer );
147 
149  void setRow( int row ) { mCombo->setCurrentIndex( row ); }
150 
152  void setField( const QString &fieldName );
153 
160  void setExpression( const QString &expression );
161 
162  protected slots:
164  void editExpression();
165 
167  void expressionEdited( const QString &expression );
168 
170  void expressionEditingFinished();
171 
172  void currentFieldChanged();
173 
179  void updateLineEditStyle( const QString &expression = QString() );
180 
181  bool isExpressionValid( const QString &expressionStr );
182 
183  protected:
184  void changeEvent( QEvent *event ) override;
185 
186  private slots:
187  void reloadLayer();
188 
189  void beforeResetModel();
190  void afterResetModel();
191 
192  private:
193  QComboBox *mCombo = nullptr;
194  QToolButton *mButton = nullptr;
195  QgsFieldProxyModel *mFieldProxyModel = nullptr;
196  QString mExpressionDialogTitle;
197  std::shared_ptr<const QgsDistanceArea> mDa;
198  QgsExpressionContext mExpressionContext;
199  const QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
200  QString mBackupExpression;
201 
202  friend class TestQgsFieldExpressionWidget;
203 };
204 
205 #endif // QGSFIELDEXPRESSIONWIDGET_H
The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains ...
Base class for all map layer types.
Definition: qgsmaplayer.h:56
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
QgsFieldProxyModel::Filters filters() const
currently used filter on list of fields
The QgsFieldProxyModel class provides an easy to use model to display the list of fields of a layer...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Abstract interface for generating an expression context.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
void setRow(int row)
sets the current row in the widget
Represents a vector layer which manages a vector based data sets.