Bug 441704 - Modified annotations are not saved
Summary: Modified annotations are not saved
Status: REPORTED
Alias: None
Product: krita
Classification: Unclassified
Component: Scripting (show other bugs)
Version: 5.0.0-beta1
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-29 14:08 UTC by grum999
Modified: 2021-08-29 14:08 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description grum999 2021-08-29 14:08:11 UTC
SUMMARY

Using the Python Scripting API, in some case the annotations are not saved.


STEPS TO REPRODUCE
1. Add annotation
2. Save document 
3. Modify an existing annotation
4. Save document 
5. Close document 
6. Load document, check annotation

OBSERVED RESULT
Added annotation from step 1 are here, but without modification made on step 3

EXPECTED RESULT
Modified annotation must be saved


ADDITIONAL INFORMATION
Here an example that can be executed in scripter:

```
from krita import *

fileName="/home/grum/test.kra"

doc = Krita.instance().createDocument(300, 300, "Test", "RGBA", "U8", "", 300.0)
#Krita.instance().activeWindow().addView(doc)

# -- add annotations --
for i in range(3):
    text=f"encoded data {i}={i*' ** '}"
    doc.setAnnotation(f'test{i}', f"added {i}", QByteArray(text.encode()))

print("-add------------")
for annotation in doc.annotationTypes():
    ba=doc.annotation(annotation)
    print("annotation: ", annotation, " / description: ", doc.annotationDescription(annotation), " / Content: ", bytes(ba).decode())
   
print("-save document---------")
doc.saveAs(fileName)


# -- update annotations --

for i in range(3):
    text=f"encoded data {i}={i*' ++ '}"
    doc.setAnnotation(f'test{i}', f"modified {i}", QByteArray(text.encode()))

print("-update---------")
for annotation in doc.annotationTypes():
    ba=doc.annotation(annotation)
    print("annotation: ", annotation, " / description: ", doc.annotationDescription(annotation), " / Content: ", bytes(ba).decode())

print("-save document---------")
doc.save()
doc.close()



doc=Krita.instance().openDocument(fileName)

print("-loaded------------")
for annotation in doc.annotationTypes():
    ba=doc.annotation(annotation)
    print("annotation: ", annotation, " / description: ", doc.annotationDescription(annotation), " / Content: ", bytes(ba).decode())

doc.close()
```



Result:
```
-add------------
annotation:  test0  / description:  added 0  / Content:  encoded data 0=
annotation:  test1  / description:  added 1  / Content:  encoded data 1= ** 
annotation:  test2  / description:  added 2  / Content:  encoded data 2= **  ** 
-save document---------
-update---------
annotation:  test0  / description:  modified 0  / Content:  encoded data 0=
annotation:  test1  / description:  modified 1  / Content:  encoded data 1= ++ 
annotation:  test2  / description:  modified 2  / Content:  encoded data 2= ++  ++ 
-save document---------
-loaded------------
annotation:  test0  / description:  added 0  / Content:  encoded data 0=
annotation:  test1  / description:  added 1  / Content:  encoded data 1= ** 
annotation:  test2  / description:  added 2  / Content:  encoded data 2= **  ** 
```
We can see that modification are not taken in account.


This is because when an annotation is added/removed, document is marked as modified.
But if document is in saved state (not modified), a modification of an existing annotation don't mark document as modified and save action does nothing (as krita consider document is unmodified)


In https://invent.kde.org/graphics/krita/-/blob/master/libs/image/kis_image.cc

```
void KisImage::addAnnotation(KisAnnotationSP annotation)
{
    // Find the icc annotation, if there is one
    vKisAnnotationSP_it it = m_d->annotations.begin();
    while (it != m_d->annotations.end()) {
        if ((*it)->type() == annotation->type()) {
            *it = annotation;
            emit sigImageModified();
            return;
        }
        ++it;
    }
    m_d->annotations.push_back(annotation);
    setModifiedWithoutUndo();
}
```

Line 1708, use of `setModifiedWithoutUndo();` instead of `emit sigImageModified();` will solve the problem.



Grum999