QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
Public Slots | Signals | Public Member Functions | List of all members
QgsExpressionPreviewWidget Class Reference

QgsExpressionPreviewWidget is a widget to preview an expression result. More...

#include <qgsexpressionpreviewwidget.h>

Inheritance diagram for QgsExpressionPreviewWidget:
Inheritance graph
[legend]

Public Slots

void setCurrentFeature (const QgsFeature &feature)
 sets the current feature used More...
 

Signals

void evalErrorChanged ()
 Will be set to true if the current expression text reported an eval error with the context. More...
 
void expressionParsed (bool isValid)
 Emitted when the user changes the expression in the widget. More...
 
void parserErrorChanged ()
 Will be set to true if the current expression text reported a parser error with the context. More...
 
void toolTipChanged (const QString &toolTip)
 Emitted whenever the tool tip changed. More...
 

Public Member Functions

 QgsExpressionPreviewWidget (QWidget *parent=nullptr)
 Constructor. More...
 
QString currentPreviewText () const
 Returns the current expression result preview text. More...
 
bool evalError () const
 Will be set to true if the current expression text reported an eval error with the context. More...
 
QgsExpressionContext expressionContext () const
 Returns the expression context for the widget. More...
 
bool parserError () const
 Will be set to true if the current expression text reports a parser error with the context. More...
 
QList< QgsExpression::ParserErrorparserErrors () const
 Returns the expression parser errors. More...
 
const QgsExpressionNoderootNode () const
 Returns the root node of the expression. More...
 
void setCustomPreviewGenerator (const QString &label, const QList< QPair< QString, QVariant > > &choices, const std::function< QgsExpressionContext(const QVariant &) > &previewContextGenerator)
 Sets the widget to run using a custom preview generator. More...
 
void setExpressionContext (const QgsExpressionContext &context)
 Sets the expression context for the widget. More...
 
void setExpressionText (const QString &expression)
 Sets the expression. More...
 
void setGeomCalculator (const QgsDistanceArea &da)
 Sets geometry calculator used in distance/area calculations. More...
 
void setLayer (QgsVectorLayer *layer)
 Sets the layer used in the preview. More...
 

Detailed Description

QgsExpressionPreviewWidget is a widget to preview an expression result.

If the layer is set, one can browse across features to see the different outputs.

Since
QGIS 3.14

Definition at line 39 of file qgsexpressionpreviewwidget.h.

Constructor & Destructor Documentation

◆ QgsExpressionPreviewWidget()

QgsExpressionPreviewWidget::QgsExpressionPreviewWidget ( QWidget *  parent = nullptr)
explicit

Constructor.

Definition at line 27 of file qgsexpressionpreviewwidget.cpp.

Member Function Documentation

◆ currentPreviewText()

QString QgsExpressionPreviewWidget::currentPreviewText ( ) const

Returns the current expression result preview text.

Since
QGIS 3.38

Definition at line 229 of file qgsexpressionpreviewwidget.cpp.

◆ evalError()

bool QgsExpressionPreviewWidget::evalError ( ) const

Will be set to true if the current expression text reported an eval error with the context.

Definition at line 243 of file qgsexpressionpreviewwidget.cpp.

◆ evalErrorChanged

void QgsExpressionPreviewWidget::evalErrorChanged ( )
signal

Will be set to true if the current expression text reported an eval error with the context.

◆ expressionContext()

QgsExpressionContext QgsExpressionPreviewWidget::expressionContext ( ) const
inline

Returns the expression context for the widget.

The context is used for the expression preview result and for populating the list of available functions and variables.

See also
setExpressionContext

Definition at line 113 of file qgsexpressionpreviewwidget.h.

◆ expressionParsed

void QgsExpressionPreviewWidget::expressionParsed ( bool  isValid)
signal

Emitted when the user changes the expression in the widget.

Users of this widget should connect to this signal to decide if to let the user continue.

Parameters
isValidIs true if the expression the user has typed is valid.

◆ parserError()

bool QgsExpressionPreviewWidget::parserError ( ) const

Will be set to true if the current expression text reports a parser error with the context.

Definition at line 224 of file qgsexpressionpreviewwidget.cpp.

◆ parserErrorChanged

void QgsExpressionPreviewWidget::parserErrorChanged ( )
signal

Will be set to true if the current expression text reported a parser error with the context.

◆ parserErrors()

QList< QgsExpression::ParserError > QgsExpressionPreviewWidget::parserErrors ( ) const
inline

Returns the expression parser errors.

Definition at line 141 of file qgsexpressionpreviewwidget.h.

◆ rootNode()

const QgsExpressionNode * QgsExpressionPreviewWidget::rootNode ( ) const
inline

Returns the root node of the expression.

Definition at line 138 of file qgsexpressionpreviewwidget.h.

◆ setCurrentFeature

void QgsExpressionPreviewWidget::setCurrentFeature ( const QgsFeature feature)
slot

sets the current feature used

Definition at line 88 of file qgsexpressionpreviewwidget.cpp.

◆ setCustomPreviewGenerator()

void QgsExpressionPreviewWidget::setCustomPreviewGenerator ( const QString &  label,
const QList< QPair< QString, QVariant > > &  choices,
const std::function< QgsExpressionContext(const QVariant &) > &  previewContextGenerator 
)

Sets the widget to run using a custom preview generator.

In this mode, the widget will call a callback function to generate a new QgsExpressionContext as the previewed object changes. This can be used to provide custom preview values for different objects (i.e. for objects which aren't vector layer features).

Parameters
labelThe label to display for the combo box presenting choices of objects. This should be a representative name, eg "Band" if the widget is showing choices of raster layer bands
choicesA list of choices to present to the user. Each choice is a pair of a human-readable label and a QVariant representing the object to preview.
previewContextGeneratorA function which takes a QVariant representing the object to preview, and returns a QgsExpressionContext to use for previewing the object.
Since
QGIS 3.38

Definition at line 64 of file qgsexpressionpreviewwidget.cpp.

◆ setExpressionContext()

void QgsExpressionPreviewWidget::setExpressionContext ( const QgsExpressionContext context)

Sets the expression context for the widget.

The context is used for the expression preview result and to populate the list of available functions and variables.

Parameters
contextexpression context

Definition at line 104 of file qgsexpressionpreviewwidget.cpp.

◆ setExpressionText()

void QgsExpressionPreviewWidget::setExpressionText ( const QString &  expression)

Sets the expression.

Definition at line 79 of file qgsexpressionpreviewwidget.cpp.

◆ setGeomCalculator()

void QgsExpressionPreviewWidget::setGeomCalculator ( const QgsDistanceArea da)

Sets geometry calculator used in distance/area calculations.

Definition at line 98 of file qgsexpressionpreviewwidget.cpp.

◆ setLayer()

void QgsExpressionPreviewWidget::setLayer ( QgsVectorLayer layer)

Sets the layer used in the preview.

Definition at line 55 of file qgsexpressionpreviewwidget.cpp.

◆ toolTipChanged

void QgsExpressionPreviewWidget::toolTipChanged ( const QString &  toolTip)
signal

Emitted whenever the tool tip changed.


The documentation for this class was generated from the following files: