Skip to content
Permalink
Browse files

Add unit tests for curved annotation geometries

  • Loading branch information
nyalldawson committed Aug 19, 2020
1 parent 15221db commit 5f0ce534e669e92b8ae3a387539a3e37e05db0ab
@@ -28,7 +28,8 @@
QgsRenderContext,
QgsAnnotationLineItem,
QgsRectangle,
QgsLineString
QgsLineString,
QgsCircularString
)
from qgis.PyQt.QtXml import QDomDocument

@@ -117,6 +118,32 @@ def testRenderLineString(self):

self.assertTrue(self.imageCheck('linestring_item', 'linestring_item', image))

def testRenderCurve(self):
item = QgsAnnotationLineItem(QgsCircularString(QgsPoint(12, 13.2), QgsPoint(14, 13.4), QgsPoint(14, 15)))
item.setSymbol(QgsLineSymbol.createSimple({'color': '#ffff00', 'line_width': '3'}))

settings = QgsMapSettings()
settings.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
settings.setExtent(QgsRectangle(10, 10, 18, 18))
settings.setOutputSize(QSize(300, 300))

settings.setFlag(QgsMapSettings.Antialiasing, False)

rc = QgsRenderContext.fromMapSettings(settings)
image = QImage(200, 200, QImage.Format_ARGB32)
image.setDotsPerMeterX(96 / 25.4 * 1000)
image.setDotsPerMeterY(96 / 25.4 * 1000)
image.fill(QColor(255, 255, 255))
painter = QPainter(image)
rc.setPainter(painter)

try:
item.render(rc, None)
finally:
painter.end()

self.assertTrue(self.imageCheck('line_circularstring', 'line_circularstring', image))

def testRenderWithTransform(self):
item = QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)]))
item.setSymbol(QgsLineSymbol.createSimple({'color': '#ffff00', 'line_width': '3'}))
@@ -29,7 +29,9 @@
QgsAnnotationPolygonItem,
QgsRectangle,
QgsLineString,
QgsPolygon
QgsPolygon,
QgsCurvePolygon,
QgsCircularString
)
from qgis.PyQt.QtXml import QDomDocument

@@ -118,6 +120,36 @@ def testRenderPolygon(self):

self.assertTrue(self.imageCheck('polygon_item', 'polygon_item', image))

def testRenderCurvePolygon(self):
cs = QgsCircularString()
cs.setPoints([QgsPoint(12, 13.2), QgsPoint(14, 13.4), QgsPoint(14, 15), QgsPoint(13, 15.1), QgsPoint(12, 13.2)])
cp = QgsCurvePolygon()
cp.setExteriorRing(cs)
item = QgsAnnotationPolygonItem(cp)
item.setSymbol(QgsFillSymbol.createSimple({'color': '200,100,100', 'outline_color': 'black', 'outline_width': '2'}))

settings = QgsMapSettings()
settings.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
settings.setExtent(QgsRectangle(10, 10, 18, 18))
settings.setOutputSize(QSize(300, 300))

settings.setFlag(QgsMapSettings.Antialiasing, False)

rc = QgsRenderContext.fromMapSettings(settings)
image = QImage(200, 200, QImage.Format_ARGB32)
image.setDotsPerMeterX(96 / 25.4 * 1000)
image.setDotsPerMeterY(96 / 25.4 * 1000)
image.fill(QColor(255, 255, 255))
painter = QPainter(image)
rc.setPainter(painter)

try:
item.render(rc, None)
finally:
painter.end()

self.assertTrue(self.imageCheck('curvepolygon_item', 'curvepolygon_item', image))

def testRenderWithTransform(self):
item = QgsAnnotationPolygonItem(QgsPolygon(QgsLineString([QgsPoint(11.5, 13), QgsPoint(12, 13), QgsPoint(12, 13.5), QgsPoint(11.5, 13)])))
item.setSymbol(QgsFillSymbol.createSimple({'color': '200,100,100', 'outline_color': 'black', 'outline_width': '2'}))
Binary file not shown.
Binary file not shown.

0 comments on commit 5f0ce53

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