Skip to content
Permalink
Browse files

Add arrow symbol layer test

  • Loading branch information
nyalldawson committed Nov 17, 2020
1 parent d90c540 commit 0c4245fc2bfaacf6d17b1cdbc903de4d53f79fa9
@@ -25,7 +25,7 @@

import os

from qgis.PyQt.QtCore import QSize
from qgis.PyQt.QtCore import QSize, QDir
from qgis.PyQt.QtGui import QColor

from qgis.core import (
@@ -38,7 +38,8 @@
QgsArrowSymbolLayer,
QgsMultiRenderChecker,
QgsProperty,
QgsSymbolLayer
QgsSymbolLayer,
QgsMapSettings
)

from qgis.testing import start_app, unittest
@@ -54,6 +55,8 @@
class TestQgsArrowSymbolLayer(unittest.TestCase):

def setUp(self):
self.report = "<h1>Python QgsArrowSymbolLayer Tests</h1>\n"

self.iface = get_iface()

lines_shp = os.path.join(TEST_DATA_DIR, 'lines.shp')
@@ -72,6 +75,9 @@ def setUp(self):

def tearDown(self):
QgsProject.instance().removeAllMapLayers()
report_file_path = "%s/qgistest.html" % QDir.tempPath()
with open(report_file_path, 'a') as report_file:
report_file.write(self.report)

def test_1(self):
sym = self.lines_layer.renderer().symbol()
@@ -160,6 +166,43 @@ def testColors(self):
self.assertEqual(sym_layer.subSymbol().color(), QColor(250, 150, 200))
self.assertEqual(sym_layer.color(), QColor(250, 150, 200))

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())

sym = QgsLineSymbol()
sym_layer = QgsArrowSymbolLayer.create({'arrow_width': '7', 'head_length': '6', 'head_thickness': '8', 'head_type': '0', 'arrow_type': '0', 'is_repeated': '0', 'is_curved': '0'})
fill_sym = QgsFillSymbol.createSimple({'color': '#8bcfff', 'outline_color': '#000000', 'outline_style': 'solid', 'outline_width': '1'})
fill_sym.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression(
"if(Name='Arterial', 'red', 'green')"))
fill_sym.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertyStrokeColor, QgsProperty.fromExpression(
"if(Name='Arterial', 'magenta', 'blue')"))

sym_layer.setSubSymbol(fill_sym)
sym.changeSymbolLayer(0, sym_layer)

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

line_layer.setRenderer(QgsSingleSymbolRenderer(sym))

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_arrow')
renderchecker.setControlName('expected_arrow_opacityddcolor')
res = renderchecker.runTest('expected_arrow_opacityddcolor')
self.report += renderchecker.report()
self.assertTrue(res)


if __name__ == '__main__':
unittest.main()
Binary file not shown.

0 comments on commit 0c4245f

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