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 );
104 mPreviewLabel->setText( preview );
112 tooltip = QStringLiteral(
"<b>%1:</b>"
113 "%2" ).arg( tr(
"Parser Errors" ), errorString );
116 tooltip += QStringLiteral(
"<b>%1:</b> %2" ).arg( tr(
"Eval Error" ), mExpression.
evalErrorString() );
118 mPreviewLabel->setText( tr(
"Expression is invalid <a href=""more"">(more info)</a>" ) );
119 mPreviewLabel->setStyleSheet( QStringLiteral(
"color: rgba(255, 6, 10, 255);" ) );
120 setExpressionToolTip( tooltip );
127 mPreviewLabel->setStyleSheet( QString() );
129 if ( longerPreview != preview )
130 setExpressionToolTip( longerPreview );
132 setExpressionToolTip( QString() );
134 setParserError(
false );
135 setEvalError(
false );
140 void QgsExpressionPreviewWidget::linkActivated(
const QString & )
143 mv.setWindowTitle( tr(
"More Info on Expression Error" ) );
144 mv.setMessageAsHtml( mToolTip );
148 void QgsExpressionPreviewWidget::setExpressionToolTip(
const QString &toolTip )
150 if ( toolTip == mToolTip )
154 mPreviewLabel->setToolTip( mToolTip );
158 void QgsExpressionPreviewWidget::setParserError(
bool parserError )
171 void QgsExpressionPreviewWidget::setEvalError(
bool evalError )
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...
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
QString evalErrorString() const
Returns evaluation error.
QString parserErrorString() const
Returns parser error.
static QString formatPreviewString(const QVariant &value, bool htmlOutput=true, int maximumPreviewLength=60)
Formats an expression result for friendly display to the user.
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.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
QVariant evaluate()
Evaluate the feature and return the result.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool isValid() const
Returns the validity of this feature.
A generic message view for displaying QGIS messages.
Represents a vector layer which manages a vector based data sets.