Skip to content

Commit b24a1bf

Browse files
committedDec 20, 2017
Add transform context to processing context
1 parent 90e5196 commit b24a1bf

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
 

‎python/core/processing/qgsprocessingcontext.sip

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ Returns the project in which the algorithm is being executed.
7070
%Docstring
7171
Sets the ``project`` in which the algorithm will be executed.
7272

73+
This also automatically sets the transformContext() to match
74+
the project's transform context.
75+
7376
.. seealso:: :py:func:`project()`
7477
%End
7578

@@ -82,6 +85,23 @@ Returns the expression context.
8285
void setExpressionContext( const QgsExpressionContext &context );
8386
%Docstring
8487
Sets the expression ``context``.
88+
%End
89+
90+
QgsCoordinateTransformContext transformContext() const;
91+
%Docstring
92+
Returns the coordinate transform context.
93+
94+
.. seealso:: :py:func:`setTransformContext()`
95+
%End
96+
97+
void setTransformContext( const QgsCoordinateTransformContext &context );
98+
%Docstring
99+
Sets the coordinate transform ``context``.
100+
101+
Note that setting a project for the context will automatically set the coordinate transform
102+
context.
103+
104+
.. seealso:: :py:func:`transformContext()`
85105
%End
86106

87107
QgsMapLayerStore *temporaryLayerStore();

‎src/core/processing/qgsprocessingcontext.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,18 @@ class CORE_EXPORT QgsProcessingContext
102102

103103
/**
104104
* Sets the \a project in which the algorithm will be executed.
105+
*
106+
* This also automatically sets the transformContext() to match
107+
* the project's transform context.
108+
*
105109
* \see project()
106110
*/
107-
void setProject( QgsProject *project ) { mProject = project; }
111+
void setProject( QgsProject *project )
112+
{
113+
mProject = project;
114+
if ( mProject )
115+
mTransformContext = mProject->transformContext();
116+
}
108117

109118
/**
110119
* Returns the expression context.
@@ -121,6 +130,22 @@ class CORE_EXPORT QgsProcessingContext
121130
*/
122131
void setExpressionContext( const QgsExpressionContext &context ) { mExpressionContext = context; }
123132

133+
/**
134+
* Returns the coordinate transform context.
135+
* \see setTransformContext()
136+
*/
137+
QgsCoordinateTransformContext transformContext() const { return mTransformContext; }
138+
139+
/**
140+
* Sets the coordinate transform \a context.
141+
*
142+
* Note that setting a project for the context will automatically set the coordinate transform
143+
* context.
144+
*
145+
* \see transformContext()
146+
*/
147+
void setTransformContext( const QgsCoordinateTransformContext &context ) { mTransformContext = context; }
148+
124149
/**
125150
* Returns a reference to the layer store used for storing temporary layers during
126151
* algorithm execution.
@@ -375,6 +400,7 @@ class CORE_EXPORT QgsProcessingContext
375400

376401
QgsProcessingContext::Flags mFlags = nullptr;
377402
QPointer< QgsProject > mProject;
403+
QgsCoordinateTransformContext mTransformContext;
378404
//! Temporary project owned by the context, used for storing temporarily loaded map layers
379405
QgsMapLayerStore tempLayerStore;
380406
QgsExpressionContext mExpressionContext;

0 commit comments

Comments
 (0)
Please sign in to comment.