Skip to content
Permalink
Browse files

Add hash line test

(cherry picked from commit 65c2542)
  • Loading branch information
nyalldawson committed Nov 20, 2020
1 parent b0cd8d6 commit e1085d701f1d2f51ce7fbf97d8c2a0f031cdb007
@@ -23,6 +23,7 @@

import qgis # NOQA

import os
from utilities import unitTestDataPath

from qgis.PyQt.QtCore import QDir, Qt, QSize
@@ -44,15 +45,17 @@
QgsGeometryGeneratorSymbolLayer,
QgsSymbol,
QgsFontMarkerSymbolLayer,
QgsFontUtils,
QgsMultiRenderChecker,
QgsLineSymbol,
QgsSymbolLayer,
QgsProperty,
QgsRectangle,
QgsUnitTypes,
QgsSimpleLineSymbolLayer,
QgsTemplatedLineSymbolLayerBase,
QgsHashedLineSymbolLayer
QgsHashedLineSymbolLayer,
QgsVectorLayer,
QgsSingleSymbolRenderer
)

from qgis.testing import unittest, start_app
@@ -355,6 +358,48 @@ def testSegmentCenter(self):
rendered_image = self.renderGeometry(s, g)
assert self.imageCheck('line_hash_segmentcenter', 'line_hash_segmentcenter', 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)
hash_line = QgsHashedLineSymbolLayer(True)
simple_line = QgsSimpleLineSymbolLayer()
simple_line.setColor(QColor(0, 255, 0))
simple_line.setDataDefinedProperty(QgsSymbolLayer.PropertyStrokeColor, QgsProperty.fromExpression(
"if(Name='Arterial', 'red', 'green')"))

simple_line.setWidth(1)
line_symbol = QgsLineSymbol()
line_symbol.changeSymbolLayer(0, simple_line)
line_symbol.setOpacity(0.5)
hash_line.setSubSymbol(line_symbol)
hash_line.setHashLength(10)
hash_line.setAverageAngleLength(0)
s.appendSymbolLayer(hash_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_hashline')
renderchecker.setControlName('expected_hashline_opacityddcolor')
res = renderchecker.runTest('expected_hashline_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 e1085d7

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