def testDefaultRotation(self):
        p = QgsProjectViewSettings()
        self.assertEqual(p.defaultRotation(), 0)

        p.setDefaultRotation(37)
        self.assertEqual(p.defaultRotation(), 37)

        p.reset()
        self.assertEqual(p.defaultRotation(), 0)
Exemple #2
0
    def testDefaultViewExtent(self):
        p = QgsProjectViewSettings()
        self.assertTrue(p.defaultViewExtent().isNull())

        p.setDefaultViewExtent(
            QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4),
                                   QgsCoordinateReferenceSystem("EPSG:3857")))
        self.assertEqual(
            p.defaultViewExtent(),
            QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4),
                                   QgsCoordinateReferenceSystem("EPSG:3857")))

        p.setDefaultViewExtent(QgsReferencedRectangle())
        self.assertTrue(p.defaultViewExtent().isNull())

        p.setDefaultViewExtent(
            QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4),
                                   QgsCoordinateReferenceSystem("EPSG:3857")))
        p.reset()
        self.assertTrue(p.defaultViewExtent().isNull())
Exemple #3
0
    def testMapScales(self):
        p = QgsProjectViewSettings()
        self.assertFalse(p.mapScales())
        self.assertFalse(p.useProjectScales())

        spy = QSignalSpy(p.mapScalesChanged)
        p.setMapScales([])
        self.assertEqual(len(spy), 0)
        p.setUseProjectScales(False)
        self.assertEqual(len(spy), 0)

        p.setMapScales([5000, 6000, 3000, 4000])
        # scales must be sorted
        self.assertEqual(p.mapScales(), [6000.0, 5000.0, 4000.0, 3000.0])
        self.assertEqual(len(spy), 1)
        p.setMapScales([5000, 6000, 3000, 4000])
        self.assertEqual(len(spy), 1)
        self.assertEqual(p.mapScales(), [6000.0, 5000.0, 4000.0, 3000.0])
        p.setMapScales([5000, 6000, 3000, 4000, 1000])
        self.assertEqual(len(spy), 2)
        self.assertEqual(p.mapScales(),
                         [6000.0, 5000.0, 4000.0, 3000.0, 1000.0])

        p.setUseProjectScales(True)
        self.assertEqual(len(spy), 3)
        p.setUseProjectScales(True)
        self.assertEqual(len(spy), 3)
        p.setUseProjectScales(False)
        self.assertEqual(len(spy), 4)

        p.setUseProjectScales(True)
        p.setMapScales([5000, 6000, 3000, 4000])
        self.assertEqual(len(spy), 6)

        p.reset()
        self.assertEqual(len(spy), 7)
        self.assertFalse(p.mapScales())
        self.assertFalse(p.useProjectScales())
Exemple #4
0
    def testReadWrite(self):
        p = QgsProjectViewSettings()
        self.assertFalse(p.mapScales())
        self.assertFalse(p.useProjectScales())
        doc = QDomDocument("testdoc")
        elem = p.writeXml(doc, QgsReadWriteContext())

        p2 = QgsProjectViewSettings()
        spy = QSignalSpy(p2.mapScalesChanged)
        self.assertTrue(p2.readXml(elem, QgsReadWriteContext()))
        self.assertFalse(p2.mapScales())
        self.assertFalse(p2.useProjectScales())
        self.assertEqual(len(spy), 0)
        self.assertTrue(p2.defaultViewExtent().isNull())

        p.setUseProjectScales(True)
        p.setMapScales([56, 78, 99])
        p.setDefaultViewExtent(
            QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4),
                                   QgsCoordinateReferenceSystem("EPSG:3857")))
        p.setPresetFullExtent(
            QgsReferencedRectangle(QgsRectangle(11, 12, 13, 14),
                                   QgsCoordinateReferenceSystem("EPSG:3111")))
        elem = p.writeXml(doc, QgsReadWriteContext())

        p2 = QgsProjectViewSettings()
        spy = QSignalSpy(p2.mapScalesChanged)
        self.assertTrue(p2.readXml(elem, QgsReadWriteContext()))
        self.assertEqual(p2.mapScales(), [99.0, 78.0, 56.0])
        self.assertTrue(p2.useProjectScales())
        self.assertEqual(len(spy), 1)
        self.assertEqual(
            p2.defaultViewExtent(),
            QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4),
                                   QgsCoordinateReferenceSystem("EPSG:3857")))
        self.assertEqual(
            p2.presetFullExtent(),
            QgsReferencedRectangle(QgsRectangle(11, 12, 13, 14),
                                   QgsCoordinateReferenceSystem("EPSG:3111")))
Exemple #5
0
    def testPresetFullExtentChangedSignal(self):
        p = QgsProjectViewSettings()
        spy = QSignalSpy(p.presetFullExtentChanged)

        p.setPresetFullExtent(
            QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4),
                                   QgsCoordinateReferenceSystem("EPSG:3857")))
        self.assertEqual(len(spy), 1)

        p.setPresetFullExtent(
            QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4),
                                   QgsCoordinateReferenceSystem("EPSG:3857")))
        self.assertEqual(len(spy), 1)

        p.setPresetFullExtent(
            QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4),
                                   QgsCoordinateReferenceSystem("EPSG:4326")))
        self.assertEqual(len(spy), 2)

        p.reset()
        self.assertEqual(len(spy), 3)

        p.reset()
        self.assertEqual(len(spy), 3)