QGIS API Documentation  2.99.0-Master (8ec3eaf)
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 
30 class QgsMapLayer;
31 class QgsVectorLayer;
32 
33 
42 class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
43 {
44  Q_OBJECT
45  Q_PROPERTY( QString expressionDialogTitle READ expressionDialogTitle WRITE setExpressionDialogTitle )
46  Q_FLAGS( QgsFieldProxyModel::Filters )
47  Q_PROPERTY( QgsFieldProxyModel::Filters filters READ filters WRITE setFilters )
48 
49  public:
50 
54  explicit QgsFieldExpressionWidget( QWidget *parent = nullptr );
55 
57  void setExpressionDialogTitle( const QString& title );
58 
60  const QString expressionDialogTitle() { return mExpressionDialogTitle; }
61 
63  void setFilters( QgsFieldProxyModel::Filters filters );
64 
65  void setLeftHandButtonStyle( bool isLeft );
66 
68  QgsFieldProxyModel::Filters filters() const { return mFieldProxyModel->filters(); }
69 
71  void setGeomCalculator( const QgsDistanceArea &da );
72 
78  QString currentField( bool *isExpression = nullptr, bool *isValid = nullptr ) const;
79 
83  bool isValidExpression( QString *expressionError = nullptr ) const;
84 
88  bool isExpression() const;
89 
93  QString currentText() const;
94 
101  QString asExpression() const;
102 
112  QString expression() const;
113 
118  QgsVectorLayer* layer() const;
119 
127  void registerExpressionContextGenerator( const QgsExpressionContextGenerator* generator );
128 
129  signals:
131  void fieldChanged( const QString& fieldName );
132 
134  void fieldChanged( const QString& fieldName, bool isValid );
135 
136 // void returnPressed();
137 
138  public slots:
139 
144  void setLayer( QgsMapLayer* layer );
145 
147  void setRow( int row ) { mCombo->setCurrentIndex( row ); }
148 
150  void setField( const QString &fieldName );
151 
158  void setExpression( const QString& expression );
159 
160  protected slots:
162  void editExpression();
163 
165  void expressionEdited( const QString& expression );
166 
168  void expressionEditingFinished();
169 
170  void currentFieldChanged();
171 
177  void updateLineEditStyle( const QString& expression = QString() );
178 
179  bool isExpressionValid( const QString& expressionStr );
180 
181  protected:
182  void changeEvent( QEvent* event ) override;
183 
184  private slots:
185  void reloadLayer();
186 
187  void beforeResetModel();
188  void afterResetModel();
189 
190  private:
191  QComboBox* mCombo;
192  QToolButton* mButton;
193  QgsFieldProxyModel* mFieldProxyModel;
194  QString mExpressionDialogTitle;
195  QSharedPointer<const QgsDistanceArea> mDa;
196  QgsExpressionContext mExpressionContext;
197  const QgsExpressionContextGenerator* mExpressionContextGenerator;
198  QString mBackupExpression;
199 
200  friend class TestQgsFieldExpressionWidget;
201 };
202 
203 #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:49
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.