Commit b1bccb81 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix cloning of the image with overlay selection mask

When cloning the image with a copy-ctor it should have exactly
the same state as before cloning. It includes the state of the
overlay selection mask. It guarantees that there will be no async
jobs running right after the operation.

When saving, we don't want the overlay mask be saved into the file,
therefore we should run a separate action to disable it.

BUG:412747
parent 77717dbb
......@@ -408,7 +408,7 @@ void KisImage::copyFromImageImpl(const KisImage &rhs, int policy)
bool exactCopy = policy & EXACT_COPY;
if (exactCopy || rhs.m_d->isolatedRootNode) {
if (exactCopy || rhs.m_d->isolatedRootNode || rhs.m_d->overlaySelectionMask) {
QQueue<KisNodeSP> linearizedNodes;
KisLayerUtils::recursiveApplyNodes(rhs.root(),
[&linearizedNodes](KisNodeSP node) {
......@@ -426,6 +426,13 @@ void KisImage::copyFromImageImpl(const KisImage &rhs, int policy)
rhs.m_d->isolatedRootNode == refNode) {
m_d->isolatedRootNode = node;
}
if (rhs.m_d->overlaySelectionMask &&
KisNodeSP(rhs.m_d->overlaySelectionMask) == refNode) {
m_d->targetOverlaySelectionMask = dynamic_cast<KisSelectionMask*>(node.data());
m_d->overlaySelectionMask = m_d->targetOverlaySelectionMask;
m_d->rootLayer->notifyChildMaskChanged();
}
});
}
......@@ -456,13 +463,6 @@ void KisImage::copyFromImageImpl(const KisImage &rhs, int policy)
m_d->blockLevelOfDetail = rhs.m_d->blockLevelOfDetail;
/**
* The overlay device is not inherited when cloning the image!
*/
if (rhs.m_d->overlaySelectionMask) {
const QRect dirtyRect = rhs.m_d->overlaySelectionMask->extent();
m_d->rootLayer->setDirty(dirtyRect);
}
#undef EMIT_IF_NEEDED
}
......
......@@ -1273,15 +1273,20 @@ void KisImageTest::testPaintOverlayMask()
p.image->setOverlaySelectionMask(mask);
p.image->waitForDone();
KIS_DUMP_DEVICE_2(p.image->projection(), refRect, "01_activated", "dd");
KIS_DUMP_DEVICE_2(p.image->projection(), refRect, "01_activated_00_image", "dd");
KIS_DUMP_DEVICE_2(p.image->root()->original(), refRect, "01_activated_01_root_original", "dd");
KIS_DUMP_DEVICE_2(p.image->root()->projection(), refRect, "01_activated_02_root_projection", "dd");
KisImageSP clonedImage = p.image->clone();
clonedImage->waitForDone();
KIS_DUMP_DEVICE_2(clonedImage->projection(), refRect, "02_cloned_when_activated_00_image", "dd");
KIS_DUMP_DEVICE_2(clonedImage->root()->original(), refRect, "02_cloned_when_activated_01_root_original", "dd");
KIS_DUMP_DEVICE_2(clonedImage->root()->projection(), refRect, "02_cloned_when_activated_02_root_projection", "dd");
p.image->setOverlaySelectionMask(0);
p.image->waitForDone();
KIS_DUMP_DEVICE_2(p.image->projection(), refRect, "02_deactivated", "dd");
KIS_DUMP_DEVICE_2(p.image->projection(), refRect, "03_deactivated", "dd");
}
KISTEST_MAIN(KisImageTest)
......@@ -97,6 +97,7 @@
#include <kis_signal_auto_connection.h>
#include <kis_canvas_widget_base.h>
#include "kis_layer_utils.h"
#include "kis_selection_mask.h"
// Local
#include "KisViewManager.h"
......@@ -1017,6 +1018,11 @@ bool KisDocument::initiateSavingInBackground(const QString actionName,
}
}
if (clonedDocument->image()->hasOverlaySelectionMask()) {
clonedDocument->image()->setOverlaySelectionMask(0);
waitForImage(clonedDocument->image());
}
KIS_SAFE_ASSERT_RECOVER(clonedDocument->image()->isIdle()) {
waitForImage(clonedDocument->image());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment