Skip to content
Permalink
Browse files

Add simple fill test

(cherry picked from commit 974046a)
  • Loading branch information
nyalldawson committed Nov 20, 2020
1 parent 3ccbbbf commit d4bf8cebaa5ea28f4dc8d2552c893f4eda5b49ca
@@ -117,6 +117,41 @@ def testDataDefinedOffset(self):
TestQgsSimpleFillSymbolLayer.report += renderchecker.report()
self.assertTrue(res)

def testOpacityWithDataDefinedColor(self):
poly_shp = os.path.join(TEST_DATA_DIR, 'polys.shp')
poly_layer = QgsVectorLayer(poly_shp, 'Polys', 'ogr')
self.assertTrue(poly_layer.isValid())

layer = QgsSimpleFillSymbolLayer()
layer.setStrokeStyle(Qt.NoPen)
layer.setColor(QColor(200, 250, 50))
layer.setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression(
"if(Name='Dam', 'red', 'green')"))
layer.setDataDefinedProperty(QgsSymbolLayer.PropertyStrokeColor, QgsProperty.fromExpression(
"if(Name='Dam', 'magenta', 'blue')"))

symbol = QgsFillSymbol()
symbol.changeSymbolLayer(0, layer)

symbol.setOpacity(0.5)

poly_layer.setRenderer(QgsSingleSymbolRenderer(symbol))

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

# Test rendering
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(ms)
renderchecker.setControlPathPrefix('symbol_simplefill')
renderchecker.setControlName('expected_simplefill_opacityddcolor')
res = renderchecker.runTest('expected_simplefill_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 d4bf8ce

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