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)
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)
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")
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)
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])
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")
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)
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")
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)
def test_save_restore_references(self): """ Test saving and restoring symbol layer references """ # simple ids mask_layer = QgsMaskMarkerSymbolLayer() mask_layer.setMasks([ QgsSymbolLayerReference(self.lines_layer.id(), QgsSymbolLayerId("", 0)), QgsSymbolLayerReference(self.lines_layer2.id(), QgsSymbolLayerId("some_id", [1, 3, 5, 19])), QgsSymbolLayerReference(self.polys_layer.id(), QgsSymbolLayerId("some_other_id", [4, 5])), ]) props = mask_layer.properties() mask_layer2 = QgsMaskMarkerSymbolLayer.create(props) self.assertEqual(mask_layer2.masks(), [ QgsSymbolLayerReference(self.lines_layer.id(), QgsSymbolLayerId("", 0)), QgsSymbolLayerReference(self.lines_layer2.id(), QgsSymbolLayerId("some_id", [1, 3, 5, 19])), QgsSymbolLayerReference(self.polys_layer.id(), QgsSymbolLayerId("some_other_id", [4, 5])), ]) # complex ids mask_layer = QgsMaskMarkerSymbolLayer() mask_layer.setMasks([ QgsSymbolLayerReference(self.lines_layer.id(), QgsSymbolLayerId("", 0)), QgsSymbolLayerReference( self.lines_layer2.id(), QgsSymbolLayerId("some id, #1", [1, 3, 5, 19])), QgsSymbolLayerReference( self.polys_layer.id(), QgsSymbolLayerId("some other id, like, this", [4, 5])), ]) props = mask_layer.properties() mask_layer2 = QgsMaskMarkerSymbolLayer.create(props) self.assertEqual(mask_layer2.masks(), [ QgsSymbolLayerReference(self.lines_layer.id(), QgsSymbolLayerId("", 0)), QgsSymbolLayerReference( self.lines_layer2.id(), QgsSymbolLayerId("some id, #1", [1, 3, 5, 19])), QgsSymbolLayerReference( self.polys_layer.id(), QgsSymbolLayerId("some other id, like, this", [4, 5])), ]) # complex ids, v2 mask_layer = QgsMaskMarkerSymbolLayer() mask_layer.setMasks([ QgsSymbolLayerReference(self.lines_layer.id(), QgsSymbolLayerId("a string; with bits", 0)), QgsSymbolLayerReference( self.lines_layer2.id(), QgsSymbolLayerId("some; id, #1", [1, 3, 5, 19])), QgsSymbolLayerReference( self.polys_layer.id(), QgsSymbolLayerId("some other; id, lik;e, this", [4, 5])), ]) props = mask_layer.properties() mask_layer2 = QgsMaskMarkerSymbolLayer.create(props) self.assertEqual(mask_layer2.masks(), [ QgsSymbolLayerReference(self.lines_layer.id(), QgsSymbolLayerId("a string; with bits", 0)), QgsSymbolLayerReference( self.lines_layer2.id(), QgsSymbolLayerId("some; id, #1", [1, 3, 5, 19])), QgsSymbolLayerReference( self.polys_layer.id(), QgsSymbolLayerId("some other; id, lik;e, this", [4, 5])), ])