Skip to content

Commit

Permalink
Improve layout clipping test
Browse files Browse the repository at this point in the history
- Avoid QgsRectangle's normalisation (the min/max values were mismatched)
- Add helpful commentary to describe what the tests are testing and how
  • Loading branch information
kannes authored and nyalldawson committed Oct 4, 2023
1 parent 17a34a1 commit 3154e99
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/src/python/test_qgslayoutmapitemclippingsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,17 @@ def testSaveRestore(self):
self.assertEqual(map2.itemClippingSettings().sourceItem(), shape2)

def testClippedMapExtent(self):
# - we position a map and a triangle in a layout at specific layout/scene coordinates
# - the map is zoomed to a specific extent, defined in map/crs coordinates
# - we use the triangle to clip the map in the layout
# and test if the triangle is converted to the correct clipped extent in map/crs coordinates
p = QgsProject()
l = QgsPrintLayout(p)
map = QgsLayoutItemMap(l)
shape = QgsLayoutItemShape(l)
l.addLayoutItem(map)
map.attemptSetSceneRect(QRectF(10, 20, 100, 80))
map.zoomToExtent(QgsRectangle(100, 200, 50, 40))
map.zoomToExtent(QgsRectangle(50, 40, 100, 200))
l.addLayoutItem(shape)
shape.setShapeType(QgsLayoutItemShape.Triangle)
shape.attemptSetSceneRect(QRectF(20, 30, 70, 50))
Expand All @@ -166,14 +170,18 @@ def testClippedMapExtent(self):
self.assertEqual(geom.asWkt(), 'Polygon ((-5 80, 135 80, 65 180, -5 80))')

def testToMapClippingRegion(self):
# - we position a map and a triangle in a layout at specific layout/scene coordinates
# - the map is zoomed to a specific extent, defined in map/crs coordinates
# - we use the triangle to clip the map in the layout
# and test if the triangle is converted to the correct clipping shape in map/crs coordinates
p = QgsProject()
l = QgsPrintLayout(p)
p.layoutManager().addLayout(l)
map = QgsLayoutItemMap(l)
shape = QgsLayoutItemShape(l)
l.addLayoutItem(map)
map.attemptSetSceneRect(QRectF(10, 20, 100, 80))
map.zoomToExtent(QgsRectangle(100, 200, 50, 40))
map.zoomToExtent(QgsRectangle(50, 40, 100, 200))
l.addLayoutItem(shape)
shape.setShapeType(QgsLayoutItemShape.Triangle)
shape.attemptSetSceneRect(QRectF(20, 30, 70, 50))
Expand Down

0 comments on commit 3154e99

Please sign in to comment.