예제 #1
0
    def testReadWrite(self):
        p = QgsProjectDisplaySettings()

        format = QgsBearingNumericFormat()
        format.setNumberDecimalPlaces(9)
        format.setDirectionFormat(QgsBearingNumericFormat.UseRange0To360)
        p.setBearingFormat(format)

        format = QgsGeographicCoordinateNumericFormat()
        format.setNumberDecimalPlaces(7)
        format.setAngleFormat(QgsGeographicCoordinateNumericFormat.AngleFormat.
                              DegreesMinutesSeconds)
        p.setGeographicCoordinateFormat(format)

        doc = QDomDocument("testdoc")
        elem = p.writeXml(doc, QgsReadWriteContext())

        p2 = QgsProjectDisplaySettings()
        spy = QSignalSpy(p2.bearingFormatChanged)
        spy2 = QSignalSpy(p2.geographicCoordinateFormatChanged)
        self.assertTrue(p2.readXml(elem, QgsReadWriteContext()))
        self.assertEqual(len(spy), 1)
        self.assertEqual(len(spy2), 1)
        self.assertEqual(p2.bearingFormat().numberDecimalPlaces(), 9)
        self.assertEqual(p2.bearingFormat().directionFormat(),
                         QgsBearingNumericFormat.UseRange0To360)
        self.assertEqual(p.geographicCoordinateFormat().numberDecimalPlaces(),
                         7)
        self.assertEqual(
            p.geographicCoordinateFormat().angleFormat(),
            QgsGeographicCoordinateNumericFormat.AngleFormat.
            DegreesMinutesSeconds)
예제 #2
0
    def testReset(self):
        """
        Test that resetting inherits local default settings
        """
        format = QgsBearingNumericFormat()
        format.setNumberDecimalPlaces(3)
        format.setDirectionFormat(
            QgsBearingNumericFormat.UseRangeNegative180ToPositive180)
        p = QgsProjectDisplaySettings()
        p.setBearingFormat(format)
        self.assertEqual(p.bearingFormat().numberDecimalPlaces(), 3)
        self.assertEqual(
            p.bearingFormat().directionFormat(),
            QgsBearingNumericFormat.UseRangeNegative180ToPositive180)

        # setup a local default bearing format
        s = QgsLocalDefaultSettings()
        format = QgsBearingNumericFormat()
        format.setNumberDecimalPlaces(9)
        format.setDirectionFormat(QgsBearingNumericFormat.UseRange0To360)
        s.setBearingFormat(format)

        spy = QSignalSpy(p.bearingFormatChanged)
        p.reset()
        self.assertEqual(len(spy), 1)
        # project should default to local default format
        self.assertEqual(p.bearingFormat().numberDecimalPlaces(), 9)
        self.assertEqual(p.bearingFormat().directionFormat(),
                         QgsBearingNumericFormat.UseRange0To360)
예제 #3
0
    def testBearingFormat(self):
        s = QgsLocalDefaultSettings()

        format = QgsBearingNumericFormat()
        format.setNumberDecimalPlaces(9)
        format.setDirectionFormat(QgsBearingNumericFormat.UseRange0To360)

        s.setBearingFormat(format)
        self.assertEqual(s.bearingFormat().numberDecimalPlaces(), 9)
        self.assertEqual(s.bearingFormat().directionFormat(),
                         QgsBearingNumericFormat.UseRange0To360)

        format = QgsBearingNumericFormat()
        format.setNumberDecimalPlaces(3)
        format.setDirectionFormat(
            QgsBearingNumericFormat.UseRangeNegative180ToPositive180)
        s.setBearingFormat(format)
        self.assertEqual(s.bearingFormat().numberDecimalPlaces(), 3)
        self.assertEqual(
            s.bearingFormat().directionFormat(),
            QgsBearingNumericFormat.UseRangeNegative180ToPositive180)

        # new settings object, should persist.
        s2 = QgsLocalDefaultSettings()
        self.assertEqual(s2.bearingFormat().numberDecimalPlaces(), 3)
        self.assertEqual(
            s2.bearingFormat().directionFormat(),
            QgsBearingNumericFormat.UseRangeNegative180ToPositive180)
