QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
28 class QgsMapLayer;
29 class QgsVectorLayer;
30 
31 
40 class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
41 {
42  Q_OBJECT
43  Q_PROPERTY( QString expressionDialogTitle READ expressionDialogTitle WRITE setExpressionDialogTitle )
44  Q_FLAGS( QgsFieldProxyModel::Filters )
45  Q_PROPERTY( QgsFieldProxyModel::Filters filters READ filters WRITE setFilters )
46 
47  public:
51  explicit QgsFieldExpressionWidget( QWidget *parent = nullptr );
52 
54  void setExpressionDialogTitle( const QString& title );
55 
57  const QString expressionDialogTitle() { return mExpressionDialogTitle; }
58 
60  void setFilters( const QgsFieldProxyModel::Filters& filters );
61 
62  void setLeftHandButtonStyle( bool isLeft );
63 
65  QgsFieldProxyModel::Filters filters() const { return mFieldProxyModel->filters(); }
66 
68  void setGeomCalculator( const QgsDistanceArea &da );
69 
75  QString currentField( bool *isExpression = nullptr, bool *isValid = nullptr ) const;
76 
80  bool isValidExpression( QString *expressionError = nullptr ) const;
81 
85  bool isExpression() const;
86 
90  QString currentText() const;
91 
98  QString asExpression() const;
99 
109  QString expression() const;
110 
112  QgsVectorLayer* layer() const;
113 
115  typedef QgsExpressionContext( *ExpressionContextCallback )( const void* context );
116 
124  void registerGetExpressionContextCallback( ExpressionContextCallback fnGetExpressionContext, const void* context );
125 
126  signals:
128  void fieldChanged( const QString& fieldName );
129 
131  void fieldChanged( const QString& fieldName, bool isValid );
132 
133 // void returnPressed();
134 
135  public slots:
137  void setLayer( QgsVectorLayer* layer );
138 
140  void setLayer( QgsMapLayer* layer );
141 
143  void setRow( int row ) { mCombo->setCurrentIndex( row ); }
144 
146  void setField( const QString &fieldName );
147 
154  void setExpression( const QString& expression );
155 
156  protected slots:
158  void editExpression();
159 
161  void expressionEdited( const QString& expression );
162 
164  void expressionEditingFinished();
165 
166  void currentFieldChanged();
167 
173  void updateLineEditStyle( const QString& expression = QString() );
174 
175  bool isExpressionValid( const QString& expressionStr );
176 
177  protected:
178  void changeEvent( QEvent* event ) override;
179 
180  private slots:
181  void reloadLayer();
182 
183  void beforeResetModel();
184  void afterResetModel();
185 
186  private:
187  QComboBox* mCombo;
188  QToolButton* mButton;
189  QgsFieldProxyModel* mFieldProxyModel;
190  QString mExpressionDialogTitle;
192  QScopedPointer< QgsExpressionContext > mExpressionContext;
193  ExpressionContextCallback mExpressionContextCallback;
194  const void* mExpressionContextCallbackContext;
195  QString mBackupExpression;
196 
197  friend class TestQgsFieldExpressionWidget;
198 };
199 
200 #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...
virtual void changeEvent(QEvent *event)
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.