QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <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 = 0 );
52 
54  void setExpressionDialogTitle( QString title );
55 
57  const QString expressionDialogTitle() { return mExpressionDialogTitle; }
58 
60  void setFilters( 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 = 0, bool *isValid = 0 ) const;
76 
80  bool isValidExpression( QString *expressionError = 0 ) const;
81 
82  bool isExpression() const;
86  QString currentText() const;
87 
89  QgsVectorLayer* layer() const;
90 
92  typedef QgsExpressionContext( *ExpressionContextCallback )( const void* context );
93 
101  void registerGetExpressionContextCallback( ExpressionContextCallback fnGetExpressionContext, const void* context );
102 
103  signals:
105  void fieldChanged( QString fieldName );
106 
108  void fieldChanged( QString fieldName, bool isValid );
109 
110 // void returnPressed();
111 
112  public slots:
114  void setLayer( QgsVectorLayer* layer );
115 
117  void setLayer( QgsMapLayer* layer );
118 
120  void setField( const QString &fieldName );
121 
122  protected slots:
124  void editExpression();
125 
127  void expressionEdited( const QString expression );
128 
130  void expressionEditingFinished();
131 
132  void currentFieldChanged();
133 
139  void updateLineEditStyle( const QString expression = QString() );
140 
141  bool isExpressionValid( const QString expressionStr );
142 
143  protected:
144  void changeEvent( QEvent* event ) override;
145 
146  private:
147  QComboBox* mCombo;
148  QToolButton* mButton;
149  QgsFieldProxyModel* mFieldProxyModel;
150  QString mExpressionDialogTitle;
152  QScopedPointer< QgsExpressionContext > mExpressionContext;
153  ExpressionContextCallback mExpressionContextCallback;
154  const void* mExpressionContextCallbackContext;
155 };
156 
157 #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
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)
QgsFieldProxyModel::Filters filters() const
currently used filter on list of fields
General purpose distance and area calculator.
const QString expressionDialogTitle()
return the title used for the expression dialog
Represents a vector layer which manages a vector based data sets.