Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression preview widget: do not disable feature picker (fixes #38646) #38797

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions src/gui/qgsexpressionpreviewwidget.cpp
Original file line number Diff line number Diff line change
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 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you remove this, that will bring back the issue when a layer is empty and you try an expression (#37100).
Or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this pull request, if the layer is empty (or you specify an invalid FID),

  • if the expression doesn't use fields, then it is evaluated
  • if the expression uses fields, the preview label displays "No feature was found on this layer to evaluate the expression" (not that the expression is invalid)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, that makes sense.

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