Skip to content

Commit

Permalink
Add explicit setter for project's transform context
Browse files Browse the repository at this point in the history
And add transformContextChanged signal, so that we can detect
when the context is changed.
  • Loading branch information
nyalldawson committed Dec 15, 2017
1 parent 1a73fef commit 6201390
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
27 changes: 24 additions & 3 deletions python/core/qgsproject.sip
Expand Up @@ -128,17 +128,29 @@ Returns the QgsProject singleton instance
%End %End





QgsCoordinateTransformContext transformContext() const;
QgsCoordinateTransformContext &transformContext();
%Docstring %Docstring
Returns a modifiable reference to the project's coordinate transform context, which stores various Returns a copy of the project's coordinate transform context, which stores various
information regarding which datum transforms should be used when transforming points information regarding which datum transforms should be used when transforming points
from a source to destination coordinate reference system. from a source to destination coordinate reference system.


.. versionadded:: 3.0 .. versionadded:: 3.0
.. seealso:: setTransformContext()
.. seealso:: transformContextChanged()
:rtype: QgsCoordinateTransformContext :rtype: QgsCoordinateTransformContext
%End %End


void setTransformContext( const QgsCoordinateTransformContext &context );
%Docstring
Sets the project's coordinate transform ``context``, which stores various
information regarding which datum transforms should be used when transforming points
from a source to destination coordinate reference system.

.. versionadded:: 3.0
.. seealso:: transformContext()
.. seealso:: transformContextChanged()
%End

void clear(); void clear();
%Docstring %Docstring
Clear the project - removes all settings and resets it back to an empty, default state. Clear the project - removes all settings and resets it back to an empty, default state.
Expand Down Expand Up @@ -924,6 +936,15 @@ emitted whenever the configuration for snapping has changed
.. seealso:: :py:func:`ellipsoid()` .. seealso:: :py:func:`ellipsoid()`
%End %End



void transformContextChanged();
%Docstring
Emitted when the project transformContext() is changed.

.. versionadded:: 3.0
.. seealso:: transformContext()
%End

void transactionGroupsChanged(); void transactionGroupsChanged();
%Docstring %Docstring
Emitted whenever a new transaction group has been created or a Emitted whenever a new transaction group has been created or a
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsproject.cpp
Expand Up @@ -476,9 +476,10 @@ QgsCoordinateTransformContext QgsProject::transformContext() const
return mTransformContext; return mTransformContext;
} }


QgsCoordinateTransformContext &QgsProject::transformContext() void QgsProject::setTransformContext( const QgsCoordinateTransformContext &context )
{ {
return mTransformContext; mTransformContext = context;
emit transformContextChanged();
} }


void QgsProject::clear() void QgsProject::clear()
Expand Down
19 changes: 16 additions & 3 deletions src/core/qgsproject.h
Expand Up @@ -186,17 +186,21 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
* from a source to destination coordinate reference system. * from a source to destination coordinate reference system.
* *
* \since QGIS 3.0 * \since QGIS 3.0
* \see setTransformContext()
* \see transformContextChanged()
*/ */
QgsCoordinateTransformContext transformContext() const SIP_SKIP; QgsCoordinateTransformContext transformContext() const;


/** /**
* Returns a modifiable reference to the project's coordinate transform context, which stores various * Sets the project's coordinate transform \a context, which stores various
* information regarding which datum transforms should be used when transforming points * information regarding which datum transforms should be used when transforming points
* from a source to destination coordinate reference system. * from a source to destination coordinate reference system.
* *
* \since QGIS 3.0 * \since QGIS 3.0
* \see transformContext()
* \see transformContextChanged()
*/ */
QgsCoordinateTransformContext &transformContext(); void setTransformContext( const QgsCoordinateTransformContext &context );


/** /**
* Clear the project - removes all settings and resets it back to an empty, default state. * Clear the project - removes all settings and resets it back to an empty, default state.
Expand Down Expand Up @@ -920,6 +924,15 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/ */
void ellipsoidChanged( const QString &ellipsoid ); void ellipsoidChanged( const QString &ellipsoid );



/**
* Emitted when the project transformContext() is changed.
*
* \since QGIS 3.0
* \see transformContext()
*/
void transformContextChanged();

/** /**
* Emitted whenever a new transaction group has been created or a * Emitted whenever a new transaction group has been created or a
* transaction group has been removed. * transaction group has been removed.
Expand Down
4 changes: 3 additions & 1 deletion tests/src/python/test_qgscoordinatetransform.py
Expand Up @@ -138,7 +138,9 @@ def testProjectContext(self):
Test creating transform using convenience constructor which takes project reference Test creating transform using convenience constructor which takes project reference
""" """
p = QgsProject() p = QgsProject()
p.transformContext().addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'), 1) context = p.transformContext()
context.addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'), 1)
p.setTransformContext(context)


transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:28356'), QgsCoordinateReferenceSystem('EPSG:28353'), p) transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:28356'), QgsCoordinateReferenceSystem('EPSG:28353'), p)
self.assertEqual(transform.sourceDatumTransform(), 1) self.assertEqual(transform.sourceDatumTransform(), 1)
Expand Down
7 changes: 6 additions & 1 deletion tests/src/python/test_qgscoordinatetransformcontext.py
Expand Up @@ -20,6 +20,7 @@
QgsProject) QgsProject)
from qgis.testing import start_app, unittest from qgis.testing import start_app, unittest
from qgis.PyQt.QtXml import QDomDocument from qgis.PyQt.QtXml import QDomDocument
from qgis.PyQt.QtTest import QSignalSpy


app = start_app() app = start_app()


Expand Down Expand Up @@ -220,7 +221,11 @@ def testProject(self):
Test project's transform context Test project's transform context
""" """
project = QgsProject() project = QgsProject()
project.transformContext().addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), 1) context_changed_spy = QSignalSpy(project.transformContextChanged)
context = project.transformContext()
context.addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), 1)
project.setTransformContext(context)
self.assertEqual(len(context_changed_spy), 1)
self.assertEqual(project.transformContext().sourceDatumTransforms(), {'EPSG:3111': 1}) self.assertEqual(project.transformContext().sourceDatumTransforms(), {'EPSG:3111': 1})




Expand Down

0 comments on commit 6201390

Please sign in to comment.