Skip to content
Permalink
Browse files

Random marker test

  • Loading branch information
nyalldawson committed Nov 17, 2020
1 parent 62b630c commit 5394b36c563ba9fae9c5eb6a9fc2d1c7a1c20fef
@@ -23,6 +23,7 @@

import qgis # NOQA

import os
from utilities import unitTestDataPath

from qgis.PyQt.QtCore import QDir, Qt, QSize
@@ -40,7 +41,13 @@
QgsSimpleMarkerSymbolLayer,
QgsSimpleFillSymbolLayer,
QgsMarkerSymbol,
QgsRandomMarkerFillSymbolLayer
QgsRandomMarkerFillSymbolLayer,
QgsVectorLayer,
QgsSingleSymbolRenderer,
QgsProperty,
QgsSymbolLayer,
QgsRectangle,
QgsMultiRenderChecker
)

from qgis.testing import unittest, start_app
@@ -199,6 +206,47 @@ def testMultiLayer(self):
rendered_image = self.renderGeometry(s, g)
self.assertTrue(self.imageCheck('randommarkerfill_multilayer', 'randommarkerfill_multilayer', rendered_image))

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())
s = QgsFillSymbol()
s.deleteSymbolLayer(0)

random_fill = QgsRandomMarkerFillSymbolLayer(1, seed=481523)
marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Circle, 6)
marker.setColor(QColor(255, 0, 0))
marker.setStrokeWidth(1)
marker.setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression(
"if(Name='Dam', 'red', 'green')"))
marker.setDataDefinedProperty(QgsSymbolLayer.PropertyStrokeColor, QgsProperty.fromExpression(
"if(Name='Dam', 'magenta', 'blue')"))
marker_symbol = QgsMarkerSymbol()
marker_symbol.changeSymbolLayer(0, marker)
marker_symbol.setOpacity(0.5)
random_fill.setSubSymbol(marker_symbol)

s.appendSymbolLayer(random_fill.clone())

s.setOpacity(0.5)

poly_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([poly_layer])

# Test rendering
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(ms)
renderchecker.setControlPathPrefix('symbol_randommarkerfill')
renderchecker.setControlName('expected_randommarker_opacityddcolor')
res = renderchecker.runTest('expected_randommarker_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 5394b36

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