Skip to content

Commit

Permalink
Fix some missing expression context variables in processing expressio…
Browse files Browse the repository at this point in the history
…n based widgets
  • Loading branch information
nyalldawson committed Feb 12, 2019
1 parent e533a40 commit 60a1d63
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion python/plugins/processing/gui/BatchPanel.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/gui/ParametersPanel.py
Expand Up @@ -41,7 +41,8 @@
QgsProcessingParameterRasterDestination,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterVectorDestination,
QgsProject)
QgsProject,
QgsProcessingModelAlgorithm)
from qgis.gui import (QgsProcessingContextGenerator,
QgsProcessingParameterWidgetContext)
from qgis.utils import iface
Expand Down Expand Up @@ -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():
Expand Down
7 changes: 6 additions & 1 deletion src/gui/processing/qgsprocessingwidgetwrapper.cpp
Expand Up @@ -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;
Expand All @@ -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() );
Expand Down

0 comments on commit 60a1d63

Please sign in to comment.