示例#1
0
    def test_mask_symbollayer_preview(self):
        #
        # Masks should be visible in previews
        #
        p = QgsMarkerSymbol.createSimple({'color': '#fdbf6f', 'size': "7"})

        circle_symbol = QgsMarkerSymbol.createSimple({'size': '10'})
        mask_layer = QgsMaskMarkerSymbolLayer()
        mask_layer.setSubSymbol(circle_symbol)
        p.insertSymbolLayer(0, mask_layer)

        for control_name, render_function in [
            ("as_image", lambda: p.asImage(QSize(64, 64)).save(tmp)),
            ("as_big_preview", lambda: p.bigSymbolPreviewImage().save(tmp)),
            ("sl_preview", lambda: QgsSymbolLayerUtils.symbolLayerPreviewIcon(
                mask_layer, QgsUnitTypes.RenderPixels, QSize(64, 64)).pixmap(
                    QSize(64, 64)).save(tmp))
        ]:
            tmp = getTempfilePath('png')
            render_function()
            self.checker.setControlName(control_name)
            self.checker.setRenderedImage(tmp)
            res = self.checker.compareImages(control_name, 90)
            self.report += self.checker.report()
            self.assertTrue(res)
示例#2
0
    def test_layout_export_marker_masking_w_effects(self):
        """Test mask effects in a layout export with a marker symbol masking"""

        p = QgsMarkerSymbol.createSimple({'color': '#fdbf6f', 'size': "3"})
        self.points_layer.setRenderer(QgsSingleSymbolRenderer(p))

        circle_symbol = QgsMarkerSymbol.createSimple({'size': '6'})
        mask_layer = QgsMaskMarkerSymbolLayer()
        mask_layer.setSubSymbol(circle_symbol)
        mask_layer.setMasks([
            # the black part of roads
            QgsSymbolLayerReference(self.lines_layer.id(),
                                    QgsSymbolLayerId("", 0)),
        ])

        # add an outer glow effect to the mask
        blur = QgsOuterGlowEffect.create({
            "enabled": "1",
            "blur_level": "3.445",
            "blur_unit": "MM",
            "opacity": "1",
            "spread": "0.06",
            "spread_unit": "MM",
            "color1": "0,0,255,255",
            "draw_mode": "2"
        })

        # TODO try to set the mask effect on p the marker symbol -> result should be the same
        mask_layer.setPaintEffect(blur)

        # add this mask layer to the point layer
        self.points_layer.renderer().symbol().appendSymbolLayer(mask_layer)

        # 2 rasters : Image and its mask for masked lines layer
        self.check_layout_export("layout_export_marker_masking_w_effects", 2)
示例#3
0
    def test_mask_with_effect(self):
        p = QgsMarkerSymbol.createSimple({'color': '#fdbf6f', 'size': "7"})
        self.points_layer.setRenderer(QgsSingleSymbolRenderer(p))

        circle_symbol = QgsMarkerSymbol.createSimple({'size': '12'})
        mask_layer = QgsMaskMarkerSymbolLayer()
        mask_layer.setSubSymbol(circle_symbol)
        mask_layer.setMasks([
            # the yellow part of roads
            QgsSymbolLayerReference(self.lines_layer.id(),
                                    QgsSymbolLayerId("", 1)),
        ])
        # add an outer glow effect to the mask layer
        blur = QgsOuterGlowEffect.create({
            "enabled": "1",
            "blur_level": "6.445",
            "blur_unit": "MM",
            "opacity": "1",
            "spread": "0.6",
            "spread_unit": "MM",
            "color1": "0,0,255,255",
            "draw_mode": "2"
        })
        mask_layer.setPaintEffect(blur)
        # add this mask layer to the point layer
        self.points_layer.renderer().symbol().appendSymbolLayer(mask_layer)

        self.check_renderings(self.map_settings, "mask_with_effect")
示例#4
0
    def test_layout_export_2_sources_masking(self):
        """Test masking with 2 different sources"""

        # mask with points layer circles...
        p = QgsMarkerSymbol.createSimple({'color': '#fdbf6f', 'size': "3"})
        self.points_layer.setRenderer(QgsSingleSymbolRenderer(p))

        circle_symbol = QgsMarkerSymbol.createSimple({'size': '6'})
        mask_layer = QgsMaskMarkerSymbolLayer()
        mask_layer.setSubSymbol(circle_symbol)
        mask_layer.setMasks([
            # the black part of roads
            QgsSymbolLayerReference(self.lines_layer.id(),
                                    QgsSymbolLayerId("", 0)),
        ])
        self.points_layer.renderer().symbol().appendSymbolLayer(mask_layer)

        # ...and with text
        label_settings = self.polys_layer.labeling().settings()
        fmt = label_settings.format()

        fmt.font().setPointSize(4)
        fmt.mask().setEnabled(True)
        fmt.mask().setSize(1.0)
        # and mask other symbol layers underneath
        fmt.mask().setMaskedSymbolLayers([
            # the black part of roads
            QgsSymbolLayerReference(self.lines_layer.id(),
                                    QgsSymbolLayerId("", 0))
        ])

        label_settings.setFormat(fmt)
        self.polys_layer.labeling().setSettings(label_settings)

        self.check_layout_export("layout_export_2_sources_masking", 0)
