Skip to content
Permalink
Browse files
Indentation
  • Loading branch information
nyalldawson committed Aug 19, 2021
1 parent aeb7d89 commit 8e87c7e436ad756a0d5e188971c4b719da59b24d
Showing with 36 additions and 21 deletions.
  1. +36 −21 tests/src/python/test_qgsannotationlayer.py
@@ -13,13 +13,13 @@
__copyright__ = 'Copyright 2020, The QGIS Project'

import qgis # NOQA

from qgis.PyQt.QtCore import (QSize,
QDir,
QTemporaryDir)
from qgis.PyQt.QtGui import (QImage,
QPainter,
QColor)
from qgis.PyQt.QtXml import QDomDocument
from qgis.core import (QgsMapSettings,
QgsCoordinateTransform,
QgsProject,
@@ -39,9 +39,8 @@
QgsLineSymbol,
QgsMarkerSymbol,
)
from qgis.PyQt.QtXml import QDomDocument

from qgis.testing import start_app, unittest

from utilities import unitTestDataPath

start_app()
@@ -68,8 +67,10 @@ def testItems(self):
self.assertIsNone(layer.item('xxxx'))
self.assertIsNone(layer.item(''))

polygon_item_id = layer.addItem(QgsAnnotationPolygonItem(QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
linestring_item_id = layer.addItem(QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)])))
polygon_item_id = layer.addItem(QgsAnnotationPolygonItem(
QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
linestring_item_id = layer.addItem(
QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)])))
marker_item_id = layer.addItem(QgsAnnotationMarkerItem(QgsPoint(12, 13)))

self.assertEqual(len(layer.items()), 3)
@@ -101,7 +102,8 @@ def testItems(self):
self.assertEqual(len(layer.items()), 0)
self.assertTrue(layer.isEmpty())

layer.addItem(QgsAnnotationPolygonItem(QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
layer.addItem(QgsAnnotationPolygonItem(
QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
layer.addItem(QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)])))
layer.addItem(QgsAnnotationMarkerItem(QgsPoint(12, 13)))

@@ -112,7 +114,8 @@ def testItems(self):
def testReset(self):
layer = QgsAnnotationLayer('test', QgsAnnotationLayer.LayerOptions(QgsProject.instance().transformContext()))
self.assertTrue(layer.isValid())
layer.addItem(QgsAnnotationPolygonItem(QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
layer.addItem(QgsAnnotationPolygonItem(
QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
layer.addItem(QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)])))
layer.addItem(QgsAnnotationMarkerItem(QgsPoint(12, 13)))
layer.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
@@ -127,7 +130,8 @@ def testExtent(self):
layer = QgsAnnotationLayer('test', QgsAnnotationLayer.LayerOptions(QgsProject.instance().transformContext()))
self.assertTrue(layer.isValid())

layer.addItem(QgsAnnotationPolygonItem(QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
layer.addItem(QgsAnnotationPolygonItem(
QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
layer.addItem(QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)])))
layer.addItem(QgsAnnotationMarkerItem(QgsPoint(12, 13)))

@@ -149,12 +153,14 @@ def testItemsInBounds(self):
layer = QgsAnnotationLayer('test', QgsAnnotationLayer.LayerOptions(QgsProject.instance().transformContext()))
self.assertTrue(layer.isValid())

item1uuid = layer.addItem(QgsAnnotationPolygonItem(QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
item2uuid = layer.addItem(QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 150)])))
item1uuid = layer.addItem(QgsAnnotationPolygonItem(
QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
item2uuid = layer.addItem(
QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 150)])))
item3uuid = layer.addItem(QgsAnnotationMarkerItem(QgsPoint(120, 13)))

self.assertFalse(layer.itemsInBounds(QgsRectangle(-10,-10, -9,9)))
self.assertCountEqual(layer.itemsInBounds(QgsRectangle(12,13, 14,15)), [item1uuid, item2uuid])
self.assertFalse(layer.itemsInBounds(QgsRectangle(-10, -10, -9, 9)))
self.assertCountEqual(layer.itemsInBounds(QgsRectangle(12, 13, 14, 15)), [item1uuid, item2uuid])
self.assertCountEqual(layer.itemsInBounds(QgsRectangle(12, 130, 14, 150)), [item2uuid])
self.assertCountEqual(layer.itemsInBounds(QgsRectangle(110, 0, 120, 20)), [item3uuid])

