QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
29 mPreviewLabel->clear();
30 mFeaturePickerWidget->setShowBrowserButtons(
true );
33 connect( mPreviewLabel, &QLabel::linkActivated,
this, &QgsExpressionPreviewWidget::linkActivated );
39 mFeaturePickerWidget->setLayer( layer );
44 mExpressionText = expression;
59 mUseGeomCalculator =
true;
64 mExpressionContext = context;
67 void QgsExpressionPreviewWidget::refreshPreview()
71 if ( mExpressionText.isEmpty() )
73 mPreviewLabel->clear();
74 mPreviewLabel->setStyleSheet( QString() );
75 setExpressionToolTip( QString() );
87 mPreviewLabel->setText( tr(
"No feature was found on this layer to evaluate the expression." ) );
88 mPreviewLabel->setStyleSheet( QStringLiteral(
"color: rgba(255, 6, 10, 255);" ) );
93 if ( mUseGeomCalculator )
100 QVariant value = mExpression.
evaluate( &mExpressionContext );
111 tooltip = QStringLiteral(
"<b>%1:</b>"
112 "%2" ).arg( tr(
"Parser Errors" ), errorString );
115 tooltip += QStringLiteral(
"<b>%1:</b> %2" ).arg( tr(
"Eval Error" ), mExpression.
evalErrorString() );
117 mPreviewLabel->setText( tr(
"Expression is invalid <a href=""more"">(more info)</a>" ) );
118 mPreviewLabel->setStyleSheet( QStringLiteral(
"color: rgba(255, 6, 10, 255);" ) );
119 setExpressionToolTip( tooltip );
126 mPreviewLabel->setStyleSheet( QString() );
127 setExpressionToolTip( QString() );
129 setParserError(
false );
130 setEvalError(
false );
135 void QgsExpressionPreviewWidget::linkActivated(
const QString & )
137 QgsMessageViewer mv(
this, QgsGuiUtils::ModalDialogFlags,
false );
138 mv.setWindowTitle( tr(
"More Info on Expression Error" ) );
139 mv.setMessageAsHtml( mToolTip );
143 void QgsExpressionPreviewWidget::setExpressionToolTip(
const QString &toolTip )
145 if ( toolTip == mToolTip )
149 mPreviewLabel->setToolTip( mToolTip );
153 void QgsExpressionPreviewWidget::setParserError(
bool parserError )
166 void QgsExpressionPreviewWidget::setEvalError(
bool evalError )
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QString evalErrorString() const
Returns evaluation error.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
void setGeomCalculator(const QgsDistanceArea *calc)
Sets the geometry calculator used for distance and area calculations in expressions.
static QString formatPreviewString(const QVariant &value, bool htmlOutput=true)
Formats an expression result for friendly display to the user.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
QString parserErrorString() const
Returns parser error.
bool isValid() const
Returns the validity of this feature.
QVariant evaluate()
Evaluate the feature and return the result.
Represents a vector layer which manages a vector based data sets.
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
Class for parsing and evaluation of expressions (formerly called "search strings").
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.