예제 #4
0
    def testReset(self):
        """
        Test that resetting inherits local default settings
        """
        format = QgsBearingNumericFormat()
        format.setNumberDecimalPlaces(3)
        format.setDirectionFormat(
            QgsBearingNumericFormat.UseRangeNegative180ToPositive180)
        p = QgsProjectDisplaySettings()
        p.setBearingFormat(format)
        self.assertEqual(p.bearingFormat().numberDecimalPlaces(), 3)
        self.assertEqual(
            p.bearingFormat().directionFormat(),
            QgsBearingNumericFormat.UseRangeNegative180ToPositive180)

        format = QgsGeographicCoordinateNumericFormat()
        format.setNumberDecimalPlaces(7)
        format.setAngleFormat(QgsGeographicCoordinateNumericFormat.AngleFormat.
                              DegreesMinutesSeconds)
        p.setGeographicCoordinateFormat(format)
        self.assertEqual(p.geographicCoordinateFormat().numberDecimalPlaces(),
                         7)
        self.assertEqual(
            p.geographicCoordinateFormat().angleFormat(),
            QgsGeographicCoordinateNumericFormat.AngleFormat.
            DegreesMinutesSeconds)

        # setup a local default bearing format
        s = QgsLocalDefaultSettings()
        format = QgsBearingNumericFormat()
        format.setNumberDecimalPlaces(9)
        format.setDirectionFormat(QgsBearingNumericFormat.UseRange0To360)
        s.setBearingFormat(format)

        format = QgsGeographicCoordinateNumericFormat()
        format.setNumberDecimalPlaces(5)
        format.setAngleFormat(
            QgsGeographicCoordinateNumericFormat.AngleFormat.DegreesMinutes)
        s.setGeographicCoordinateFormat(format)

        spy = QSignalSpy(p.bearingFormatChanged)
        spy2 = QSignalSpy(p.geographicCoordinateFormatChanged)
        p.reset()
        self.assertEqual(len(spy), 1)
        self.assertEqual(len(spy2), 1)
        # project should default to local default format
        self.assertEqual(p.bearingFormat().numberDecimalPlaces(), 9)
        self.assertEqual(p.bearingFormat().directionFormat(),
                         QgsBearingNumericFormat.UseRange0To360)

        self.assertEqual(p.geographicCoordinateFormat().numberDecimalPlaces(),
                         5)
        self.assertEqual(
            p.geographicCoordinateFormat().angleFormat(),
            QgsGeographicCoordinateNumericFormat.AngleFormat.DegreesMinutes)
예제 #5
0
    def testBearingFormat(self):
        w = QgsNumericFormatSelectorWidget()

        original = QgsBearingNumericFormat()
        original.setNumberDecimalPlaces(4)
        original.setShowTrailingZeros(True)
        original.setDirectionFormat(QgsBearingNumericFormat.UseRange0To360)

        w.setFormat(original)
        new = w.format()

        self.assertIsInstance(new, QgsBearingNumericFormat)
        self.assertEqual(new.numberDecimalPlaces(),
                         original.numberDecimalPlaces())
        self.assertEqual(new.showTrailingZeros(), original.showTrailingZeros())
        self.assertEqual(new.directionFormat(), original.directionFormat())
예제 #6
0
    def testReadWrite(self):
        p = QgsProjectDisplaySettings()

        format = QgsBearingNumericFormat()
        format.setNumberDecimalPlaces(9)
        format.setDirectionFormat(QgsBearingNumericFormat.UseRange0To360)
        p.setBearingFormat(format)

        doc = QDomDocument("testdoc")
        elem = p.writeXml(doc, QgsReadWriteContext())

        p2 = QgsProjectDisplaySettings()
        spy = QSignalSpy(p2.bearingFormatChanged)
        self.assertTrue(p2.readXml(elem, QgsReadWriteContext()))
        self.assertEqual(len(spy), 1)
        self.assertEqual(p2.bearingFormat().numberDecimalPlaces(), 9)
        self.assertEqual(p2.bearingFormat().directionFormat(),
                         QgsBearingNumericFormat.UseRange0To360)
