Skip to content
Permalink
Browse files

[processing] When configurating a field calculator algorithm in a model,

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 7, 2021
1 parent c57ab07 commit c1a9088b3da1f767618d62be1caadc5cbab48803
@@ -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 );
@@ -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
@@ -1994,6 +1994,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
@@ -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 );

0 comments on commit c1a9088

Please sign in to comment.