mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Add explicit setter for project's transform context
And add transformContextChanged signal, so that we can detect when the context is changed.
This commit is contained in:
parent
1a73fef4a7
commit
620139054d
@ -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.
|
||||||
@ -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
|
||||||
|
@ -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()
|
||||||
|
@ -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.
|
||||||
@ -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.
|
||||||
|
@ -138,7 +138,9 @@ class TestQgsCoordinateTransform(unittest.TestCase):
|
|||||||
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)
|
||||||
|
@ -20,6 +20,7 @@ from qgis.core import (QgsCoordinateReferenceSystem,
|
|||||||
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()
|
||||||
|
|
||||||
@ -220,7 +221,11 @@ class TestQgsCoordinateTransformContext(unittest.TestCase):
|
|||||||
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})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user