Skip to content
Permalink
Browse files

Add marker line test

  • Loading branch information
nyalldawson committed Nov 17, 2020
1 parent 9152a3d commit bfc7c118eea9811e7375c1d377af53ac1923d2a2
@@ -23,6 +23,7 @@

import qgis # NOQA

import os
from utilities import unitTestDataPath

from qgis.PyQt.QtCore import QDir, Qt, QSize
@@ -35,6 +36,7 @@
QgsFeature,
QgsMapSettings,
QgsRenderChecker,
QgsVectorLayer,
QgsReadWriteContext,
QgsSymbolLayerUtils,
QgsSimpleMarkerSymbolLayer,
@@ -50,7 +52,9 @@
QgsSymbolLayer,
QgsProperty,
QgsRectangle,
QgsUnitTypes
QgsUnitTypes,
QgsMultiRenderChecker,
QgsSingleSymbolRenderer
)

from qgis.testing import unittest, start_app
@@ -392,6 +396,50 @@ def testMarkerAngleDD(self):
rendered_image = self.renderGeometry(s, g)
assert self.imageCheck('markerline_center_angle_dd', 'markerline_center_angle_dd', rendered_image)

def testOpacityWithDataDefinedColor(self):
line_shp = os.path.join(TEST_DATA_DIR, 'lines.shp')
line_layer = QgsVectorLayer(line_shp, 'Lines', 'ogr')
self.assertTrue(line_layer.isValid())

s = QgsLineSymbol()
s.deleteSymbolLayer(0)
marker_line = QgsMarkerLineSymbolLayer(True)
marker_line.setPlacement(QgsTemplatedLineSymbolLayerBase.CentralPoint)
simple_marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Circle, 10)
simple_marker.setColor(QColor(0, 255, 0))
simple_marker.setStrokeColor(QColor(255, 0, 0))
simple_marker.setStrokeWidth(1)
simple_marker.setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression(
"if(Name='Arterial', 'red', 'green')"))
simple_marker.setDataDefinedProperty(QgsSymbolLayer.PropertyStrokeColor, QgsProperty.fromExpression(
"if(Name='Arterial', 'magenta', 'blue')"))

marker_symbol = QgsMarkerSymbol()
marker_symbol.changeSymbolLayer(0, simple_marker)
marker_symbol.setOpacity(0.5)
marker_line.setSubSymbol(marker_symbol)
s.appendSymbolLayer(marker_line.clone())

# set opacity on both the symbol and subsymbol, to test that they get combined
s.setOpacity(0.5)

line_layer.setRenderer(QgsSingleSymbolRenderer(s))

ms = QgsMapSettings()
ms.setOutputSize(QSize(400, 400))
ms.setOutputDpi(96)
ms.setExtent(QgsRectangle(-118.5, 19.0, -81.4, 50.4))
ms.setLayers([line_layer])

# Test rendering
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(ms)
renderchecker.setControlPathPrefix('symbol_markerline')
renderchecker.setControlName('expected_markerline_opacityddcolor')
res = renderchecker.runTest('expected_markerline_opacityddcolor')
self.report += renderchecker.report()
self.assertTrue(res)

def renderGeometry(self, symbol, geom, buffer=20):
f = QgsFeature()
f.setGeometry(geom)
Binary file not shown.

0 comments on commit bfc7c11

Please sign in to comment.
You can’t perform that action at this time.