Skip to content

Commit 05dd5f1

Browse files
committed
Fix some missing expression context variables in processing expression based widgets
(cherry picked from commit 60a1d63)
1 parent 78a3556 commit 05dd5f1

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

python/plugins/processing/gui/BatchPanel.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
from qgis.core import (Qgis,
3636
QgsApplication,
3737
QgsSettings,
38-
QgsProcessingParameterDefinition)
38+
QgsProcessingParameterDefinition,
39+
QgsProcessingModelAlgorithm)
3940
from qgis.gui import (QgsProcessingParameterWidgetContext,
4041
QgsProcessingContextGenerator)
4142
from qgis.utils import iface
@@ -273,6 +274,9 @@ def setCellWrapper(self, row, column, wrapper, context):
273274
widget_context = QgsProcessingParameterWidgetContext()
274275
if iface is not None:
275276
widget_context.setMapCanvas(iface.mapCanvas())
277+
if isinstance(self.alg, QgsProcessingModelAlgorithm):
278+
widget_context.setModel(self.alg)
279+
276280
wrapper.setWidgetContext(widget_context)
277281
widget = wrapper.createWrappedWidget(context)
278282
wrapper.registerProcessingContextGenerator(self.context_generator)

python/plugins/processing/gui/ParametersPanel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
QgsProcessingParameterRasterDestination,
4242
QgsProcessingParameterFeatureSink,
4343
QgsProcessingParameterVectorDestination,
44-
QgsProject)
44+
QgsProject,
45+
QgsProcessingModelAlgorithm)
4546
from qgis.gui import (QgsProcessingContextGenerator,
4647
QgsProcessingParameterWidgetContext)
4748
from qgis.utils import iface
@@ -128,6 +129,8 @@ def initWidgets(self):
128129
widget_context = QgsProcessingParameterWidgetContext()
129130
if iface is not None:
130131
widget_context.setMapCanvas(iface.mapCanvas())
132+
if isinstance(self.alg, QgsProcessingModelAlgorithm):
133+
widget_context.setModel(self.alg)
131134

132135
# Create widgets and put them in layouts
133136
for param in self.alg.parameterDefinitions():

src/gui/processing/qgsprocessingwidgetwrapper.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ QgsExpressionContext QgsAbstractProcessingParameterWidgetWrapper::createExpressi
243243
if ( mWidgetContext.model()->childAlgorithms().contains( mWidgetContext.modelChildAlgorithmId() ) )
244244
alg = mWidgetContext.model()->childAlgorithm( mWidgetContext.modelChildAlgorithmId() ).algorithm();
245245

246-
QgsExpressionContextScope *algorithmScope = QgsExpressionContextUtils::processingAlgorithmScope( alg, QVariantMap(), *context );
246+
QgsExpressionContextScope *algorithmScope = QgsExpressionContextUtils::processingAlgorithmScope( alg ? alg : mParameterDefinition->algorithm(), QVariantMap(), *context );
247247
c << algorithmScope;
248248
QgsExpressionContextScope *childScope = mWidgetContext.model()->createExpressionContextScopeForChildAlgorithm( mWidgetContext.modelChildAlgorithmId(), *context, QVariantMap(), QVariantMap() );
249249
c << childScope;
@@ -255,6 +255,11 @@ QgsExpressionContext QgsAbstractProcessingParameterWidgetWrapper::createExpressi
255255
c.setHighlightedVariables( highlightedVariables );
256256
c.setHighlightedFunctions( highlightedFunctions );
257257
}
258+
else
259+
{
260+
if ( mParameterDefinition->algorithm() )
261+
c << QgsExpressionContextUtils::processingAlgorithmScope( mParameterDefinition->algorithm(), QVariantMap(), *context );
262+
}
258263

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

0 commit comments

Comments
 (0)