|
46 | 46 | QgsGeometry,
|
47 | 47 | QgsLayoutItemShape,
|
48 | 48 | QgsMapClippingRegion,
|
49 |
| - QgsLayoutItemMapOverview) |
| 49 | + QgsLayoutItemMapOverview, |
| 50 | + QgsAnnotationPolygonItem) |
50 | 51 |
|
51 | 52 | from qgis.testing import start_app, unittest
|
52 | 53 | from utilities import unitTestDataPath
|
@@ -769,6 +770,58 @@ def testClippingBackgroundFrame(self):
|
769 | 770 | TestQgsLayoutMap.report += checker.report()
|
770 | 771 | self.assertTrue(result, message)
|
771 | 772 |
|
| 773 | + def testMainAnnotationLayer(self): |
| 774 | + """ |
| 775 | + Make sure main annotation layer is rendered in maps above all other layers |
| 776 | + """ |
| 777 | + p = QgsProject() |
| 778 | + |
| 779 | + vl = QgsVectorLayer("Polygon?crs=epsg:4326&field=fldtxt:string", |
| 780 | + "layer", "memory") |
| 781 | + sym3 = QgsFillSymbol.createSimple({'color': '#b200b2'}) |
| 782 | + vl.renderer().setSymbol(sym3) |
| 783 | + |
| 784 | + p.addMapLayer(vl) |
| 785 | + layout = QgsLayout(p) |
| 786 | + layout.initializeDefaults() |
| 787 | + p.setCrs(QgsCoordinateReferenceSystem('EPSG:4326')) |
| 788 | + map = QgsLayoutItemMap(layout) |
| 789 | + map.attemptSetSceneRect(QRectF(10, 10, 180, 180)) |
| 790 | + map.setFrameEnabled(True) |
| 791 | + map.setFrameStrokeWidth(QgsLayoutMeasurement(2, QgsUnitTypes.LayoutMillimeters)) |
| 792 | + map.setBackgroundEnabled(True) |
| 793 | + map.setBackgroundColor(QColor(200, 255, 200)) |
| 794 | + map.zoomToExtent(QgsRectangle(10, 30, 20, 35)) |
| 795 | + map.setLayers([vl]) |
| 796 | + layout.addLayoutItem(map) |
| 797 | + |
| 798 | + # add polygon to layer |
| 799 | + f = QgsFeature() |
| 800 | + f.setGeometry(QgsGeometry.fromRect(QgsRectangle(5, 25, 25, 45))) |
| 801 | + self.assertTrue(vl.dataProvider().addFeatures([f])) |
| 802 | + |
| 803 | + # no annotation yet... |
| 804 | + checker = QgsLayoutChecker('composermap_annotation_empty', layout) |
| 805 | + checker.setControlPathPrefix("composer_map") |
| 806 | + result, message = checker.testLayout() |
| 807 | + TestQgsLayoutMap.report += checker.report() |
| 808 | + self.assertTrue(result, message) |
| 809 | + |
| 810 | + annotation_layer = p.mainAnnotationLayer() |
| 811 | + annotation_layer.setCrs(QgsCoordinateReferenceSystem(4326)) |
| 812 | + annotation_geom = QgsGeometry.fromRect(QgsRectangle(12, 30, 18, 33)) |
| 813 | + annotation = QgsAnnotationPolygonItem(annotation_geom.constGet().clone()) |
| 814 | + sym3 = QgsFillSymbol.createSimple({'color': '#ff0000', 'outline_style': 'no'}) |
| 815 | + annotation.setSymbol(sym3) |
| 816 | + annotation_layer.addItem(annotation) |
| 817 | + |
| 818 | + # annotation must be drawn above map layers |
| 819 | + checker = QgsLayoutChecker('composermap_annotation_item', layout) |
| 820 | + checker.setControlPathPrefix("composer_map") |
| 821 | + result, message = checker.testLayout() |
| 822 | + TestQgsLayoutMap.report += checker.report() |
| 823 | + self.assertTrue(result, message) |
| 824 | + |
772 | 825 |
|
773 | 826 | if __name__ == '__main__':
|
774 | 827 | unittest.main()
|
0 commit comments