Skip to content

Commit

Permalink
Avoid duplicate signals, add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 20, 2019
1 parent cb8b4a8 commit 0cd49ca
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/gui/qgscoordinateoperationwidget.cpp
Expand Up @@ -668,7 +668,17 @@ void QgsCoordinateOperationWidget::tableCurrentItemChanged( QTableWidgetItem *,
QTableWidgetItem *destItem = mCoordinateOperationTableWidget->item( row, 1 );
mLabelDstDescription->setText( destItem ? destItem->toolTip() : QString() );
}
emit operationChanged();
OperationDetails newOp = selectedOperation();
#if PROJ_VERSION_MAJOR>=6
if ( newOp.proj != mPreviousOp.proj )
emit operationChanged();
#else
if ( newOp.sourceTransformId != mPreviousOp.sourceTransformId ||
newOp.destinationTransformId != mPreviousOp.destinationTransformId ||
)
emit operationChanged();
#endif
mPreviousOp = newOp;
}

void QgsCoordinateOperationWidget::setSourceCrs( const QgsCoordinateReferenceSystem &sourceCrs )
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgscoordinateoperationwidget.h
Expand Up @@ -155,6 +155,7 @@ class GUI_EXPORT QgsCoordinateOperationWidget : public QWidget, private Ui::QgsC
#endif
QgsCoordinateReferenceSystem mSourceCrs;
QgsCoordinateReferenceSystem mDestinationCrs;
OperationDetails mPreviousOp;
};

#endif // QGSCOORDINATEOPERATIONWIDGET_H
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -37,6 +37,7 @@ ADD_PYTHON_TEST(PyQgsColorRamp test_qgscolorramp.py)
ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py)
ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.py)
ADD_PYTHON_TEST(PyQgsCoordinateFormatter test_qgscoordinateformatter.py)
ADD_PYTHON_TEST(PyQgsCoordinateOperationWidget test_qgscoordinateoperationwidget.py)
ADD_PYTHON_TEST(PyQgsConditionalFormatWidgets test_qgsconditionalformatwidgets.py)
ADD_PYTHON_TEST(PyQgsConditionalStyle test_qgsconditionalstyle.py)
ADD_PYTHON_TEST(PyQgsCoordinateTransformContext test_qgscoordinatetransformcontext.py)
Expand Down
82 changes: 82 additions & 0 deletions tests/src/python/test_qgscoordinateoperationwidget.py
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for TestQgsCoordinateOperationWidget
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Nyall Dawson'
__date__ = '19/12/2019'
__copyright__ = 'Copyright 2019, The QGIS Project'

import qgis # NOQA
import os

from qgis.core import (
QgsProjUtils,
QgsRectangle,
QgsCoordinateReferenceSystem,
QgsVectorLayer,
QgsProject,
QgsFeature,
QgsGeometry)
from qgis.gui import QgsCoordinateOperationWidget

from qgis.PyQt.QtTest import QSignalSpy
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath

start_app()
TEST_DATA_DIR = unitTestDataPath()


class TestQgsCoordinateOperationWidget(unittest.TestCase):

def testGettersSetters(self):
""" test widget getters/setters """
w = QgsCoordinateOperationWidget()
self.assertFalse(w.sourceCrs().isValid())
self.assertFalse(w.destinationCrs().isValid())

w.setSourceCrs(QgsCoordinateReferenceSystem('EPSG:28355'))
self.assertEqual(w.sourceCrs().authid(), 'EPSG:28355')
self.assertFalse(w.destinationCrs().isValid())

w.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:7855'))
self.assertEqual(w.sourceCrs().authid(), 'EPSG:28355')
self.assertEqual(w.destinationCrs().authid(), 'EPSG:7855')

@unittest.skipIf(QgsProjUtils.projVersionMajor() < 6, 'Not a proj6 build')
def testOperations(self):
w = QgsCoordinateOperationWidget()
spy = QSignalSpy(w.operationChanged)
w.setSourceCrs(QgsCoordinateReferenceSystem('EPSG:28355'))
self.assertEqual(len(spy), 0)
w.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:7855'))
self.assertEqual(len(spy), 1)

self.assertEqual(w.defaultOperation().proj, '+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(w.selectedOperation().proj,
'+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')

op = QgsCoordinateOperationWidget.OperationDetails()
op.proj = '+proj=pipeline +step +inv +proj=utm +zone=55 +south +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=utm +zone=55 +south +ellps=GRS80'
w.setSelectedOperation(op)
self.assertEqual(w.selectedOperation().proj,
'+proj=pipeline +step +inv +proj=utm +zone=55 +south +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=utm +zone=55 +south +ellps=GRS80')
self.assertEqual(len(spy), 2)
w.setSelectedOperation(op)
self.assertEqual(w.selectedOperation().proj,
'+proj=pipeline +step +inv +proj=utm +zone=55 +south +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=utm +zone=55 +south +ellps=GRS80')
self.assertEqual(len(spy), 2)

op.proj = '+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'
w.setSelectedOperation(op)
self.assertEqual(w.selectedOperation().proj,
'+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)


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

0 comments on commit 0cd49ca

Please sign in to comment.