Skip to content
Permalink
Browse files

Fix some missing expression context variables in processing expressio…

…n based widgets
  • Loading branch information
nyalldawson committed Feb 12, 2019
1 parent e533a40 commit 60a1d6306fe75c84374d88f0e5fab3731d569097
@@ -35,7 +35,8 @@
from qgis.core import (Qgis,
QgsApplication,
QgsSettings,
QgsProcessingParameterDefinition)
QgsProcessingParameterDefinition,
QgsProcessingModelAlgorithm)
from qgis.gui import (QgsProcessingParameterWidgetContext,
QgsProcessingContextGenerator)
from qgis.utils import iface
@@ -273,6 +274,9 @@ def setCellWrapper(self, row, column, wrapper, context):
widget_context = QgsProcessingParameterWidgetContext()
if iface is not None:
widget_context.setMapCanvas(iface.mapCanvas())
if isinstance(self.alg, QgsProcessingModelAlgorithm):
widget_context.setModel(self.alg)

wrapper.setWidgetContext(widget_context)
widget = wrapper.createWrappedWidget(context)
wrapper.registerProcessingContextGenerator(self.context_generator)
@@ -41,7 +41,8 @@
QgsProcessingParameterRasterDestination,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterVectorDestination,
QgsProject)
QgsProject,
QgsProcessingModelAlgorithm)
from qgis.gui import (QgsProcessingContextGenerator,
QgsProcessingParameterWidgetContext)
from qgis.utils import iface
@@ -128,6 +129,8 @@ def initWidgets(self):
widget_context = QgsProcessingParameterWidgetContext()
if iface is not None:
widget_context.setMapCanvas(iface.mapCanvas())
if isinstance(self.alg, QgsProcessingModelAlgorithm):
widget_context.setModel(self.alg)

# Create widgets and put them in layouts
for param in self.alg.parameterDefinitions():
@@ -245,7 +245,7 @@ QgsExpressionContext QgsAbstractProcessingParameterWidgetWrapper::createExpressi
if ( mWidgetContext.model()->childAlgorithms().contains( mWidgetContext.modelChildAlgorithmId() ) )
alg = mWidgetContext.model()->childAlgorithm( mWidgetContext.modelChildAlgorithmId() ).algorithm();

QgsExpressionContextScope *algorithmScope = QgsExpressionContextUtils::processingAlgorithmScope( alg, QVariantMap(), *context );
QgsExpressionContextScope *algorithmScope = QgsExpressionContextUtils::processingAlgorithmScope( alg ? alg : mParameterDefinition->algorithm(), QVariantMap(), *context );
c << algorithmScope;
QgsExpressionContextScope *childScope = mWidgetContext.model()->createExpressionContextScopeForChildAlgorithm( mWidgetContext.modelChildAlgorithmId(), *context, QVariantMap(), QVariantMap() );
c << childScope;
@@ -257,6 +257,11 @@ QgsExpressionContext QgsAbstractProcessingParameterWidgetWrapper::createExpressi
c.setHighlightedVariables( highlightedVariables );
c.setHighlightedFunctions( highlightedFunctions );
}
else
{
if ( mParameterDefinition->algorithm() )
c << QgsExpressionContextUtils::processingAlgorithmScope( mParameterDefinition->algorithm(), QVariantMap(), *context );
}

if ( linkedVectorLayer() )
c << QgsExpressionContextUtils::layerScope( linkedVectorLayer() );

0 comments on commit 60a1d63

Please sign in to comment.
You can’t perform that action at this time.