QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
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;
69 mUseGeomCalculator =
true;
74 mExpressionContext = context;
77 void QgsExpressionPreviewWidget::refreshPreview()
81 if ( mExpressionText.isEmpty() )
83 mPreviewLabel->clear();
84 mPreviewLabel->setStyleSheet( QString() );
85 setExpressionToolTip( QString() );
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.
void setValid(bool validity)
Sets the validity of the feature.
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.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.