Skip to content

Commit 2695e00

Browse files
committed
Add a context getter to QgsCoordinateTransform
1 parent a04d228 commit 2695e00

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

python/core/auto_generated/qgscoordinatetransform.sip.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,19 @@ Sets the destination coordinate reference system.
156156
Sets the ``context`` in which the coordinate transform should be
157157
calculated.
158158

159+
.. seealso:: :py:func:`context`
160+
159161
.. versionadded:: 3.0
162+
%End
163+
164+
QgsCoordinateTransformContext context() const;
165+
%Docstring
166+
Returns the context in which the coordinate transform will be
167+
calculated.
168+
169+
.. seealso:: :py:func:`setContext`
170+
171+
.. versionadded:: 3.4
160172
%End
161173

162174
QgsCoordinateReferenceSystem sourceCrs() const;

src/core/qgscoordinatetransform.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ void QgsCoordinateTransform::setContext( const QgsCoordinateTransformContext &co
185185
}
186186
}
187187

188+
QgsCoordinateTransformContext QgsCoordinateTransform::context() const
189+
{
190+
return mContext;
191+
}
192+
188193
QgsCoordinateReferenceSystem QgsCoordinateTransform::sourceCrs() const
189194
{
190195
return d->mSourceCRS;

src/core/qgscoordinatetransform.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,19 @@ class CORE_EXPORT QgsCoordinateTransform
175175
/**
176176
* Sets the \a context in which the coordinate transform should be
177177
* calculated.
178+
* \see context()
178179
* \since QGIS 3.0
179180
*/
180181
void setContext( const QgsCoordinateTransformContext &context );
181182

183+
/**
184+
* Returns the context in which the coordinate transform will be
185+
* calculated.
186+
* \see setContext()
187+
* \since QGIS 3.4
188+
*/
189+
QgsCoordinateTransformContext context() const;
190+
182191
/**
183192
* Returns the source coordinate reference system, which the transform will
184193
* transform coordinates from.

src/quickgui/qgsquickcoordinatetransformer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,13 @@ void QgsQuickCoordinateTransformer::setSourceCrs( const QgsCoordinateReferenceSy
7676

7777
void QgsQuickCoordinateTransformer::setTransformContext( const QgsCoordinateTransformContext &context )
7878
{
79-
mTransformContext = context;
80-
mCoordinateTransform.setContext( mTransformContext );
79+
mCoordinateTransform.setContext( context );
8180
emit transformContextChanged();
8281
}
8382

8483
QgsCoordinateTransformContext QgsQuickCoordinateTransformer::transformContext() const
8584
{
86-
return mTransformContext;
85+
return mCoordinateTransform.context();
8786
}
8887

8988
void QgsQuickCoordinateTransformer::updatePosition()

src/quickgui/qgsquickcoordinatetransformer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ class QUICK_EXPORT QgsQuickCoordinateTransformer : public QObject
108108
QgsPoint mProjectedPosition;
109109
QgsPoint mSourcePosition;
110110
QgsCoordinateTransform mCoordinateTransform;
111-
QgsCoordinateTransformContext mTransformContext;
112111
};
113112

114113
#endif // QGSQUICKCOORDINATETRANSFORMER_H

tests/src/python/test_qgscoordinatetransform.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def testContext(self):
145145
3, 4)
146146

147147
transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:28354'), QgsCoordinateReferenceSystem('EPSG:28353'), context)
148+
self.assertEqual(list(transform.context().sourceDestinationDatumTransforms().keys()), [('EPSG:28356', 'EPSG:4283')])
148149
# should be no datum transforms
149150
self.assertEqual(transform.sourceDatumTransformId(), -1)
150151
self.assertEqual(transform.destinationDatumTransformId(), -1)
@@ -193,6 +194,7 @@ def testContext(self):
193194
transform.setContext(context)
194195
self.assertEqual(transform.sourceDatumTransformId(), 3)
195196
self.assertEqual(transform.destinationDatumTransformId(), 4)
197+
self.assertEqual(list(transform.context().sourceDestinationDatumTransforms().keys()), [('EPSG:28356', 'EPSG:4283')])
196198

197199
def testProjectContext(self):
198200
"""

0 commit comments

Comments
 (0)