Skip to content

Commit

Permalink
Expression preview widget: do not disable feature picker (fixes #38646)
Browse files Browse the repository at this point in the history
In the text edit of the feature picker, if one currently enters an invalid value,
the whole feature picker becomes disabled, which requires to close and re-open
the expression string builder dialog.

So instead of doing this, use the preview label to indicate that a valid
feature is needed to evaluate the expression, for expressions that require feature
fields.

Previous related pull requests are:
#37518
#37139
  • Loading branch information
rouault authored and nyalldawson committed Sep 16, 2020
1 parent e79103e commit ecc8405
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/gui/qgsexpressionpreviewwidget.cpp
Expand Up @@ -49,20 +49,7 @@ void QgsExpressionPreviewWidget::setCurrentFeature( const QgsFeature &feature )
{
// todo: update the combo box if it has been set externaly?

// force the feature to be valid, so it can evaluate an invalid feature but having its fields set
if ( !feature.isValid() )
{
QgsFeature validFeature( feature );
validFeature.setValid( true );
mExpressionContext.setFeature( validFeature );
mFeaturePickerWidget->setEnabled( false );
mFeaturePickerWidget->setToolTip( tr( "No feature was found on this layer to evaluate the expression." ) );
}
else
{
mExpressionContext.setFeature( feature );
mFeaturePickerWidget->setEnabled( true );
}
mExpressionContext.setFeature( feature );
refreshPreview();
}

Expand Down Expand Up @@ -93,6 +80,16 @@ void QgsExpressionPreviewWidget::refreshPreview()
{
mExpression = QgsExpression( mExpressionText );

if ( !mExpressionContext.feature().isValid() )
{
if ( !mExpression.referencedColumns().isEmpty() || mExpression.needsGeometry() )
{
mPreviewLabel->setText( tr( "No feature was found on this layer to evaluate the expression." ) );
mPreviewLabel->setStyleSheet( QStringLiteral( "color: rgba(255, 6, 10, 255);" ) );
return;
}
}

if ( mUseGeomCalculator )
{
// only set an explicit geometry calculator if a call to setGeomCalculator was made. If not,
Expand Down

0 comments on commit ecc8405

Please sign in to comment.