diff --git a/python/core/processing/qgsprocessingcontext.sip b/python/core/processing/qgsprocessingcontext.sip index 1222195b3e7..6ff74e51ea9 100644 --- a/python/core/processing/qgsprocessingcontext.sip +++ b/python/core/processing/qgsprocessingcontext.sip @@ -70,6 +70,9 @@ Returns the project in which the algorithm is being executed. %Docstring Sets the ``project`` in which the algorithm will be executed. +This also automatically sets the transformContext() to match +the project's transform context. + .. seealso:: :py:func:`project()` %End @@ -82,6 +85,23 @@ Returns the expression context. void setExpressionContext( const QgsExpressionContext &context ); %Docstring Sets the expression ``context``. +%End + + QgsCoordinateTransformContext transformContext() const; +%Docstring +Returns the coordinate transform context. + +.. seealso:: :py:func:`setTransformContext()` +%End + + void setTransformContext( const QgsCoordinateTransformContext &context ); +%Docstring +Sets the coordinate transform ``context``. + +Note that setting a project for the context will automatically set the coordinate transform +context. + +.. seealso:: :py:func:`transformContext()` %End QgsMapLayerStore *temporaryLayerStore(); diff --git a/src/core/processing/qgsprocessingcontext.h b/src/core/processing/qgsprocessingcontext.h index 4493361f740..6aad4e66911 100644 --- a/src/core/processing/qgsprocessingcontext.h +++ b/src/core/processing/qgsprocessingcontext.h @@ -102,9 +102,18 @@ class CORE_EXPORT QgsProcessingContext /** * Sets the \a project in which the algorithm will be executed. + * + * This also automatically sets the transformContext() to match + * the project's transform context. + * * \see project() */ - void setProject( QgsProject *project ) { mProject = project; } + void setProject( QgsProject *project ) + { + mProject = project; + if ( mProject ) + mTransformContext = mProject->transformContext(); + } /** * Returns the expression context. @@ -121,6 +130,22 @@ class CORE_EXPORT QgsProcessingContext */ void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; } + /** + * Returns the coordinate transform context. + * \see setTransformContext() + */ + QgsCoordinateTransformContext transformContext() const { return mTransformContext; } + + /** + * Sets the coordinate transform \a context. + * + * Note that setting a project for the context will automatically set the coordinate transform + * context. + * + * \see transformContext() + */ + void setTransformContext( const QgsCoordinateTransformContext &context ) { mTransformContext = context; } + /** * Returns a reference to the layer store used for storing temporary layers during * algorithm execution. @@ -375,6 +400,7 @@ class CORE_EXPORT QgsProcessingContext QgsProcessingContext::Flags mFlags = nullptr; QPointer< QgsProject > mProject; + QgsCoordinateTransformContext mTransformContext; //! Temporary project owned by the context, used for storing temporarily loaded map layers QgsMapLayerStore tempLayerStore; QgsExpressionContext mExpressionContext;