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() );
83 if ( mUseGeomCalculator )
90 const QVariant value = mExpression.
evaluate( &mExpressionContext );
94 mPreviewLabel->setText( preview );
106 mPreviewLabel->setText( tr(
"No feature was found on this layer to evaluate the expression." ) );
107 mPreviewLabel->setStyleSheet( QStringLiteral(
"color: rgba(220, 125, 0, 255);" ) );
109 setParserError(
false );
110 setEvalError(
false );
115 const QString errorString = mExpression.
parserErrorString().replace( QLatin1String(
"\n" ), QLatin1String(
"<br>" ) );
118 tooltip = QStringLiteral(
"<b>%1:</b>"
119 "%2" ).arg( tr(
"Parser Errors" ), errorString );
122 tooltip += QStringLiteral(
"<b>%1:</b> %2" ).arg( tr(
"Eval Error" ), mExpression.
evalErrorString() );
124 mPreviewLabel->setText( tr(
"Expression is invalid <a href=""more"">(more info)</a>" ) );
125 mPreviewLabel->setStyleSheet( QStringLiteral(
"color: rgba(255, 6, 10, 255);" ) );
126 setExpressionToolTip( tooltip );
133 mPreviewLabel->setStyleSheet( QString() );
135 if ( longerPreview != preview )
136 setExpressionToolTip( longerPreview );
138 setExpressionToolTip( QString() );
140 setParserError(
false );
141 setEvalError(
false );
146 void QgsExpressionPreviewWidget::linkActivated(
const QString & )
149 mv.setWindowTitle( tr(
"More Info on Expression Error" ) );
150 mv.setMessageAsHtml( mToolTip );
154 void QgsExpressionPreviewWidget::setExpressionToolTip(
const QString &toolTip )
156 if ( toolTip == mToolTip )
160 mPreviewLabel->setToolTip( mToolTip );
164 void QgsExpressionPreviewWidget::setParserError(
bool parserError )
177 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 unique ID, geometry and a list of field...
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.