mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-13 00:07:27 -05:00
Expression context creation for processing improvements
Hiding away the implementation directly in QgsProcessingFeatureSource
See discussion ec97102bc6 (r152903378)
This commit is contained in:
parent
fd127ee6a4
commit
abe1a9b661
@ -274,10 +274,11 @@ class QgsProcessingFeatureSource : QgsFeatureSource
|
||||
virtual QVariant maximumValue( int fieldIndex ) const;
|
||||
|
||||
|
||||
QgsFeatureSource *source() const;
|
||||
QgsExpressionContext createExpressionContext( const QgsProcessingContext &context ) const;
|
||||
%Docstring
|
||||
Access the underlying original ``source``.
|
||||
:rtype: QgsFeatureSource
|
||||
Returns an expression context scope suitable for this source or a default global/project
|
||||
context if nothing more specific can be created.
|
||||
:rtype: QgsExpressionContext
|
||||
%End
|
||||
|
||||
};
|
||||
|
||||
@ -132,17 +132,11 @@ QgsExpressionContext QgsProcessingAlgorithm::createExpressionContext( const QVar
|
||||
// If there's a source capable of generating a context scope, use it
|
||||
if ( source )
|
||||
{
|
||||
QgsExpressionContextGenerator *generator = dynamic_cast<QgsExpressionContextGenerator *>( source->source() );
|
||||
if ( generator )
|
||||
{
|
||||
const auto &scopes = generator->createExpressionContext().takeScopes();
|
||||
const auto &scopes = source->createExpressionContext( context ).takeScopes();
|
||||
for ( QgsExpressionContextScope *scope : scopes )
|
||||
c << scope;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if ( c.scopeCount() == 0 )
|
||||
else if ( c.scopeCount() == 0 )
|
||||
{
|
||||
//empty scope, populate with initial scopes
|
||||
c << QgsExpressionContextUtils::globalScope()
|
||||
|
||||
@ -721,7 +721,19 @@ QVariant QgsProcessingFeatureSource::maximumValue( int fieldIndex ) const
|
||||
return mSource->maximumValue( fieldIndex );
|
||||
}
|
||||
|
||||
QgsFeatureSource *QgsProcessingFeatureSource::source() const
|
||||
QgsExpressionContext QgsProcessingFeatureSource::createExpressionContext( const QgsProcessingContext &context ) const
|
||||
{
|
||||
return mSource;
|
||||
QgsExpressionContext expressionContext;
|
||||
QgsExpressionContextGenerator *generator = dynamic_cast<QgsExpressionContextGenerator *>( mSource );
|
||||
if ( generator )
|
||||
{
|
||||
expressionContext = generator->createExpressionContext();
|
||||
}
|
||||
else
|
||||
{
|
||||
expressionContext
|
||||
<< QgsExpressionContextUtils::globalScope()
|
||||
<< QgsExpressionContextUtils::projectScope( context.project() );
|
||||
}
|
||||
return expressionContext;
|
||||
}
|
||||
|
||||
@ -320,9 +320,10 @@ class CORE_EXPORT QgsProcessingFeatureSource : public QgsFeatureSource
|
||||
QVariant maximumValue( int fieldIndex ) const override;
|
||||
|
||||
/**
|
||||
* Access the underlying original \a source.
|
||||
* Returns an expression context scope suitable for this source or a default global/project
|
||||
* context if nothing more specific can be created.
|
||||
*/
|
||||
QgsFeatureSource *source() const;
|
||||
QgsExpressionContext createExpressionContext( const QgsProcessingContext &context ) const;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user