-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow showing 'not set' in QgsProjectionSelectionWidget
- Loading branch information
1 parent
08231b8
commit fbc12a8
Showing
5 changed files
with
254 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for QgsProjectionSelectionWidget. | ||
.. 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__ = '12/11/2016' | ||
__copyright__ = 'Copyright 2016, The QGIS Project' | ||
# This will get replaced with a git SHA1 when you do a git archive | ||
__revision__ = '$Format:%H$' | ||
|
||
import qgis # NOQA | ||
|
||
from qgis.gui import QgsProjectionSelectionWidget | ||
from qgis.core import QgsCoordinateReferenceSystem, QgsProject | ||
from qgis.testing import start_app, unittest | ||
from qgis.PyQt.QtGui import QColor | ||
start_app() | ||
|
||
|
||
class TestQgsProjectionSelectionWidget(unittest.TestCase): | ||
|
||
def testShowingHiding(self): | ||
""" test showing and hiding options """ | ||
w = QgsProjectionSelectionWidget() | ||
|
||
# layer crs | ||
w.setOptionVisible(QgsProjectionSelectionWidget.LayerCrs, False) | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.LayerCrs)) | ||
w.setOptionVisible(QgsProjectionSelectionWidget.LayerCrs, True) | ||
# should still be hidden, because layer crs not set | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.LayerCrs)) | ||
w.setLayerCrs(QgsCoordinateReferenceSystem('EPSG:3111')) | ||
self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.LayerCrs)) | ||
w.setOptionVisible(QgsProjectionSelectionWidget.LayerCrs, False) | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.LayerCrs)) | ||
|
||
# project crs | ||
w.setOptionVisible(QgsProjectionSelectionWidget.ProjectCrs, False) | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.ProjectCrs)) | ||
w.setOptionVisible(QgsProjectionSelectionWidget.ProjectCrs, True) | ||
# should still be hidden, because project crs was not set | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.ProjectCrs)) | ||
QgsProject.instance().setCrs(QgsCoordinateReferenceSystem('EPSG:3113')) | ||
w = QgsProjectionSelectionWidget() | ||
w.setOptionVisible(QgsProjectionSelectionWidget.ProjectCrs, True) | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.ProjectCrs)) | ||
# should still be hidden, because otf reprojection not active | ||
QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectionsEnabled", 1) | ||
w = QgsProjectionSelectionWidget() | ||
w.setOptionVisible(QgsProjectionSelectionWidget.ProjectCrs, True) | ||
self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.ProjectCrs)) | ||
w.setOptionVisible(QgsProjectionSelectionWidget.ProjectCrs, False) | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.ProjectCrs)) | ||
|
||
# default crs | ||
w.setOptionVisible(QgsProjectionSelectionWidget.DefaultCrs, False) | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.DefaultCrs)) | ||
w.setOptionVisible(QgsProjectionSelectionWidget.DefaultCrs, True) | ||
self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.DefaultCrs)) | ||
|
||
# current crs | ||
w = QgsProjectionSelectionWidget() | ||
w.setOptionVisible(QgsProjectionSelectionWidget.CurrentCrs, False) | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.CurrentCrs)) | ||
w.setOptionVisible(QgsProjectionSelectionWidget.CurrentCrs, True) | ||
self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.CurrentCrs)) | ||
|
||
w = QgsProjectionSelectionWidget() | ||
w.setCrs(QgsCoordinateReferenceSystem('EPSG:3111')) | ||
w.setOptionVisible(QgsProjectionSelectionWidget.CurrentCrs, False) | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.CurrentCrs)) | ||
w.setOptionVisible(QgsProjectionSelectionWidget.CurrentCrs, True) | ||
self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.CurrentCrs)) | ||
|
||
# not set | ||
w = QgsProjectionSelectionWidget() | ||
w.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, False) | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.CrsNotSet)) | ||
w.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True) | ||
self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.CrsNotSet)) | ||
w.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, False) | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.CrsNotSet)) | ||
|
||
def testShowingNotSetOption(self): | ||
""" test showing the not set option """ | ||
|
||
w = QgsProjectionSelectionWidget() | ||
# start with an invalid CRS | ||
w.setCrs(QgsCoordinateReferenceSystem()) | ||
# add the not-set option | ||
w.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True) | ||
self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.CrsNotSet)) | ||
# current crs (which would show "invalid") should be hidden | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.CurrentCrs)) | ||
# hide not-set option | ||
w.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, False) | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.CrsNotSet)) | ||
# and now current crs option ('invalid') should be reshown | ||
self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.CurrentCrs)) | ||
|
||
# repeat with a slightly different workflow | ||
w = QgsProjectionSelectionWidget() | ||
# start with an invalid CRS | ||
w.setCrs(QgsCoordinateReferenceSystem()) | ||
# add the not-set option | ||
w.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True) | ||
self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.CrsNotSet)) | ||
# current crs (which would show "invalid") should be hidden | ||
self.assertFalse(w.optionVisible(QgsProjectionSelectionWidget.CurrentCrs)) | ||
# now set a current crs | ||
w.setCrs(QgsCoordinateReferenceSystem('EPSG:3111')) | ||
# both current and not set options should be shown | ||
self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.CurrentCrs)) | ||
self.assertTrue(w.optionVisible(QgsProjectionSelectionWidget.CrsNotSet)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |