|
18 | 18 | QgsCoordinateTransformContext,
|
19 | 19 | QgsCoordinateTransform,
|
20 | 20 | QgsReadWriteContext,
|
21 |
| - QgsProject) |
| 21 | + QgsProject, |
| 22 | + QgsSettings) |
22 | 23 | from qgis.testing import start_app, unittest
|
23 | 24 | from qgis.PyQt.QtXml import QDomDocument
|
24 | 25 | from qgis.PyQt.QtTest import QSignalSpy
|
| 26 | +from qgis.PyQt.QtCore import QCoreApplication |
25 | 27 |
|
26 | 28 | app = start_app()
|
27 | 29 |
|
28 | 30 |
|
29 | 31 | class TestQgsCoordinateTransformContext(unittest.TestCase):
|
30 | 32 |
|
| 33 | + @classmethod |
| 34 | + def setUpClass(cls): |
| 35 | + """Run before all tests""" |
| 36 | + QCoreApplication.setOrganizationName("QGIS_Test") |
| 37 | + QCoreApplication.setOrganizationDomain("TestPyQgsWFSProvider.com") |
| 38 | + QCoreApplication.setApplicationName("TestPyQgsWFSProvider") |
| 39 | + QgsSettings().clear() |
| 40 | + |
31 | 41 | @unittest.skip('ifdefed out in c++ until required')
|
32 | 42 | def testSourceDatumTransforms(self):
|
33 | 43 | context = QgsCoordinateTransformContext()
|
@@ -249,6 +259,10 @@ def testCalculateSourceDest(self):
|
249 | 259 | self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:28356'),
|
250 | 260 | QgsCoordinateReferenceSystem('EPSG:3111')),
|
251 | 261 | QgsCoordinateTransform.TransformPair(-1, -1))
|
| 262 | + # check that reverse transforms are automatically supported |
| 263 | + self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:4283'), |
| 264 | + QgsCoordinateReferenceSystem('EPSG:28356')), |
| 265 | + QgsCoordinateTransform.TransformPair(4, 3)) |
252 | 266 |
|
253 | 267 | @unittest.skip('ifdefed out in c++ until required')
|
254 | 268 | def testWriteReadXmlSingleVariant(self):
|
@@ -320,6 +334,34 @@ def testProject(self):
|
320 | 334 | self.assertEqual(len(context_changed_spy), 1)
|
321 | 335 | self.assertEqual(project.transformContext().sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): QgsCoordinateTransform.TransformPair(1, 2)})
|
322 | 336 |
|
| 337 | + def testReadWriteSettings(self): |
| 338 | + context = QgsCoordinateTransformContext() |
| 339 | + context.readSettings() |
| 340 | + # should be empty |
| 341 | + self.assertEqual(context.sourceDestinationDatumTransforms(), {}) |
| 342 | + |
| 343 | + self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), |
| 344 | + QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2)) |
| 345 | + self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'), |
| 346 | + QgsCoordinateReferenceSystem(4283), 3, 4)) |
| 347 | + |
| 348 | + self.assertEqual(context.sourceDestinationDatumTransforms(), |
| 349 | + {('EPSG:3111', 'EPSG:4283'): QgsCoordinateTransform.TransformPair(1, 2), |
| 350 | + ('EPSG:28356', 'EPSG:4283'): QgsCoordinateTransform.TransformPair(3, 4)}) |
| 351 | + |
| 352 | + # save to settings |
| 353 | + context.writeSettings() |
| 354 | + |
| 355 | + # restore from settings |
| 356 | + context2 = QgsCoordinateTransformContext() |
| 357 | + self.assertEqual(context2.sourceDestinationDatumTransforms(), {}) |
| 358 | + context2.readSettings() |
| 359 | + |
| 360 | + # check result |
| 361 | + self.assertEqual(context2.sourceDestinationDatumTransforms(), |
| 362 | + {('EPSG:3111', 'EPSG:4283'): QgsCoordinateTransform.TransformPair(1, 2), |
| 363 | + ('EPSG:28356', 'EPSG:4283'): QgsCoordinateTransform.TransformPair(3, 4)}) |
| 364 | + |
323 | 365 |
|
324 | 366 | if __name__ == '__main__':
|
325 | 367 | unittest.main()
|
0 commit comments