示例#5
0
    def test_layout_export_w_force_raster_render(self):
        """
        Test layout export with a marker symbol masking forced to be render as raster
        We expect the lines to be masked and the whole output needs to be vector except
        the marker layer forced as raster
        """

        p = QgsMarkerSymbol.createSimple({'color': '#fdbf6f', 'size': "3"})
        self.points_layer.setRenderer(QgsSingleSymbolRenderer(p))

        circle_symbol = QgsMarkerSymbol.createSimple({'size': '6'})
        mask_layer = QgsMaskMarkerSymbolLayer()
        mask_layer.setSubSymbol(circle_symbol)
        mask_layer.setMasks([
            # the black part of roads
            QgsSymbolLayerReference(self.lines_layer.id(),
                                    QgsSymbolLayerId("", 0)),
        ])
        # add this mask layer to the point layer
        self.points_layer.renderer().symbol().appendSymbolLayer(mask_layer)
        self.points_layer.renderer().setForceRasterRender(True)

        # 2 rasters : Image and its mask for the points layer
        self.check_layout_export("layout_export_force_raster_render", 2,
                                 [self.points_layer, self.lines_layer])
示例#6
0
    def test_symbol_layer_mask(self):
        p = QgsMarkerSymbol.createSimple({'color': '#fdbf6f', 'size': "7"})
        self.points_layer.setRenderer(QgsSingleSymbolRenderer(p))

        circle_symbol = QgsMarkerSymbol.createSimple({'size': '10'})
        mask_layer = QgsMaskMarkerSymbolLayer()
        mask_layer.setSubSymbol(circle_symbol)
        mask_layer.setMasks([
            # the black part of roads
            QgsSymbolLayerReference(self.lines_layer.id(), QgsSymbolLayerId("", 0)),
        ])
        # add this mask layer to the point layer
        self.points_layer.renderer().symbol().appendSymbolLayer(mask_layer)

        self.check_renderings(self.map_settings, "sl_mask")
示例#7
0
    def test_layout_export_marker_masking(self):
        """Test mask effects in a layout export with a marker symbol masking"""

        p = QgsMarkerSymbol.createSimple({'color': '#fdbf6f', 'size': "3"})
        self.points_layer.setRenderer(QgsSingleSymbolRenderer(p))

        circle_symbol = QgsMarkerSymbol.createSimple({'size': '6'})
        mask_layer = QgsMaskMarkerSymbolLayer()
        mask_layer.setSubSymbol(circle_symbol)
        mask_layer.setMasks([
            # the black part of roads
            QgsSymbolLayerReference(self.lines_layer.id(),
                                    QgsSymbolLayerId("", 0)),
        ])
        # add this mask layer to the point layer
        self.points_layer.renderer().symbol().appendSymbolLayer(mask_layer)

        self.check_layout_export("layout_export_marker_masking", 0)
示例#8
0
    def test_multiple_masks_different_symbol_layers_same_layer2(self):
        """Test multiple masks that occlude different symbol layers of the same layer - 2nd possible order
        The UI should disallow this settings. We test here that only one mask is retained"""
        #
        # 1. a symbol layer mask
        #
        p = QgsMarkerSymbol.createSimple({'color': '#fdbf6f', 'size': "7"})
        self.points_layer.setRenderer(QgsSingleSymbolRenderer(p))

        circle_symbol = QgsMarkerSymbol.createSimple({'size': '10'})
        mask_layer = QgsMaskMarkerSymbolLayer()
        mask_layer.setSubSymbol(circle_symbol)
        mask_layer.setMasks([
            # the black part of roads
            QgsSymbolLayerReference(self.lines_layer.id(),
                                    QgsSymbolLayerId("", 0)),
        ])
        # add this mask layer to the point layer
        self.points_layer.renderer().symbol().appendSymbolLayer(mask_layer)

        #
        # 2. a label mask
        #

        # modify labeling settings
        label_settings = self.polys_layer.labeling().settings()
        fmt = label_settings.format()
        # enable a mask
        fmt.mask().setEnabled(True)
        fmt.mask().setSize(4.0)
        # and mask other symbol layers underneath
        fmt.mask().setMaskedSymbolLayers([
            # the yellow part of roads
            QgsSymbolLayerReference(self.lines_layer.id(),
                                    QgsSymbolLayerId("", 1))
        ])
        label_settings.setFormat(fmt)
        self.polys_layer.labeling().setSettings(label_settings)

        self.check_renderings(self.map_settings,
                              "multiple_masks_different_sl2")
示例#9
0
    def test_layout_export_marker_masking_w_transparency(self):
        """Test layout export with a marker symbol masking which has an opacity lower than 1"""

        p = QgsMarkerSymbol.createSimple({'color': '#fdbf6f', 'size': "3"})
        self.points_layer.setRenderer(QgsSingleSymbolRenderer(p))

        circle_symbol = QgsMarkerSymbol.createSimple({'size': '6'})
        circle_symbol.setOpacity(0.5)
        mask_layer = QgsMaskMarkerSymbolLayer()
        mask_layer.setSubSymbol(circle_symbol)
        mask_layer.setMasks([
            # the black part of roads
            QgsSymbolLayerReference(self.lines_layer.id(),
                                    QgsSymbolLayerId("", 0)),
        ])
        # add this mask layer to the point layer
        self.points_layer.renderer().symbol().appendSymbolLayer(mask_layer)

        # 2 rasters (mask + image) because opacity force rasterization of the masked line layers
        self.check_layout_export("layout_export_marker_masking_w_transparency",
                                 2)