File tree Expand file tree Collapse file tree 4 files changed +30
-22
lines changed Expand file tree Collapse file tree 4 files changed +30
-22
lines changed Original file line number Diff line number Diff line change @@ -274,10 +274,11 @@ class QgsProcessingFeatureSource : QgsFeatureSource
274
274
virtual QVariant maximumValue( int fieldIndex ) const;
275
275
276
276
277
- QgsFeatureSource *source( ) const;
277
+ QgsExpressionContext createExpressionContext( const QgsProcessingContext &context ) const;
278
278
%Docstring
279
- Access the underlying original ``source``.
280
- :rtype: QgsFeatureSource
279
+ Returns an expression context scope suitable for this source or a default global/project
280
+ context if nothing more specific can be created.
281
+ :rtype: QgsExpressionContext
281
282
%End
282
283
283
284
};
Original file line number Diff line number Diff line change @@ -132,22 +132,16 @@ QgsExpressionContext QgsProcessingAlgorithm::createExpressionContext( const QVar
132
132
// If there's a source capable of generating a context scope, use it
133
133
if ( source )
134
134
{
135
- QgsExpressionContextGenerator *generator = dynamic_cast <QgsExpressionContextGenerator *>( source->source () );
136
- if ( generator )
137
- {
138
- const auto &scopes = generator->createExpressionContext ().takeScopes ();
139
- for ( QgsExpressionContextScope *scope : scopes )
140
- c << scope;
141
- }
135
+ const auto &scopes = source->createExpressionContext ( context ).takeScopes ();
136
+ for ( QgsExpressionContextScope *scope : scopes )
137
+ c << scope;
138
+ }
139
+ else if ( c.scopeCount () == 0 )
140
+ {
141
+ // empty scope, populate with initial scopes
142
+ c << QgsExpressionContextUtils::globalScope ()
143
+ << QgsExpressionContextUtils::projectScope ( context.project () );
142
144
}
143
- else
144
-
145
- if ( c.scopeCount () == 0 )
146
- {
147
- // empty scope, populate with initial scopes
148
- c << QgsExpressionContextUtils::globalScope ()
149
- << QgsExpressionContextUtils::projectScope ( context.project () );
150
- }
151
145
152
146
c << QgsExpressionContextUtils::processingAlgorithmScope ( this , parameters, context );
153
147
return c;
Original file line number Diff line number Diff line change @@ -721,7 +721,19 @@ QVariant QgsProcessingFeatureSource::maximumValue( int fieldIndex ) const
721
721
return mSource ->maximumValue ( fieldIndex );
722
722
}
723
723
724
- QgsFeatureSource * QgsProcessingFeatureSource::source ( ) const
724
+ QgsExpressionContext QgsProcessingFeatureSource::createExpressionContext ( const QgsProcessingContext &context ) const
725
725
{
726
- return mSource ;
726
+ QgsExpressionContext expressionContext;
727
+ QgsExpressionContextGenerator *generator = dynamic_cast <QgsExpressionContextGenerator *>( mSource );
728
+ if ( generator )
729
+ {
730
+ expressionContext = generator->createExpressionContext ();
731
+ }
732
+ else
733
+ {
734
+ expressionContext
735
+ << QgsExpressionContextUtils::globalScope ()
736
+ << QgsExpressionContextUtils::projectScope ( context.project () );
737
+ }
738
+ return expressionContext;
727
739
}
Original file line number Diff line number Diff line change @@ -320,9 +320,10 @@ class CORE_EXPORT QgsProcessingFeatureSource : public QgsFeatureSource
320
320
QVariant maximumValue ( int fieldIndex ) const override ;
321
321
322
322
/* *
323
- * Access the underlying original \a source.
323
+ * Returns an expression context scope suitable for this source or a default global/project
324
+ * context if nothing more specific can be created.
324
325
*/
325
- QgsFeatureSource * source ( ) const ;
326
+ QgsExpressionContext createExpressionContext ( const QgsProcessingContext &context ) const ;
326
327
327
328
private:
328
329
You can’t perform that action at this time.
0 commit comments