Bug report #14812
Saving / re-openning a project reverse the annotations z-order
|Affected QGIS version:||master||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||22768|
To reproduce :
- Create a project
- Add an annotation
- Add a second annotation that overlap the first one.
- Save the project.
- Re-open the project.
=> The annotations display in reversed z-order.
Note : I don't see any possibility to manage the annotations z-order.
Save annotations to project.qgs in creation order (fix #14812)
Save annotations to project file in the order they were loaded or
created, so that annotations have the same display order each
time the project is opened.
#1 Updated by Simon Chenery over 5 years ago
- File 14812.patch.txt added
If I create three Text Annotations 'Annotation1', 'Annotation2' and 'Annotation3' and save the project, then the Text Annotations are saved in order 'Annotation3', 'Annotation2', 'Annotation1' in the project.qgs file.
This is because QgsMapCanvas::items() (from parent class QGraphicsView::items()) returns the items in "stacking order" with the uppermost item 'Annotation3' first, and QgisApp::writeAnnotationItemsToProject saves the Text Annotations in this order too.
When I load the project again, 'Annotation1' is now on top, although it was on the bottom before.
Solution is to go through the QgsAnnotationItem list in reverse order when saving the project.qgs file -- this logic is already used in QgsMapCanvas::saveAsImage for creating an image file.
A master patch is attached (git diff --patch > /tmp/14812.patch.txt).