QGIS API Documentation  2.99.0-Master (7d4f81d)
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 : [email protected]
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 
45 class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
46 {
47  Q_OBJECT
48  Q_PROPERTY( QString expressionDialogTitle READ expressionDialogTitle WRITE setExpressionDialogTitle )
49  Q_FLAGS( QgsFieldProxyModel::Filters )
50  Q_PROPERTY( QgsFieldProxyModel::Filters filters READ filters WRITE setFilters )
51 
52  public:
53 
57  explicit QgsFieldExpressionWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
58 
60  void setExpressionDialogTitle( const QString &title );
61 
63  const QString expressionDialogTitle() { return mExpressionDialogTitle; }
64 
66  void setFilters( QgsFieldProxyModel::Filters filters );
67 
68  void setLeftHandButtonStyle( bool isLeft );
69 
71  QgsFieldProxyModel::Filters filters() const { return mFieldProxyModel->filters(); }
72 
74  void setGeomCalculator( const QgsDistanceArea &da );
75 
81  QString currentField( bool *isExpression = nullptr, bool *isValid = nullptr ) const;
82 
86  bool isValidExpression( QString *expressionError = nullptr ) const;
87 
91  bool isExpression() const;
92 
96  QString currentText() const;
97 
104  QString asExpression() const;
105 
115  QString expression() const;
116 
121  QgsVectorLayer *layer() const;
122 
130  void registerExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
131 
132  signals:
134  void fieldChanged( const QString &fieldName );
135 
137  void fieldChanged( const QString &fieldName, bool isValid );
138 
139  public slots:
140 
145  void setLayer( QgsMapLayer *layer );
146 
148  void setRow( int row ) { mCombo->setCurrentIndex( row ); }
149 
151  void setField( const QString &fieldName );
152 
159  void setExpression( const QString &expression );
160 
161  protected slots:
163  void editExpression();
164 
166  void expressionEdited( const QString &expression );
167 
169  void expressionEditingFinished();
170 
171  void currentFieldChanged();
172 
178  void updateLineEditStyle( const QString &expression = QString() );
179 
180  bool isExpressionValid( const QString &expressionStr );
181 
182  protected:
183  void changeEvent( QEvent *event ) override;
184 
185  private slots:
186  void reloadLayer();
187 
188  void beforeResetModel();
189  void afterResetModel();
190 
191  private:
192  QComboBox *mCombo = nullptr;
193  QToolButton *mButton = nullptr;
194  QgsFieldProxyModel *mFieldProxyModel = nullptr;
195  QString mExpressionDialogTitle;
196  std::shared_ptr<const QgsDistanceArea> mDa;
197  QgsExpressionContext mExpressionContext;
198  const QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
199  QString mBackupExpression;
200 
201  friend class TestQgsFieldExpressionWidget;
202 };
203 
204 #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:54
#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.