@@ -165,8 +171,10 @@ def testReadWriteXml(self):
self.assertTrue(layer.isValid())

layer.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
polygon_item_id = layer.addItem(QgsAnnotationPolygonItem(QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
linestring_item_id = layer.addItem(QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)])))
polygon_item_id = layer.addItem(QgsAnnotationPolygonItem(
QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
linestring_item_id = layer.addItem(
QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)])))
marker_item_id = layer.addItem(QgsAnnotationMarkerItem(QgsPoint(12, 13)))

elem = doc.createElement("maplayer")
@@ -185,8 +193,10 @@ def testClone(self):
layer = QgsAnnotationLayer('test', QgsAnnotationLayer.LayerOptions(QgsProject.instance().transformContext()))
self.assertTrue(layer.isValid())

polygon_item_id = layer.addItem(QgsAnnotationPolygonItem(QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
linestring_item_id = layer.addItem(QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)])))
polygon_item_id = layer.addItem(QgsAnnotationPolygonItem(
QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
linestring_item_id = layer.addItem(
QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)])))
marker_item_id = layer.addItem(QgsAnnotationMarkerItem(QgsPoint(12, 13)))

layer2 = layer.clone()
@@ -203,8 +213,10 @@ def testProjectMainAnnotationLayer(self):
self.assertIsNotNone(p.mainAnnotationLayer())

# add some items to project annotation layer
polygon_item_id = p.mainAnnotationLayer().addItem(QgsAnnotationPolygonItem(QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
linestring_item_id = p.mainAnnotationLayer().addItem(QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)])))
polygon_item_id = p.mainAnnotationLayer().addItem(QgsAnnotationPolygonItem(
QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)]))))
linestring_item_id = p.mainAnnotationLayer().addItem(
QgsAnnotationLineItem(QgsLineString([QgsPoint(11, 13), QgsPoint(12, 13), QgsPoint(12, 15)])))
marker_item_id = p.mainAnnotationLayer().addItem(QgsAnnotationMarkerItem(QgsPoint(12, 13)))

# save project to xml
@@ -229,7 +241,8 @@ def testRenderLayer(self):
layer.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
self.assertTrue(layer.isValid())

item = QgsAnnotationPolygonItem(QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)])))
item = QgsAnnotationPolygonItem(
QgsPolygon(QgsLineString([QgsPoint(12, 13), QgsPoint(14, 13), QgsPoint(14, 15), QgsPoint(12, 13)])))
item.setSymbol(
QgsFillSymbol.createSimple({'color': '200,100,100', 'outline_color': 'black', 'outline_width': '2'}))
item.setZIndex(3)
@@ -272,7 +285,8 @@ def testRenderWithTransform(self):
layer = QgsAnnotationLayer('test', QgsAnnotationLayer.LayerOptions(QgsProject.instance().transformContext()))
self.assertTrue(layer.isValid())

item = QgsAnnotationPolygonItem(QgsPolygon(QgsLineString([QgsPoint(11.5, 13), QgsPoint(12, 13), QgsPoint(12, 13.5), QgsPoint(11.5, 13)])))
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'}))
item.setZIndex(1)
@@ -299,7 +313,8 @@ def testRenderWithTransform(self):

rc = QgsRenderContext.fromMapSettings(settings)
rc.setCoordinateTransform(QgsCoordinateTransform(layer.crs(), settings.destinationCrs(), QgsProject.instance()))
rc.setExtent(rc.coordinateTransform().transformBoundingBox(settings.extent(), QgsCoordinateTransform.ReverseTransform))
rc.setExtent(
rc.coordinateTransform().transformBoundingBox(settings.extent(), QgsCoordinateTransform.ReverseTransform))
image = QImage(200, 200, QImage.Format_ARGB32)
image.setDotsPerMeterX(96 / 25.4 * 1000)
image.setDotsPerMeterY(96 / 25.4 * 1000)

0 comments on commit 8e87c7e

Please sign in to comment.