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



QgsCoordinateTransformContext &transformContext();
QgsCoordinateTransformContext transformContext() const;
%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
from a source to destination coordinate reference system.

.. versionadded:: 3.0
.. seealso:: setTransformContext()
.. seealso:: transformContextChanged()
:rtype: QgsCoordinateTransformContext
%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();
%Docstring
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()`
%End


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

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

void transactionGroupsChanged();
%Docstring
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;
}

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

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.
*
* \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
* from a source to destination coordinate reference system.
*
* \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.
Expand Down Expand Up @@ -920,6 +924,15 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
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
* 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
"""
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)
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)
from qgis.testing import start_app, unittest
from qgis.PyQt.QtXml import QDomDocument
from qgis.PyQt.QtTest import QSignalSpy

app = start_app()

Expand Down Expand Up @@ -220,7 +221,11 @@ def testProject(self):
Test project's transform context
"""
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})


Expand Down

0 comments on commit 6201390

Please sign in to comment.