QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsexpressionpreviewwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsexpressionpreviewwidget.h
3 --------------------------------------
4 Date : march 2020 - quarantine day 12
5 Copyright : (C) 2020 by Denis Rouzaud
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 QGSEXPRESSIONPREVIEWWIDGET_H
17#define QGSEXPRESSIONPREVIEWWIDGET_H
18
19#include <QWidget>
20
21#include "ui_qgsexpressionpreviewbase.h"
22
23#include "qgis_gui.h"
24#include "qgsdistancearea.h"
25#include "qgsexpression.h"
27
28#include <functional>
29
30class QAction;
31class QgsVectorLayer;
32
39class GUI_EXPORT QgsExpressionPreviewWidget : public QWidget, private Ui::QgsExpressionPreviewWidgetBase
40{
41 Q_OBJECT
42 public:
44 explicit QgsExpressionPreviewWidget( QWidget *parent = nullptr );
45
47 void setLayer( QgsVectorLayer *layer );
48
49#ifndef SIP_RUN
50
64 void setCustomPreviewGenerator( const QString &label, const QList<QPair<QString, QVariant>> &choices, const std::function<QgsExpressionContext( const QVariant & )> &previewContextGenerator );
65#else
66
80 void setCustomPreviewGenerator( const QString &label, const QList<QPair<QString, QVariant>> &choices, SIP_PYCALLABLE );
81 //%MethodCode
82 Py_XINCREF( a2 );
83 Py_BEGIN_ALLOW_THREADS
84 sipCpp->setCustomPreviewGenerator( *a0, *a1, [a2]( const QVariant &value ) -> QgsExpressionContext {
86 SIP_BLOCK_THREADS
87 PyObject *s = sipCallMethod( NULL, a2, "D", &value, sipType_QVariant, NULL );
88 int state;
89 int sipIsError = 0;
90 QgsExpressionContext *t1 = reinterpret_cast<QgsExpressionContext *>( sipConvertToType( s, sipType_QgsExpressionContext, 0, SIP_NOT_NONE, &state, &sipIsError ) );
91 if ( sipIsError == 0 )
92 {
93 res = QgsExpressionContext( *t1 );
94 }
95 sipReleaseType( t1, sipType_QgsExpressionContext, state );
96 SIP_UNBLOCK_THREADS
97 return res;
98 } );
99
100 Py_END_ALLOW_THREADS
101 //%End
102#endif
103
105 void setExpressionText( const QString &expression );
106
112 QgsExpressionContext expressionContext() const { return mExpressionContext; }
113
119 void setExpressionContext( const QgsExpressionContext &context );
120
122 void setGeomCalculator( const QgsDistanceArea &da );
123
128 bool evalError() const;
129
134 bool parserError() const;
135
137 const QgsExpressionNode *rootNode() const { return mExpression.rootNode(); }
138
140 QList<QgsExpression::ParserError> parserErrors() const { return mExpression.parserErrors(); }
141
147 QString currentPreviewText() const;
148
149 signals:
150
157 void expressionParsed( bool isValid );
158
164
170
172 void toolTipChanged( const QString &toolTip );
173
174 public slots:
176 void setCurrentFeature( const QgsFeature &feature );
177
178
179 private slots:
180 void linkActivated( const QString & );
181 void setEvalError( bool evalError );
182 void setParserError( bool parserError );
183 void copyFullExpressionValue();
184 void setCustomChoice( int );
185
186 private:
187 void setExpressionToolTip( const QString &toolTip );
188 void refreshPreview();
189
190 QgsVectorLayer *mLayer = nullptr;
191 QgsExpressionContext mExpressionContext;
192 QgsDistanceArea mDa;
193 bool mUseGeomCalculator = false;
194 QString mToolTip;
195 bool mEvalError = true;
196 bool mParserError = true;
197 QString mExpressionText;
198 QgsExpression mExpression;
199 QAction *mCopyPreviewAction = nullptr;
200
201 std::function<QgsExpressionContext( const QVariant & )> mCustomPreviewGeneratorFunction;
202};
203
204#endif // QGSEXPRESSIONPREVIEWWIDGET_H
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Abstract base class for all nodes that can appear in an expression.
QgsExpressionPreviewWidget is a widget to preview an expression result.
const QgsExpressionNode * rootNode() const
Returns the root node of the expression.
void parserErrorChanged()
Will be set to true if the current expression text reported a parser error with the context.
QList< QgsExpression::ParserError > parserErrors() const
Returns the expression parser errors.
QgsExpressionContext expressionContext() const
Returns the expression context for the widget.
void evalErrorChanged()
Will be set to true if the current expression text reported an eval error with the context.
void toolTipChanged(const QString &toolTip)
Emitted whenever the tool tip changed.
void expressionParsed(bool isValid)
Emitted when the user changes the expression in the widget.
Class for parsing and evaluation of expressions (formerly called "search strings").
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Represents a vector layer which manages a vector based data sets.