Skip to content
Permalink
Browse files

Add explicit setter for project's transform context

And add transformContextChanged signal, so that we can detect
when the context is changed.
  • Loading branch information
nyalldawson committed Nov 6, 2017
1 parent a88dcdf commit 30604ed48c201ad2a8cff9810c3665fe1686daea
@@ -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.
@@ -924,6 +936,15 @@ emitted whenever the configuration for snapping has changed
.. seealso:: 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
@@ -479,9 +479,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()
@@ -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.
@@ -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.
@@ -114,7 +114,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)
@@ -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()

@@ -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})


0 comments on commit 30604ed

Please sign in to comment.
You can’t perform that action at this time.