def append_SimpleFillSymbolLayer(symbol, layer): """ Appends a SimpleFillSymbolLayer to a symbol """ fill_color = symbol_color_to_qcolor(layer.color) out = QgsSimpleFillSymbolLayer(fill_color) out.setEnabled(layer.enabled) out.setLocked(layer.locked) if layer.outline_layer: if isinstance(layer.outline_layer, (SimpleLineSymbolLayer, CartographicLineSymbolLayer)): out.setStrokeColor( symbol_color_to_qcolor(layer.outline_layer.color)) out.setStrokeWidth(points_to_mm(layer.outline_layer.width)) if isinstance(layer.outline_layer, SimpleLineSymbolLayer): out.setStrokeStyle( symbol_pen_to_qpenstyle(layer.outline_layer.line_type)) if isinstance(layer.outline_layer, CartographicLineSymbolLayer): out.setPenJoinStyle( symbol_pen_to_qpenjoinstyle(layer.outline_layer.join)) # better matching of null stroke color to QGIS symbology if out.strokeColor().alpha() == 0: out.setStrokeStyle(Qt.NoPen) # todo - change to new symbol layer if outline offset set symbol.appendSymbolLayer(out) else: # outline is a symbol itself out.setStrokeStyle(Qt.NoPen) symbol.appendSymbolLayer(out) # get all layers from outline append_SymbolLayer_to_QgsSymbolLayer(symbol, layer.outline_symbol)
def SimpleFillSymbolLayer_to_QgsSimpleFillSymbolLayer(layer): """ Converts a SimpleFillSymbolLayer to a QgsSimpleFillSymbolLayer """ fill_color = symbol_color_to_qcolor(layer.color) out = QgsSimpleFillSymbolLayer(fill_color) if layer.outline_layer: if isinstance(layer.outline_layer, (SimpleLineSymbolLayer, CartographicLineSymbolLayer)): out.setStrokeColor( symbol_color_to_qcolor(layer.outline_layer.color)) out.setStrokeWidth(points_to_mm(layer.outline_layer.width)) if isinstance(layer.outline_layer, SimpleLineSymbolLayer): out.setStrokeStyle( symbol_pen_to_qpenstyle(layer.outline_layer.line_type)) if isinstance(layer.outline_layer, CartographicLineSymbolLayer): out.setPenJoinStyle( symbol_pen_to_qpenjoinstyle(layer.outline_layer.join)) # better matching of null stroke color to QGIS symbology if out.strokeColor().alpha() == 0: out.setStrokeStyle(Qt.NoPen) # todo - change to new symbol layer if outline offset set else: # todo - outline symbol layer raise NotImplementedException('Outline symbol layer not implemented') return out
def testCondenseFillAndOutline(self): """ Test QgsSymbolLayerUtils.condenseFillAndOutline """ self.assertFalse(QgsSymbolLayerUtils.condenseFillAndOutline( None, None)) # not simple fill or line self.assertFalse( QgsSymbolLayerUtils.condenseFillAndOutline( QgsShapeburstFillSymbolLayer(), QgsSimpleLineSymbolLayer())) self.assertFalse( QgsSymbolLayerUtils.condenseFillAndOutline( QgsSimpleFillSymbolLayer(), QgsMarkerLineSymbolLayer())) # simple fill/line fill = QgsSimpleFillSymbolLayer() line = QgsSimpleLineSymbolLayer() # set incompatible settings on outline line.setUseCustomDashPattern(True) self.assertFalse(QgsSymbolLayerUtils.condenseFillAndOutline( fill, line)) line = QgsSimpleLineSymbolLayer() line.setDashPatternOffset(1) self.assertFalse(QgsSymbolLayerUtils.condenseFillAndOutline( fill, line)) line = QgsSimpleLineSymbolLayer() line.setAlignDashPattern(True) self.assertFalse(QgsSymbolLayerUtils.condenseFillAndOutline( fill, line)) line = QgsSimpleLineSymbolLayer() line.setTweakDashPatternOnCorners(True) self.assertFalse(QgsSymbolLayerUtils.condenseFillAndOutline( fill, line)) line = QgsSimpleLineSymbolLayer() line.setTrimDistanceStart(1) self.assertFalse(QgsSymbolLayerUtils.condenseFillAndOutline( fill, line)) line = QgsSimpleLineSymbolLayer() line.setTrimDistanceEnd(1) self.assertFalse(QgsSymbolLayerUtils.condenseFillAndOutline( fill, line)) line = QgsSimpleLineSymbolLayer() line.setDrawInsidePolygon(True) self.assertFalse(QgsSymbolLayerUtils.condenseFillAndOutline( fill, line)) line = QgsSimpleLineSymbolLayer() line.setRingFilter(QgsSimpleLineSymbolLayer.ExteriorRingOnly) self.assertFalse(QgsSymbolLayerUtils.condenseFillAndOutline( fill, line)) line = QgsSimpleLineSymbolLayer() line.setOffset(1) self.assertFalse(QgsSymbolLayerUtils.condenseFillAndOutline( fill, line)) line = QgsSimpleLineSymbolLayer() line.setDataDefinedProperty(QgsSymbolLayer.PropertyTrimEnd, QgsProperty.fromValue(4)) self.assertFalse(QgsSymbolLayerUtils.condenseFillAndOutline( fill, line)) # compatible! line = QgsSimpleLineSymbolLayer() line.setColor(QColor(255, 0, 0)) line.setWidth(1.2) line.setWidthUnit(QgsUnitTypes.RenderPoints) line.setWidthMapUnitScale(QgsMapUnitScale(1, 2)) line.setPenJoinStyle(Qt.MiterJoin) line.setPenStyle(Qt.DashDotDotLine) self.assertTrue(QgsSymbolLayerUtils.condenseFillAndOutline(fill, line)) self.assertEqual(fill.strokeColor(), QColor(255, 0, 0)) self.assertEqual(fill.strokeWidth(), 1.2) self.assertEqual(fill.strokeWidthUnit(), QgsUnitTypes.RenderPoints) self.assertEqual(fill.strokeWidthMapUnitScale(), QgsMapUnitScale(1, 2)) self.assertEqual(fill.penJoinStyle(), Qt.MiterJoin) self.assertEqual(fill.strokeStyle(), Qt.DashDotDotLine)
def append_SimpleFillSymbolLayer( symbol, # pylint: disable=too-many-branches layer: SimpleFillSymbolLayer, context: Context): """ Appends a SimpleFillSymbolLayer to a symbol """ fill_color = symbol_color_to_qcolor(layer.color) out = QgsSimpleFillSymbolLayer(fill_color) out.setEnabled(layer.enabled) out.setLocked(layer.locked) if isinstance(layer, SimpleFillSymbolLayer): if layer.outline_layer: if isinstance( layer.outline_layer, (SimpleLineSymbolLayer, CartographicLineSymbolLayer)): out.setStrokeColor( symbol_color_to_qcolor(layer.outline_layer.color)) out.setStrokeWidth( context.convert_size(layer.outline_layer.width)) out.setStrokeWidthUnit(context.units) if isinstance(layer.outline_layer, SimpleLineSymbolLayer): out.setStrokeStyle( symbol_pen_to_qpenstyle(layer.outline_layer.line_type)) if isinstance(layer.outline_layer, CartographicLineSymbolLayer): out.setPenJoinStyle( symbol_pen_to_qpenjoinstyle(layer.outline_layer.join)) # better matching of null stroke color to QGIS symbology if out.strokeColor().alpha() == 0: out.setStrokeStyle(Qt.NoPen) # TODO try: if layer.outline_layer.offset: raise NotImplementedException( 'Fill outline offset not supported') except AttributeError: pass try: if layer.outline_layer.template: raise NotImplementedException( 'Fill outline template not supported') except AttributeError: pass try: if layer.outline_layer.decoration: raise NotImplementedException( 'Fill outline decoration not supported') except AttributeError: pass symbol.appendSymbolLayer(out) elif layer.outline_symbol: # outline is a symbol itself out.setStrokeStyle(Qt.NoPen) symbol.appendSymbolLayer(out) # get all layers from outline append_SymbolLayer_to_QgsSymbolLayer(symbol, layer.outline_symbol, context) else: out.setStrokeStyle(Qt.NoPen) symbol.appendSymbolLayer(out) elif isinstance(layer, ColorSymbol): out.setStrokeStyle(Qt.NoPen) symbol.appendSymbolLayer(out)