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))
    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))
示例#3
0
    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.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 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.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))