Skip to content
Permalink
Browse files

Simple line test

  • Loading branch information
nyalldawson committed Nov 17, 2020
1 parent b159365 commit d90c54083cb55f42f460a214b255f0b26596a094
@@ -23,13 +23,16 @@

import qgis # NOQA

import os

from utilities import unitTestDataPath

from qgis.PyQt.QtCore import QDir, Qt
from qgis.PyQt.QtCore import QDir, Qt, QSize
from qgis.PyQt.QtGui import QImage, QColor, QPainter
from qgis.PyQt.QtXml import QDomDocument

from qgis.core import (QgsGeometry,
QgsRectangle,
QgsFillSymbol,
QgsRenderContext,
QgsFeature,
@@ -42,8 +45,11 @@
QgsLineSymbol,
QgsUnitTypes,
QgsMapUnitScale,
QgsVectorLayer,
QgsSymbolLayer,
QgsProperty
QgsMultiRenderChecker,
QgsProperty,
QgsSingleSymbolRenderer
)

from qgis.testing import unittest, start_app
@@ -219,6 +225,34 @@ def testRingFilter(self):
rendered_image = self.renderGeometry(s3, g)
assert self.imageCheck('simpleline_interioronly', 'simpleline_interioronly', 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.createSimple({'outline_color': '#ff0000', 'outline_width': '2'})
s.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertyStrokeColor, QgsProperty.fromExpression(
"if(Name='Arterial', 'red', 'green')"))

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

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

0 comments on commit d90c540

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