Skip to content

Commit

Permalink
Add transform context to processing context
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 20, 2017
1 parent 90e5196 commit b24a1bf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
20 changes: 20 additions & 0 deletions python/core/processing/qgsprocessingcontext.sip
Expand Up @@ -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

Expand All @@ -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();
Expand Down
28 changes: 27 additions & 1 deletion src/core/processing/qgsprocessingcontext.h
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b24a1bf

Please sign in to comment.