Skip to content

Commit

Permalink
Only use distance area calculator in expression preview results
Browse files Browse the repository at this point in the history
when it has been initialized correctly

Fixes #35628
  • Loading branch information
nyalldawson committed May 5, 2020
1 parent 0ada65b commit fdce7e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/gui/qgsexpressionpreviewwidget.cpp
Expand Up @@ -55,6 +55,7 @@ void QgsExpressionPreviewWidget::setCurrentFeature( const QgsFeature &feature )
void QgsExpressionPreviewWidget::setGeomCalculator( const QgsDistanceArea &da )
{
mDa = da;
mUseGeomCalculator = true;
}

void QgsExpressionPreviewWidget::setExpressionContext( const QgsExpressionContext &context )
Expand All @@ -78,10 +79,10 @@ void QgsExpressionPreviewWidget::refreshPreview()
{
mExpression = QgsExpression( mExpressionText );

if ( mLayer )
if ( mUseGeomCalculator )
{
// TODO: is this OK?
// Only set calculator if we have layer, else use default.
// only set an explicit geometry calculator if a call to setGeomCalculator was made. If not,
// let the expression context handle this correctly
mExpression.setGeomCalculator( &mDa );
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsexpressionpreviewwidget.h
Expand Up @@ -123,6 +123,7 @@ class GUI_EXPORT QgsExpressionPreviewWidget : public QWidget, private Ui::QgsExp
QgsVectorLayer *mLayer = nullptr;
QgsExpressionContext mExpressionContext;
QgsDistanceArea mDa;
bool mUseGeomCalculator = false;
QString mToolTip;
bool mEvalError = true;
bool mParserError = true;
Expand Down

0 comments on commit fdce7e2

Please sign in to comment.