Fix data loss after flattening the image from inside the group
Summary:
Before this patch, if the selected layer was inside of a group
and user requested flattening of the image, all layers
were deleted and no new layer with merged content appeared.
This commit makes the new layer with the merged content
be created and added to the layers stack.
BUG:405119
Test Plan:
- testing with test file from BUG:404200 both from inside
of the group (Layer 2) and outside of the group (Layer 1)
- running unit tests added to the project in the patch
- merging and unmerging layers in a complex file
Reviewers: Krita, rempt
Reviewed By: Krita, rempt
Subscribers: rempt
Tags: Krita
Differential Revision: https://phabricator.kde.org/D19593