QGIS API Documentation  2.99.0-Master (0a63d1f)
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 <QSharedPointer>
20 #include <QWidget>
21 #include <QToolButton>
22 #include <QComboBox>
23 #include <QColor>
24 
25 #include "qgsdistancearea.h"
26 #include "qgsfieldproxymodel.h"
27 #include "qgsexpressioncontext.h"
29 #include "qgis_gui.h"
30 
31 class QgsMapLayer;
32 class QgsVectorLayer;
33 
34 
43 class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
44 {
45  Q_OBJECT
46  Q_PROPERTY( QString expressionDialogTitle READ expressionDialogTitle WRITE setExpressionDialogTitle )
47  Q_FLAGS( QgsFieldProxyModel::Filters )
48  Q_PROPERTY( QgsFieldProxyModel::Filters filters READ filters WRITE setFilters )
49 
50  public:
51 
55  explicit QgsFieldExpressionWidget( QWidget *parent = nullptr );
56 
58  void setExpressionDialogTitle( const QString& title );
59 
61  const QString expressionDialogTitle() { return mExpressionDialogTitle; }
62 
64  void setFilters( QgsFieldProxyModel::Filters filters );
65 
66  void setLeftHandButtonStyle( bool isLeft );
67 
69  QgsFieldProxyModel::Filters filters() const { return mFieldProxyModel->filters(); }
70 
72  void setGeomCalculator( const QgsDistanceArea &da );
73 
79  QString currentField( bool *isExpression = nullptr, bool *isValid = nullptr ) const;
80 
84  bool isValidExpression( QString *expressionError = nullptr ) const;
85 
89  bool isExpression() const;
90 
94  QString currentText() const;
95 
102  QString asExpression() const;
103 
113  QString expression() const;
114 
119  QgsVectorLayer* layer() const;
120 
128  void registerExpressionContextGenerator( const QgsExpressionContextGenerator* generator );
129 
130  signals:
132  void fieldChanged( const QString& fieldName );
133 
135  void fieldChanged( const QString& fieldName, bool isValid );
136 
137 // void returnPressed();
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;
193  QToolButton* mButton;
194  QgsFieldProxyModel* mFieldProxyModel;
195  QString mExpressionDialogTitle;
196  QSharedPointer<const QgsDistanceArea> mDa;
197  QgsExpressionContext mExpressionContext;
198  const QgsExpressionContextGenerator* mExpressionContextGenerator;
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:50
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.
General purpose distance and area calculator.
void setRow(int row)
sets the current row in the widget
Represents a vector layer which manages a vector based data sets.