QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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
85 {
87 SIP_BLOCK_THREADS
88 PyObject *s = sipCallMethod( NULL, a2, "D", &value, sipType_QVariant, NULL );
89 int state;
90 int sipIsError = 0;
91 QgsExpressionContext *t1 = reinterpret_cast<QgsExpressionContext *>( sipConvertToType( s, sipType_QgsExpressionContext, 0, SIP_NOT_NONE, &state, &sipIsError ) );
92 if ( sipIsError == 0 )
93 {
94 res = QgsExpressionContext( *t1 );
95 }
96 sipReleaseType( t1, sipType_QgsExpressionContext, state );
97 SIP_UNBLOCK_THREADS
98 return res;
99 } );
100
101 Py_END_ALLOW_THREADS
102 % End
103#endif
104
106 void setExpressionText( const QString &expression );
107
113 QgsExpressionContext expressionContext() const { return mExpressionContext; }
114
120 void setExpressionContext( const QgsExpressionContext &context );
121
123 void setGeomCalculator( const QgsDistanceArea &da );
124
129 bool evalError() const;
130
135 bool parserError() const;
136
138 const QgsExpressionNode *rootNode() const {return mExpression.rootNode();}
139
141 QList<QgsExpression::ParserError> parserErrors() const {return mExpression.parserErrors();}
142
148 QString currentPreviewText() const;
149
150 signals:
151
158 void expressionParsed( bool isValid );
159
165
171
173 void toolTipChanged( const QString &toolTip );
174
175 public slots:
177 void setCurrentFeature( const QgsFeature &feature );
178
179
180 private slots:
181 void linkActivated( const QString & );
182 void setEvalError( bool evalError );
183 void setParserError( bool parserError );
184 void copyFullExpressionValue();
185 void setCustomChoice( int );
186
187 private:
188 void setExpressionToolTip( const QString &toolTip );
189 void refreshPreview();
190
191 QgsVectorLayer *mLayer = nullptr;
192 QgsExpressionContext mExpressionContext;
193 QgsDistanceArea mDa;
194 bool mUseGeomCalculator = false;
195 QString mToolTip;
196 bool mEvalError = true;
197 bool mParserError = true;
198 QString mExpressionText;
199 QgsExpression mExpression;
200 QAction *mCopyPreviewAction = nullptr;
201
202 std::function< QgsExpressionContext( const QVariant & ) > mCustomPreviewGeneratorFunction;
203};
204
205#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.