Bug 475860

Summary: Quick-ungrouping a group with a mask may lead to data loss
Product: [Applications] krita Reporter: paleh <paleh21669>
Component: Layer StackAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: dimula73, wildcardc
Priority: NOR    
Version First Reported In: 5.2.0   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description paleh 2023-10-20 01:48:02 UTC
SUMMARY
When ungrouping a group containing any mask (except a selection mask) the layers located below the mask are correctly ungrouped, whereas the mask and the all layers above are deleted.  Undoing this operation doesn't bring the mask back, leading to a potential data loss. 


STEPS TO REPRODUCE
1. Create a group with at least one layer 
2. Create a mask (e.g. a transparency mask) inside the group, and place it below a layer. The mask should be applied to the group itself, not the layer.   
3. Execute some operations on the mask (e.g. draw some strokes if it's a transparency) 
4. Right click the group layer and do Group->Quick Ungroup
5. Press undo.
6. Press undo.

OBSERVED RESULT
After step 4, the layers above the mask have disappeared.
After step 5, the group is back, but it no longer contains the mask.
After step 6, which should undo the last operation done in step 3, nothing happens, as there is no mask to apply the change to. If the user can undo until step 1, then pressing "redo" enough times will bring the mask and all the work back. However if the undo stack has been exceeded, all the work done in step 3 will be lost.

EXPECTED RESULT
When ungrouping, layers above the mask should not get lost.
Masks should be at least recoverable through undo and, ideally, available after the ungrouping. For example filter and transparency mask could get converted to filter and transparency layers (maybe this should happen whenever a mask is created/dragged inside a group layer?). Alternatively, ungrouping could just push the regular layers outside the group while keeping the group layer as the container for the masks, if they are present.

SOFTWARE/OS VERSIONS
Linux: Ubuntu 22.04
Qt Version: 5.15.7

ADDITIONAL INFORMATION
also present in 5.1.5
Comment 1 Simon Ra 2023-10-20 06:08:37 UTC
I can confirm this, it's indeed possible to lose layer data, and krita will even think the image is "unchanged" if you hit undo with just the right/wrong timing.

The question is, what is the correct behaviour when ungrouping a group with more than one data layer and at least one mask layer?
1) Refuse to do so while mask layers are present
2) Drop the masks, possibly warn
3) Apply any mask to the topmost data layer in the group, or whichever data layer the mask is below (unintuitive)
4) Copy all masks to all data layers (safest but huge amount of duplication)
Comment 2 Dmitry Kazakov 2023-10-20 11:12:39 UTC
Hm... here locally, just mere ungrouping of the group removes all the layers inside it :(
Comment 3 Dmitry Kazakov 2023-10-20 14:56:46 UTC
Git commit 170b36b3c790a619046906e20a3dad208f7f520b by Dmitry Kazakov.
Committed on 20/10/2023 at 16:56.
Pushed by dkazakov into branch 'krita/5.2'.

Don't allow ungrouping if the layers cannot be put into the parent layer

Masks cannot be added to the root layer of the image, hence we shouldn't
allow ungrouping a layers with masks into the root.

M  +32   -7    libs/ui/kis_node_manager.cpp

https://invent.kde.org/graphics/krita/-/commit/170b36b3c790a619046906e20a3dad208f7f520b
Comment 4 Dmitry Kazakov 2023-10-20 14:58:10 UTC
Git commit f5f150972ebf57ade4dbfa3ce0bcd105f179c57b by Dmitry Kazakov.
Committed on 20/10/2023 at 16:57.
Pushed by dkazakov into branch 'master'.

Don't allow ungrouping if the layers cannot be put into the parent layer

Masks cannot be added to the root layer of the image, hence we shouldn't
allow ungrouping a layers with masks into the root.

M  +32   -7    libs/ui/kis_node_manager.cpp

https://invent.kde.org/graphics/krita/-/commit/f5f150972ebf57ade4dbfa3ce0bcd105f179c57b