def testQgsGraduatedSymbolRenderer_1(self):
        """Test QgsGraduatedSymbolRenderer: Basic get/set functions """

        # Create a renderer
        renderer = QgsGraduatedSymbolRenderer()

        symbol = createMarkerSymbol()
        renderer.setSourceSymbol(symbol.clone())
        self.assertEqual(symbol.dump(),
                         renderer.sourceSymbol().dump(),
                         "Get/set renderer source symbol")

        attr = '"value"*"value"'
        renderer.setClassAttribute(attr)
        self.assertEqual(attr, renderer.classAttribute(),
                         "Get/set renderer class attribute")

        for m in (
                QgsGraduatedSymbolRenderer.Custom,
                QgsGraduatedSymbolRenderer.EqualInterval,
                QgsGraduatedSymbolRenderer.Quantile,
                QgsGraduatedSymbolRenderer.Jenks,
                QgsGraduatedSymbolRenderer.Pretty,
                QgsGraduatedSymbolRenderer.StdDev,
        ):
            renderer.setMode(m)
            self.assertEqual(m, renderer.mode(), "Get/set renderer mode")

        format = createLabelFormat()
        renderer.setLabelFormat(format)
        self.assertEqual(dumpLabelFormat(format),
                         dumpLabelFormat(renderer.labelFormat()),
                         "Get/set renderer label format")

        ramp = createColorRamp()
        renderer.setSourceColorRamp(ramp)
        self.assertEqual(dumpColorRamp(ramp),
                         dumpColorRamp(renderer.sourceColorRamp()),
                         "Get/set renderer color ramp")

        renderer.setSourceColorRamp(ramp)
        self.assertEqual(dumpColorRamp(ramp),
                         dumpColorRamp(renderer.sourceColorRamp()),
                         "Get/set renderer color ramp")

        # test for classificatio with varying size
        renderer.setGraduatedMethod(QgsGraduatedSymbolRenderer.GraduatedSize)
        renderer.setSourceColorRamp(None)
        renderer.addClassLowerUpper(0, 2)
        renderer.addClassLowerUpper(2, 4)
        renderer.addClassLowerUpper(4, 6)
        renderer.setSymbolSizes(2, 13)
        self.assertEqual(renderer.maxSymbolSize(), 13)
        self.assertEqual(renderer.minSymbolSize(), 2)
        refSizes = [2, (13 + 2) * .5, 13]
        ctx = QgsRenderContext()
        for idx, symbol in enumerate(renderer.symbols(ctx)):
            self.assertEqual(symbol.size(), refSizes[idx])
    def testQgsGraduatedSymbolRenderer_1(self):
        """Test QgsGraduatedSymbolRenderer: Basic get/set functions """

        # Create a renderer
        renderer = QgsGraduatedSymbolRenderer()

        symbol = createMarkerSymbol()
        renderer.setSourceSymbol(symbol.clone())
        self.assertEqual(symbol.dump(), renderer.sourceSymbol().dump(), "Get/set renderer source symbol")

        attr = '"value"*"value"'
        renderer.setClassAttribute(attr)
        self.assertEqual(attr, renderer.classAttribute(), "Get/set renderer class attribute")

        for m in (
            QgsGraduatedSymbolRenderer.Custom,
            QgsGraduatedSymbolRenderer.EqualInterval,
            QgsGraduatedSymbolRenderer.Quantile,
            QgsGraduatedSymbolRenderer.Jenks,
            QgsGraduatedSymbolRenderer.Pretty,
            QgsGraduatedSymbolRenderer.StdDev,
        ):
            renderer.setMode(m)
            self.assertEqual(m, renderer.mode(), "Get/set renderer mode")

        format = createLabelFormat()
        renderer.setLabelFormat(format)
        self.assertEqual(
            dumpLabelFormat(format),
            dumpLabelFormat(renderer.labelFormat()),
            "Get/set renderer label format")

        ramp = createColorRamp()
        renderer.setSourceColorRamp(ramp)
        self.assertEqual(
            dumpColorRamp(ramp),
            dumpColorRamp(renderer.sourceColorRamp()),
            "Get/set renderer color ramp")

        renderer.setSourceColorRamp(ramp)
        self.assertEqual(
            dumpColorRamp(ramp),
            dumpColorRamp(renderer.sourceColorRamp()),
            "Get/set renderer color ramp")

        # test for classificatio with varying size
        renderer.setGraduatedMethod(QgsGraduatedSymbolRenderer.GraduatedSize)
        renderer.setSourceColorRamp(None)
        renderer.addClassLowerUpper(0, 2)
        renderer.addClassLowerUpper(2, 4)
        renderer.addClassLowerUpper(4, 6)
        renderer.setSymbolSizes(2, 13)
        self.assertEqual(renderer.maxSymbolSize(), 13)
        self.assertEqual(renderer.minSymbolSize(), 2)
        refSizes = [2, (13 + 2) * .5, 13]
        ctx = QgsRenderContext()
        for idx, symbol in enumerate(renderer.symbols(ctx)):
            self.assertEqual(symbol.size(), refSizes[idx])