예제 #7
0
    def testBearingFormat(self):
        p = QgsProjectDisplaySettings()

        format = QgsBearingNumericFormat()
        format.setNumberDecimalPlaces(9)
        format.setDirectionFormat(QgsBearingNumericFormat.UseRange0To360)

        spy = QSignalSpy(p.bearingFormatChanged)
        p.setBearingFormat(format)
        self.assertEqual(len(spy), 1)
        self.assertEqual(p.bearingFormat().numberDecimalPlaces(), 9)
        self.assertEqual(p.bearingFormat().directionFormat(),
                         QgsBearingNumericFormat.UseRange0To360)

        format = QgsBearingNumericFormat()
        format.setNumberDecimalPlaces(3)
        format.setDirectionFormat(
            QgsBearingNumericFormat.UseRangeNegative180ToPositive180)
        p.setBearingFormat(format)
        self.assertEqual(len(spy), 2)
        self.assertEqual(p.bearingFormat().numberDecimalPlaces(), 3)
        self.assertEqual(
            p.bearingFormat().directionFormat(),
            QgsBearingNumericFormat.UseRangeNegative180ToPositive180)
예제 #8
0
    def testBearingFormat(self):
        """ test bearing formatter """
        f = QgsBearingNumericFormat()
        f.setDirectionFormat(
            QgsBearingNumericFormat.UseRange0To180WithEWDirectionalSuffix)
        context = QgsNumericFormatContext()
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(90, context), '90°E')
        self.assertEqual(f.formatDouble(180, context), '180°')
        self.assertEqual(f.formatDouble(270, context), '90°W')
        self.assertEqual(f.formatDouble(300, context), '60°W')
        self.assertEqual(f.formatDouble(5, context), '5°E')
        self.assertEqual(f.formatDouble(5.5, context), '5.5°E')
        self.assertEqual(f.formatDouble(-5, context), '5°W')
        self.assertEqual(f.formatDouble(-5.5, context), '5.5°W')
        context.setDecimalSeparator('x')
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(-5.5, context), '5x5°W')
        self.assertEqual(f.formatDouble(180, context), '180°')
        context.setDecimalSeparator('.')
        f.setNumberDecimalPlaces(0)
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(5.5, context), '6°E')
        self.assertEqual(f.formatDouble(-5.5, context), '6°W')
        self.assertEqual(f.formatDouble(180, context), '180°')
        f.setNumberDecimalPlaces(3)
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(5.5, context), '5.5°E')
        self.assertEqual(f.formatDouble(-5.5, context), '5.5°W')
        self.assertEqual(f.formatDouble(180, context), '180°')
        f.setShowTrailingZeros(True)
        self.assertEqual(f.formatDouble(0, context),
                         '0.000°E')  # todo - fix and avoid E
        self.assertEqual(f.formatDouble(5, context), '5.000°E')
        self.assertEqual(f.formatDouble(-5, context), '5.000°W')
        self.assertEqual(f.formatDouble(5.5, context), '5.500°E')
        self.assertEqual(f.formatDouble(-5.5, context), '5.500°W')
        self.assertEqual(f.formatDouble(180, context),
                         '180.000°E')  # todo fix and avoid E

        f = QgsBearingNumericFormat()
        f.setDirectionFormat(
            QgsBearingNumericFormat.UseRangeNegative180ToPositive180)
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(90, context), '90°')
        self.assertEqual(f.formatDouble(180, context), '180°')
        self.assertEqual(f.formatDouble(270, context), '-90°')
        self.assertEqual(f.formatDouble(5, context), '5°')
        self.assertEqual(f.formatDouble(5.5, context), '5.5°')
        self.assertEqual(f.formatDouble(-5, context), '-5°')
        self.assertEqual(f.formatDouble(-5.5, context), '-5.5°')
        context.setDecimalSeparator('x')
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(-5.5, context), '-5x5°')
        self.assertEqual(f.formatDouble(180, context), '180°')
        context.setDecimalSeparator('.')
        f.setNumberDecimalPlaces(0)
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(5.5, context), '6°')
        self.assertEqual(f.formatDouble(-5.5, context), '-6°')
        self.assertEqual(f.formatDouble(180, context), '180°')
        f.setNumberDecimalPlaces(3)
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(5.5, context), '5.5°')
        self.assertEqual(f.formatDouble(-5.5, context), '-5.5°')
        self.assertEqual(f.formatDouble(180, context), '180°')
        f.setShowTrailingZeros(True)
        self.assertEqual(f.formatDouble(0, context), '0.000°')
        self.assertEqual(f.formatDouble(5, context), '5.000°')
        self.assertEqual(f.formatDouble(-5, context), '-5.000°')
        self.assertEqual(f.formatDouble(5.5, context), '5.500°')
        self.assertEqual(f.formatDouble(-5.5, context), '-5.500°')
        self.assertEqual(f.formatDouble(180, context), '180.000°')

        f = QgsBearingNumericFormat()
        f.setDirectionFormat(QgsBearingNumericFormat.UseRange0To360)
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(90, context), '90°')
        self.assertEqual(f.formatDouble(180, context), '180°')
        self.assertEqual(f.formatDouble(270, context), '270°')
        self.assertEqual(f.formatDouble(5, context), '5°')
        self.assertEqual(f.formatDouble(5.5, context), '5.5°')
        self.assertEqual(f.formatDouble(-5, context), '355°')
        self.assertEqual(f.formatDouble(-5.5, context), '354.5°')
        context.setDecimalSeparator('x')
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(-5.5, context), '354x5°')
        self.assertEqual(f.formatDouble(180, context), '180°')
        context.setDecimalSeparator('.')
        f.setNumberDecimalPlaces(0)
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(5.5, context), '6°')
        self.assertEqual(f.formatDouble(-5.4, context), '355°')
        self.assertEqual(f.formatDouble(180, context), '180°')
        f.setNumberDecimalPlaces(3)
        self.assertEqual(f.formatDouble(0, context), '0°')
        self.assertEqual(f.formatDouble(5.5, context), '5.5°')
        self.assertEqual(f.formatDouble(-5.5, context), '354.5°')
        self.assertEqual(f.formatDouble(180, context), '180°')
        f.setShowTrailingZeros(True)
        self.assertEqual(f.formatDouble(0, context), '0.000°')
        self.assertEqual(f.formatDouble(5, context), '5.000°')
        self.assertEqual(f.formatDouble(-5, context), '355.000°')
        self.assertEqual(f.formatDouble(5.5, context), '5.500°')
        self.assertEqual(f.formatDouble(-5.5, context), '354.500°')
        self.assertEqual(f.formatDouble(180, context), '180.000°')

        f2 = f.clone()
        self.assertIsInstance(f2, QgsBearingNumericFormat)

        self.assertEqual(f2.showTrailingZeros(), f.showTrailingZeros())
        self.assertEqual(f2.showPlusSign(), f.showPlusSign())
        self.assertEqual(f2.numberDecimalPlaces(), f.numberDecimalPlaces())
        self.assertEqual(f2.showThousandsSeparator(),
                         f.showThousandsSeparator())
        self.assertEqual(f2.directionFormat(), f.directionFormat())

        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        f2.writeXml(elem, doc, QgsReadWriteContext())

        f3 = QgsNumericFormatRegistry().createFromXml(elem,
                                                      QgsReadWriteContext())
        self.assertIsInstance(f3, QgsBearingNumericFormat)

        self.assertEqual(f3.showTrailingZeros(), f.showTrailingZeros())
        self.assertEqual(f3.showPlusSign(), f.showPlusSign())
        self.assertEqual(f3.numberDecimalPlaces(), f.numberDecimalPlaces())
        self.assertEqual(f3.showThousandsSeparator(),
                         f.showThousandsSeparator())
        self.assertEqual(f3.directionFormat(), f.directionFormat())