https://bugs.kde.org/show_bug.cgi?id=441704

            Bug ID: 441704
           Summary: Modified annotations are not saved
           Product: krita
           Version: 5.0.0-beta1
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: Scripting
          Assignee: krita-bugs-n...@kde.org
          Reporter: grum...@grum.fr
  Target Milestone: ---

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

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to