Skip to content

Commit

Permalink
[processing] When configurating a field calculator algorithm in a model,
Browse files Browse the repository at this point in the history
ensure that the correct expression context is set for the widget

Otherwise we don't see any of the available variables ready for
use in the calculation.

We need to do this manually after creating the widget, because the
context generator isn't set till after the widget is created, and
this particular widget configuration doesn't fetch the expression
context on demand.
  • Loading branch information
nyalldawson committed Apr 1, 2021
1 parent 22dc611 commit 615b63e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Expand Up @@ -332,10 +332,12 @@ Returns the current value of the parameter.
Returns any custom properties set by the wrapper.
%End

void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
virtual void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
%Docstring
Registers a Processing context ``generator`` class that will be used to retrieve
a Processing context for the wrapper when required.

Care must be taken to call the base class implementation if overwrite this method.
%End

void registerProcessingParametersGenerator( QgsProcessingParametersGenerator *generator );
Expand Down
4 changes: 3 additions & 1 deletion src/gui/processing/qgsprocessingwidgetwrapper.h
Expand Up @@ -373,8 +373,10 @@ class GUI_EXPORT QgsAbstractProcessingParameterWidgetWrapper : public QObject, p
/**
* Registers a Processing context \a generator class that will be used to retrieve
* a Processing context for the wrapper when required.
*
* Care must be taken to call the base class implementation if overwrite this method.
*/
void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
virtual void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );

/**
* Registers a Processing parameters \a generator class that will be used to retrieve
Expand Down
10 changes: 10 additions & 0 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Expand Up @@ -1990,6 +1990,16 @@ void QgsProcessingExpressionWidgetWrapper::postInitialize( const QList<QgsAbstra
}
}

void QgsProcessingExpressionWidgetWrapper::registerProcessingContextGenerator( QgsProcessingContextGenerator *generator )
{
QgsAbstractProcessingParameterWidgetWrapper::registerProcessingContextGenerator( generator );
if ( mExpBuilderWidget )
{
// we need to regenerate the expression context for use by this widget -- it doesn't fetch automatically on demand
mExpBuilderWidget->setExpressionContext( createExpressionContext() );
}
}

void QgsProcessingExpressionWidgetWrapper::setParentLayerWrapperValue( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper )
{
// evaluate value to layer
Expand Down
1 change: 1 addition & 0 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.h
Expand Up @@ -662,6 +662,7 @@ class GUI_EXPORT QgsProcessingExpressionWidgetWrapper : public QgsAbstractProces
// QgsProcessingParameterWidgetWrapper interface
QWidget *createWidget() override SIP_FACTORY;
void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers ) override;
void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator ) override;

public slots:
void setParentLayerWrapperValue( const QgsAbstractProcessingParameterWidgetWrapper *parentWrapper );
Expand Down

0 comments on commit 615b63e

Please sign in to comment.