Beispiel #1
0
    def testGettersSetters(self):
        """
        Basic getter/setter tests
        """
        c = QgsRenderContext()

        c.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysText)
        self.assertEqual(c.textRenderFormat(),
                         QgsRenderContext.TextFormatAlwaysText)
        c.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysOutlines)
        self.assertEqual(c.textRenderFormat(),
                         QgsRenderContext.TextFormatAlwaysOutlines)

        c.setMapExtent(QgsRectangle(1, 2, 3, 4))
        self.assertEqual(c.mapExtent(), QgsRectangle(1, 2, 3, 4))

        self.assertTrue(c.zRange().isInfinite())
        c.setZRange(QgsDoubleRange(1, 10))
        self.assertEqual(c.zRange(), QgsDoubleRange(1, 10))

        self.assertEqual(c.symbologyReferenceScale(), -1)
        c.setSymbologyReferenceScale(1000)
        self.assertEqual(c.symbologyReferenceScale(), 1000)

        self.assertTrue(c.outputSize().isEmpty())
        c.setOutputSize(QSize(100, 200))
        self.assertEqual(c.outputSize(), QSize(100, 200))

        self.assertEqual(c.devicePixelRatio(), 1)
        c.setDevicePixelRatio(2)
        self.assertEqual(c.devicePixelRatio(), 2)
        self.assertEqual(c.deviceOutputSize(), QSize(200, 400))

        c.setImageFormat(QImage.Format_Alpha8)
        self.assertEqual(c.imageFormat(), QImage.Format_Alpha8)

        # should have an invalid mapToPixel by default
        self.assertFalse(c.mapToPixel().isValid())

        self.assertEqual(c.frameRate(), -1)
        c.setFrameRate(30)
        self.assertEqual(c.frameRate(), 30)

        self.assertEqual(c.currentFrame(), -1)
        c.setCurrentFrame(6)
        self.assertEqual(c.currentFrame(), 6)
Beispiel #2
0
    def testCopyConstructor(self):
        """
        Test the copy constructor
        """
        c1 = QgsRenderContext()

        c1.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysText)
        c1.setMapExtent(QgsRectangle(1, 2, 3, 4))
        c1.setZRange(QgsDoubleRange(1, 10))
        c1.setSymbologyReferenceScale(1000)
        c1.setOutputSize(QSize(100, 200))
        c1.setImageFormat(QImage.Format_Alpha8)
        c1.setDevicePixelRatio(2)
        c1.setFrameRate(30)
        c1.setCurrentFrame(6)

        c2 = QgsRenderContext(c1)
        self.assertEqual(c2.textRenderFormat(),
                         QgsRenderContext.TextFormatAlwaysText)
        self.assertEqual(c2.mapExtent(), QgsRectangle(1, 2, 3, 4))
        self.assertEqual(c2.zRange(), QgsDoubleRange(1, 10))
        self.assertEqual(c2.symbologyReferenceScale(), 1000)
        self.assertEqual(c2.outputSize(), QSize(100, 200))
        self.assertEqual(c2.imageFormat(), QImage.Format_Alpha8)
        self.assertEqual(c2.devicePixelRatio(), 2)
        self.assertEqual(c2.deviceOutputSize(), QSize(200, 400))
        self.assertEqual(c2.frameRate(), 30)
        self.assertEqual(c2.currentFrame(), 6)

        c1.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysOutlines)
        c2 = QgsRenderContext(c1)
        self.assertEqual(c2.textRenderFormat(),
                         QgsRenderContext.TextFormatAlwaysOutlines)

        c1.setIsTemporal(True)
        c1.setTemporalRange(
            QgsDateTimeRange(QDateTime(2020, 1, 1, 0, 0),
                             QDateTime(2010, 12, 31, 23, 59)))
        c2 = QgsRenderContext(c1)

        self.assertEqual(c2.isTemporal(), True)
        self.assertEqual(
            c2.temporalRange(),
            QgsDateTimeRange(QDateTime(2020, 1, 1, 0, 0),
                             QDateTime(2010, 12, 31, 23, 59)))