Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add simple line custom dash pattern tests
  • Loading branch information
nirvn committed Apr 28, 2019
1 parent db5bfdc commit 8401db1
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions tests/src/python/test_qgslinesymbollayers.py
Expand Up @@ -90,6 +90,82 @@ def testSimpleLineWithOffset(self):

self.assertTrue(self.imageCheck('symbol_layer', 'simpleline_offset', image))

def testSimpleLineWithCustomDashPattern(self):
""" test that rendering a simple line symbol with custom dash pattern"""
layer = QgsSimpleLineSymbolLayer(QColor(0, 0, 0))
layer.setWidth(0.5)
layer.setCustomDashVector([2, 5])
layer.setUseCustomDashPattern(True)

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

image = QImage(200, 200, QImage.Format_RGB32)
painter = QPainter()
ms = QgsMapSettings()

geom = QgsGeometry.fromWkt('LineString (0 0, 10 0, 10 10, 0 10, 0 0)')
f = QgsFeature()
f.setGeometry(geom)

extent = geom.constGet().boundingBox()
# buffer extent by 10%
extent = extent.buffered((extent.height() + extent.width()) / 20.0)

ms.setExtent(extent)
ms.setOutputSize(image.size())
context = QgsRenderContext.fromMapSettings(ms)
context.setPainter(painter)
context.setScaleFactor(96 / 25.4) # 96 DPI

painter.begin(image)
image.fill(QColor(255, 255, 255))

symbol.startRender(context)
symbol.renderFeature(f, context)
symbol.stopRender(context)
painter.end()

self.assertTrue(self.imageCheck('symbol_layer_simpleline_customdashpattern', 'simpleline_customdashpattern', image))

def testSimpleLineWithCustomDashPatternHairline(self):
""" test that rendering a simple line symbol with custom dash pattern"""
layer = QgsSimpleLineSymbolLayer(QColor(0, 0, 0))
layer.setWidth(0)
layer.setCustomDashVector([3, 3, 2, 2])
layer.setUseCustomDashPattern(True)

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

image = QImage(200, 200, QImage.Format_RGB32)
painter = QPainter()
ms = QgsMapSettings()

geom = QgsGeometry.fromWkt('LineString (0 0, 10 0, 10 10, 0 10, 0 0)')
f = QgsFeature()
f.setGeometry(geom)

extent = geom.constGet().boundingBox()
# buffer extent by 10%
extent = extent.buffered((extent.height() + extent.width()) / 20.0)

ms.setExtent(extent)
ms.setOutputSize(image.size())
context = QgsRenderContext.fromMapSettings(ms)
context.setPainter(painter)
context.setScaleFactor(96 / 25.4) # 96 DPI

painter.begin(image)
image.fill(QColor(255, 255, 255))

symbol.startRender(context)
symbol.renderFeature(f, context)
symbol.stopRender(context)
painter.end()

self.assertTrue(self.imageCheck('symbol_layer_simpleline_customdashpattern_hairline', 'simpleline_customdashpattern_hairline', image))


if __name__ == '__main__':
unittest.main()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8401db1

Please sign in to comment.