SUMMARY I'm testing annotations that have been implemented with Krita 5 I'm facing an issue on annotation loading, when more than one annotation is saved in document. - Annotations are OK when just created (possible to access all annotations) - Annotations are KO after document is loaded . All annotations are visible . All annotations identifier are OK . All annotations description are OK . Annotations data are KO => only the last one is loaded Looking kra file, everything is OK: - maindoc.xml => all annotations are present - all annotations files => present and contains expected data So it’s seems problem is during file loading, only the last annotation content is loaded. STEPS TO REPRODUCE 1. With Python Scripting, execute following script: # ------------------------------------ from krita import * fileName="/home/grum/Temporaire/test.kra" doc = Krita.instance().createDocument(300, 300, "Test", "RGBA", "U8", "", 300.0) #Krita.instance().activeWindow().addView(doc) for i in range(3): text=f"{i}={i*' * '}" doc.setAnnotation(f'test{i}', f"description {i}", QByteArray(text.encode())) print("-set------------") for annotation in doc.annotationTypes(): print("annotation: ", annotation, "description: ", doc.annotationDescription(annotation)) ba=doc.annotation(annotation) print(bytes(ba).decode()) doc.saveAs(fileName) doc.close() doc=Krita.instance().openDocument(fileName) print("-loaded------------") for annotation in doc.annotationTypes(): print("annotation: ", annotation, "description: ", doc.annotationDescription(annotation)) ba=doc.annotation(annotation) print(bytes(ba).decode()) doc.close() # ------------------------------------ OBSERVED RESULT The following result is displayed on output: # ------------------------------------ -set------------ annotation: test0 description: description 0 0= annotation: test1 description: description 1 1= * annotation: test2 description: description 2 2= * * -loaded------------ annotation: test2 description: description 2 2= * * annotation: test1 description: description 1 annotation: test0 description: description 0 # ------------------------------------ EXPECTED RESULT The following expected result should be displayed on output: # ------------------------------------ -loaded------------ annotation: test0 description: description 0 0= annotation: test1 description: description 1 1= * annotation: test2 description: description 2 2= * * # ------------------------------------ ==> loaded data should match with data that have been saved SOFTWARE/OS VERSIONS Windows: not tested macOS: not tested Linux/KDE Plasma: Debian 10 (Krita 5 prealpha appimage) ADDITIONAL INFORMATION Problem seems not to be located in Python API but in core implementation: - Open document with more than one annotation. - In menu "Images > Properties", Tab "Annotations" => we can see all annotations listed, but data are available only for the last one (so for me problem is not only related to Python API)
Additionally - Open a document - Set and/or remove annotation The document is considered as not modified. Then close the document, all annotations changes are lost without any warning possibility. I think it’s not possible to add annotation in undo/redo stack, but at least when annotations are modified, file status should be changed to “modified”, otherwise: - that’s sure, some plugin annotations will be lost (and then, a part of user's work will be lost too) - plugins developers will try dirty and tricky things to force document to be in “modified” status
Git commit c0775ffa396e362cb0da37eba3d29d25bb48611e by Halla Rempt. Committed on 18/03/2021 at 10:47. Pushed by rempt into branch 'master'. Fix loading annotations and load them in the right order M +4 -0 libs/libkis/Document.cpp M +3 -3 plugins/impex/libkra/kis_kra_loader.cpp https://invent.kde.org/graphics/krita/commit/c0775ffa396e362cb0da37eba3d29d25bb48611e
Git commit 582d9a70a7bdaf89c8274a732f416674a451008b by Halla Rempt. Committed on 18/03/2021 at 10:48. Pushed by rempt into branch 'master'. Notify Krita that the image has been modified if an annotation is changed or added M +2 -0 libs/image/kis_image.cc https://invent.kde.org/graphics/krita/commit/582d9a70a7bdaf89c8274a732f416674a451008b