Skip to content
Permalink
Browse files

Add test for proj < 6 logic

  • Loading branch information
nyalldawson committed Dec 19, 2019
1 parent f804a0a commit dbc175f131145dd09f3cca21ea6007a7c7d60f58
Showing with 66 additions and 7 deletions.
  1. +14 −6 src/gui/qgscoordinateoperationwidget.cpp
  2. +52 −1 tests/src/python/test_qgscoordinateoperationwidget.py
@@ -579,13 +579,21 @@ void QgsCoordinateOperationWidget::setSelectedOperation( const QgsCoordinateOper
}
#else
QTableWidgetItem *destItem = mCoordinateOperationTableWidget->item( row, 1 );
if ( !srcItem || !destItem )
continue;

if ( ( operation.sourceTransformId == srcItem->data( TransformIdRole ).toInt() &&
operation.destinationTransformId == destItem->data( TransformIdRole ).toInt() ) ||
( operation.destinationTransformId == srcItem->data( TransformIdRole ).toInt() &&
operation.sourceTransformId == destItem->data( TransformIdRole ).toInt() ) )
// eww, gross logic. Ah well, it's of extremely limited lifespan anyway... it'll be ripped out as soon as we can drop proj < 6 support
if ( ( srcItem && destItem && operation.sourceTransformId == srcItem->data( TransformIdRole ).toInt() &&
operation.destinationTransformId == destItem->data( TransformIdRole ).toInt() )
|| ( srcItem && destItem && operation.destinationTransformId == srcItem->data( TransformIdRole ).toInt() &&
operation.sourceTransformId == destItem->data( TransformIdRole ).toInt() )
|| ( srcItem && !destItem && operation.sourceTransformId == srcItem->data( TransformIdRole ).toInt() &&
operation.destinationTransformId == -1 )
|| ( !srcItem && destItem && operation.destinationTransformId == destItem->data( TransformIdRole ).toInt() &&
operation.sourceTransformId == -1 )
|| ( srcItem && !destItem && operation.destinationTransformId == srcItem->data( TransformIdRole ).toInt() &&
operation.sourceTransformId == -1 )
|| ( !srcItem && destItem && operation.sourceTransformId == destItem->data( TransformIdRole ).toInt() &&
operation.destinationTransformId == -1 )
)
{
mCoordinateOperationTableWidget->selectRow( row );
break;
@@ -15,7 +15,7 @@

from qgis.core import (
QgsProjUtils,
QgsRectangle,
QgsDatumTransform,
QgsCoordinateReferenceSystem,
QgsVectorLayer,
QgsProject,
@@ -83,6 +83,57 @@ def testOperations(self):
'+proj=pipeline +step +inv +proj=utm +zone=55 +south +ellps=GRS80 +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=utm +zone=55 +south +ellps=GRS80')
self.assertEqual(len(spy), 3)

@unittest.skipIf(QgsProjUtils.projVersionMajor() >= 6, 'Not a crufty proj build')
def testOperationsCruftyProj(self):
w = QgsCoordinateOperationWidget()
self.assertFalse(w.hasSelection())
spy = QSignalSpy(w.operationChanged)
w.setSourceCrs(QgsCoordinateReferenceSystem('EPSG:4283'))
self.assertEqual(len(spy), 0)
w.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:7844'))
self.assertEqual(len(spy), 1)
self.assertTrue(w.hasSelection())
self.assertEqual(len(w.availableOperations()), 2)

self.assertEqual(QgsDatumTransform.datumTransformToProj(w.defaultOperation().sourceTransformId), '+nadgrids=GDA94_GDA2020_conformal_and_distortion.gsb')
self.assertEqual(w.defaultOperation().destinationTransformId, -1)
self.assertEqual(QgsDatumTransform.datumTransformToProj(w.selectedOperation().sourceTransformId), '+nadgrids=GDA94_GDA2020_conformal_and_distortion.gsb')
self.assertEqual(w.selectedOperation().destinationTransformId, -1)

self.assertEqual(QgsDatumTransform.datumTransformToProj(w.availableOperations()[1].sourceTransformId),
'+nadgrids=GDA94_GDA2020_conformal.gsb')
self.assertEqual(w.availableOperations()[1].destinationTransformId, -1)

op = QgsCoordinateOperationWidget.OperationDetails()
op.sourceTransformId = w.availableOperations()[1].sourceTransformId
w.setSelectedOperation(op)
self.assertEqual(QgsDatumTransform.datumTransformToProj(w.selectedOperation().sourceTransformId), '+nadgrids=GDA94_GDA2020_conformal.gsb')
self.assertEqual(len(spy), 2)
w.setSelectedOperation(op)
self.assertEqual(QgsDatumTransform.datumTransformToProj(w.selectedOperation().sourceTransformId), '+nadgrids=GDA94_GDA2020_conformal.gsb')
self.assertEqual(len(spy), 2)

op.sourceTransformId = w.availableOperations()[0].sourceTransformId
op.destinationTransformId = -1
w.setSelectedOperation(op)
self.assertEqual(QgsDatumTransform.datumTransformToProj(w.selectedOperation().sourceTransformId),
'+nadgrids=GDA94_GDA2020_conformal_and_distortion.gsb')
self.assertEqual(len(spy), 3)

op.destinationTransformId = w.availableOperations()[1].sourceTransformId
op.sourceTransformId = -1
w.setSelectedOperation(op)
self.assertEqual(QgsDatumTransform.datumTransformToProj(w.selectedOperation().sourceTransformId),
'+nadgrids=GDA94_GDA2020_conformal.gsb')
self.assertEqual(len(spy), 4)

op.destinationTransformId = w.availableOperations()[0].sourceTransformId
op.sourceTransformId = -1
w.setSelectedOperation(op)
self.assertEqual(QgsDatumTransform.datumTransformToProj(w.selectedOperation().sourceTransformId),
'+nadgrids=GDA94_GDA2020_conformal_and_distortion.gsb')
self.assertEqual(len(spy), 5)


if __name__ == '__main__':
unittest.main()

0 comments on commit dbc175f

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