Exemple #3
0
    def testQgsGraduatedSymbolRenderer_1(self):
        """Test QgsGraduatedSymbolRenderer: Basic get/set functions """

        # Create a renderer
        renderer = QgsGraduatedSymbolRenderer()

        symbol = createMarkerSymbol()
        renderer.setSourceSymbol(symbol.clone())
        self.assertEqual(symbol.dump(),
                         renderer.sourceSymbol().dump(),
                         "Get/set renderer source symbol")

        attr = '"value"*"value"'
        renderer.setClassAttribute(attr)
        self.assertEqual(attr, renderer.classAttribute(),
                         "Get/set renderer class attribute")

        for m in (
                QgsGraduatedSymbolRenderer.Custom,
                QgsGraduatedSymbolRenderer.EqualInterval,
                QgsGraduatedSymbolRenderer.Quantile,
                QgsGraduatedSymbolRenderer.Jenks,
                QgsGraduatedSymbolRenderer.Pretty,
                QgsGraduatedSymbolRenderer.StdDev,
        ):
            renderer.setMode(m)
            self.assertEqual(m, renderer.mode(), "Get/set renderer mode")

        format = createLabelFormat()
        renderer.setLabelFormat(format)
        self.assertEqual(dumpLabelFormat(format),
                         dumpLabelFormat(renderer.labelFormat()),
                         "Get/set renderer label format")

        ramp = createColorRamp()
        renderer.setSourceColorRamp(ramp)
        self.assertEqual(dumpColorRamp(ramp),
                         dumpColorRamp(renderer.sourceColorRamp()),
                         "Get/set renderer color ramp")

        renderer.setInvertedColorRamp(True)
        self.assertTrue(renderer.invertedColorRamp(),
                        "Get/set renderer inverted color ramp")
        renderer.setInvertedColorRamp(False)
        self.assertFalse(renderer.invertedColorRamp(),
                         "Get/set renderer inverted color ramp")

        value = '"value"*2'
        exp = QgsSymbolLayerUtils.fieldOrExpressionToExpression(value)
        valuestr = QgsSymbolLayerUtils.fieldOrExpressionFromExpression(exp)
        renderer.setRotationField(value)
        self.assertEqual(valuestr, renderer.rotationField(),
                         "Get/set renderer rotation field")

        value = '"value"*3'
        exp = QgsSymbolLayerUtils.fieldOrExpressionToExpression(value)
        valuestr = QgsSymbolLayerUtils.fieldOrExpressionFromExpression(exp)
        renderer.setSizeScaleField(value)
        self.assertEqual(valuestr, renderer.sizeScaleField(),
                         "Get/set renderer size scale field")

        renderer.setSourceColorRamp(ramp)
        self.assertEqual(dumpColorRamp(ramp),
                         dumpColorRamp(renderer.sourceColorRamp()),
                         "Get/set renderer color ramp")

        for sm in (
                QgsSymbol.ScaleArea,
                QgsSymbol.ScaleDiameter,
        ):
            renderer.setScaleMethod(sm)
            self.assertEqual(str(sm), str(renderer.scaleMethod()),
                             "Get/set renderer scale method")
        # test for classificatio with varying size
        renderer.setGraduatedMethod(QgsGraduatedSymbolRenderer.GraduatedSize)
        renderer.setSourceColorRamp(None)
        renderer.addClassLowerUpper(0, 2)
        renderer.addClassLowerUpper(2, 4)
        renderer.addClassLowerUpper(4, 6)
        renderer.setSymbolSizes(2, 13)
        self.assertEqual(renderer.maxSymbolSize(), 13)
        self.assertEqual(renderer.minSymbolSize(), 2)
        refSizes = [2, (13 + 2) * .5, 13]
        ctx = QgsRenderContext()
        for idx, symbol in enumerate(renderer.symbols2(ctx)):
            self.assertEqual(symbol.size(), refSizes[idx])
    def testQgsGraduatedSymbolRenderer_1(self):
        """Test QgsGraduatedSymbolRenderer: Basic get/set functions """

        # Create a renderer
        renderer = QgsGraduatedSymbolRenderer()

        symbol = createMarkerSymbol()
        renderer.setSourceSymbol(symbol.clone())
        self.assertEqual(symbol.dump(), renderer.sourceSymbol().dump(), "Get/set renderer source symbol")

        attr = '"value"*"value"'
        renderer.setClassAttribute(attr)
        self.assertEqual(attr, renderer.classAttribute(), "Get/set renderer class attribute")

        for m in (
            QgsGraduatedSymbolRenderer.Custom,
            QgsGraduatedSymbolRenderer.EqualInterval,
            QgsGraduatedSymbolRenderer.Quantile,
            QgsGraduatedSymbolRenderer.Jenks,
            QgsGraduatedSymbolRenderer.Pretty,
            QgsGraduatedSymbolRenderer.StdDev,
        ):
            renderer.setMode(m)
            self.assertEqual(m, renderer.mode(), "Get/set renderer mode")

        format = createLabelFormat()
        renderer.setLabelFormat(format)
        self.assertEqual(
            dumpLabelFormat(format),
            dumpLabelFormat(renderer.labelFormat()),
            "Get/set renderer label format")

        ramp = createColorRamp()
        renderer.setSourceColorRamp(ramp)
        self.assertEqual(
            dumpColorRamp(ramp),
            dumpColorRamp(renderer.sourceColorRamp()),
            "Get/set renderer color ramp")

        renderer.setInvertedColorRamp(True)
        self.assertTrue(renderer.invertedColorRamp(),
                        "Get/set renderer inverted color ramp")
        renderer.setInvertedColorRamp(False)
        self.assertFalse(renderer.invertedColorRamp(),
                         "Get/set renderer inverted color ramp")

        value = '"value"*2'
        exp = QgsSymbolLayerUtils.fieldOrExpressionToExpression(value)
        valuestr = QgsSymbolLayerUtils.fieldOrExpressionFromExpression(exp)
        renderer.setRotationField(value)
        self.assertEqual(valuestr, renderer.rotationField(),
                         "Get/set renderer rotation field")

        value = '"value"*3'
        exp = QgsSymbolLayerUtils.fieldOrExpressionToExpression(value)
        valuestr = QgsSymbolLayerUtils.fieldOrExpressionFromExpression(exp)
        renderer.setSizeScaleField(value)
        self.assertEqual(valuestr, renderer.sizeScaleField(),
                         "Get/set renderer size scale field")

        renderer.setSourceColorRamp(ramp)
        self.assertEqual(
            dumpColorRamp(ramp),
            dumpColorRamp(renderer.sourceColorRamp()),
            "Get/set renderer color ramp")

        for sm in (
            QgsSymbol.ScaleArea,
            QgsSymbol.ScaleDiameter,
        ):
            renderer.setScaleMethod(sm)
            self.assertEqual(str(sm), str(renderer.scaleMethod()),
                             "Get/set renderer scale method")
        # test for classificatio with varying size
        renderer.setGraduatedMethod(QgsGraduatedSymbolRenderer.GraduatedSize)
        renderer.setSourceColorRamp(None)
        renderer.addClassLowerUpper(0, 2)
        renderer.addClassLowerUpper(2, 4)
        renderer.addClassLowerUpper(4, 6)
        renderer.setSymbolSizes(2, 13)
        self.assertEqual(renderer.maxSymbolSize(), 13)
        self.assertEqual(renderer.minSymbolSize(), 2)
        refSizes = [2, (13 + 2) * .5, 13]
        ctx = QgsRenderContext()
        for idx, symbol in enumerate(renderer.symbols2(ctx)):
            self.assertEqual(symbol.size(), refSizes[idx])