@@ -225,50 +225,7 @@ void QgsAbstractProcessingParameterWidgetWrapper::postInitialize( const QList<Qg
225
225
226
226
QgsExpressionContext QgsAbstractProcessingParameterWidgetWrapper::createExpressionContext () const
227
227
{
228
- // Get a processing context to start with
229
- QgsProcessingContext *context = nullptr ;
230
- std::unique_ptr< QgsProcessingContext > tmpContext;
231
- if ( mProcessingContextGenerator )
232
- context = mProcessingContextGenerator ->processingContext ();
233
-
234
- if ( !context )
235
- {
236
- tmpContext = qgis::make_unique< QgsProcessingContext >();
237
- context = tmpContext.get ();
238
- }
239
-
240
- QgsExpressionContext c = context->expressionContext ();
241
-
242
- if ( mWidgetContext .model () )
243
- {
244
- c << QgsExpressionContextUtils::processingModelAlgorithmScope ( mWidgetContext .model (), QVariantMap (), *context );
245
-
246
- const QgsProcessingAlgorithm *alg = nullptr ;
247
- if ( mWidgetContext .model ()->childAlgorithms ().contains ( mWidgetContext .modelChildAlgorithmId () ) )
248
- alg = mWidgetContext .model ()->childAlgorithm ( mWidgetContext .modelChildAlgorithmId () ).algorithm ();
249
-
250
- QgsExpressionContextScope *algorithmScope = QgsExpressionContextUtils::processingAlgorithmScope ( alg ? alg : mParameterDefinition ->algorithm (), QVariantMap (), *context );
251
- c << algorithmScope;
252
- QgsExpressionContextScope *childScope = mWidgetContext .model ()->createExpressionContextScopeForChildAlgorithm ( mWidgetContext .modelChildAlgorithmId (), *context, QVariantMap (), QVariantMap () );
253
- c << childScope;
254
-
255
- QStringList highlightedVariables = childScope->variableNames ();
256
- QStringList highlightedFunctions = childScope->functionNames ();
257
- highlightedVariables += algorithmScope->variableNames ();
258
- highlightedFunctions += algorithmScope->functionNames ();
259
- c.setHighlightedVariables ( highlightedVariables );
260
- c.setHighlightedFunctions ( highlightedFunctions );
261
- }
262
- else
263
- {
264
- if ( mParameterDefinition ->algorithm () )
265
- c << QgsExpressionContextUtils::processingAlgorithmScope ( mParameterDefinition ->algorithm (), QVariantMap (), *context );
266
- }
267
-
268
- if ( linkedVectorLayer () )
269
- c << QgsExpressionContextUtils::layerScope ( linkedVectorLayer () );
270
-
271
- return c;
228
+ return QgsProcessingGuiUtils::createExpressionContext ( mProcessingContextGenerator , mWidgetContext , mParameterDefinition ? mParameterDefinition ->algorithm () : nullptr , linkedVectorLayer () );
272
229
}
273
230
274
231
void QgsAbstractProcessingParameterWidgetWrapper::parentLayerChanged ( QgsAbstractProcessingParameterWidgetWrapper *wrapper )
@@ -332,3 +289,56 @@ QString QgsProcessingParameterWidgetFactoryInterface::modelerExpressionFormatStr
332
289
return QString ();
333
290
}
334
291
292
+ //
293
+ // QgsProcessingGuiUtils
294
+ //
295
+
296
+ // /@cond PRIVATE
297
+ QgsExpressionContext QgsProcessingGuiUtils::createExpressionContext ( QgsProcessingContextGenerator *processingContextGenerator, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingAlgorithm *algorithm, const QgsVectorLayer *linkedLayer )
298
+ {
299
+ // Get a processing context to start with
300
+ QgsProcessingContext *context = nullptr ;
301
+ std::unique_ptr< QgsProcessingContext > tmpContext;
302
+ if ( processingContextGenerator )
303
+ context = processingContextGenerator->processingContext ();
304
+
305
+ if ( !context )
306
+ {
307
+ tmpContext = qgis::make_unique< QgsProcessingContext >();
308
+ context = tmpContext.get ();
309
+ }
310
+
311
+ QgsExpressionContext c = context->expressionContext ();
312
+
313
+ if ( widgetContext.model () )
314
+ {
315
+ c << QgsExpressionContextUtils::processingModelAlgorithmScope ( widgetContext.model (), QVariantMap (), *context );
316
+
317
+ const QgsProcessingAlgorithm *alg = nullptr ;
318
+ if ( widgetContext.model ()->childAlgorithms ().contains ( widgetContext.modelChildAlgorithmId () ) )
319
+ alg = widgetContext.model ()->childAlgorithm ( widgetContext.modelChildAlgorithmId () ).algorithm ();
320
+
321
+ QgsExpressionContextScope *algorithmScope = QgsExpressionContextUtils::processingAlgorithmScope ( alg ? alg : algorithm, QVariantMap (), *context );
322
+ c << algorithmScope;
323
+ QgsExpressionContextScope *childScope = widgetContext.model ()->createExpressionContextScopeForChildAlgorithm ( widgetContext.modelChildAlgorithmId (), *context, QVariantMap (), QVariantMap () );
324
+ c << childScope;
325
+
326
+ QStringList highlightedVariables = childScope->variableNames ();
327
+ QStringList highlightedFunctions = childScope->functionNames ();
328
+ highlightedVariables += algorithmScope->variableNames ();
329
+ highlightedFunctions += algorithmScope->functionNames ();
330
+ c.setHighlightedVariables ( highlightedVariables );
331
+ c.setHighlightedFunctions ( highlightedFunctions );
332
+ }
333
+ else
334
+ {
335
+ if ( algorithm )
336
+ c << QgsExpressionContextUtils::processingAlgorithmScope ( algorithm, QVariantMap (), *context );
337
+ }
338
+
339
+ if ( linkedLayer )
340
+ c << QgsExpressionContextUtils::layerScope ( linkedLayer );
341
+
342
+ return c;
343
+ }
344
+ // /@endcond
0 commit comments