Commit 1bfd3493 authored by Tusooa Zhu's avatar Tusooa Zhu 🅱

Get rid of HACK code in KisNodeReplaceBasedStrokeStrategy

The crash of immediately ending the interaction comes from
updateTreeCompressor in KoShapeManager, and since we have
get rid of that, we will not need the deleteLater() strategy
any more.
parent db24b6d6
......@@ -28,6 +28,7 @@ ecm_add_tests(
kis_animation_importer_test.cpp
KisSpinBoxSplineUnitConverterTest.cpp
KisDocumentReplaceTest.cpp
KisImageNodeDeleteTest.cpp
LINK_LIBRARIES kritaui Qt5::Test
NAME_PREFIX "libs-ui-"
......
/*
* Copyright (c) 2019 Tusooa Zhu <tusooa@vista.aero>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "KisImageNodeDeleteTest.h"
#include <kis_image.h>
#include <KoColorSpaceRegistry.h>
#include <kis_paint_layer.h>
#include <KisRunnableBasedStrokeStrategy.h>
#include <kis_shape_layer.h>
#include <kis_shape_controller.h>
#include <KisPart.h>
#include <KisDocument.h>
#include <tests/MockShapes.h>
#include <kistest.h>
class ClonableShape : public MockShape
{
public:
ClonableShape() : MockShape() {}
~ClonableShape() = default;
KoShape * cloneShape() const override { return new ClonableShape(*this); }
};
class TestStrokeStrategy : public KisRunnableBasedStrokeStrategy
{
public:
TestStrokeStrategy(KisShapeLayerSP node, KoShape *shape);
~TestStrokeStrategy() = default;
void doStrokeCallback(KisStrokeJobData * data) override
{
const QRectF oldDirtyRect = m_shape->boundingRect();
QPointF delta;
m_shape->setAbsolutePosition(m_shape->absolutePosition(KoFlake::Center), KoFlake::Center);
m_shape->updateAbsolute(oldDirtyRect | oldDirtyRect.translated(delta));
}
void finishStrokeCallback() override { qDebug() << "finish stroke callback"; }
KoShape *m_shape;
KisShapeLayerSP m_affectedNode;
KisShapeLayerSP m_originalState;
};
TestStrokeStrategy::TestStrokeStrategy(KisShapeLayerSP node, KoShape *shape)
: KisRunnableBasedStrokeStrategy("TEST")
, m_shape(shape)
, m_affectedNode(node)
, m_originalState(dynamic_cast<KisShapeLayer *>(m_affectedNode->clone().data()))
{
KIS_SAFE_ASSERT_RECOVER_NOOP(m_originalState != 0);
enableJob(KisSimpleStrokeStrategy::JOB_DOSTROKE);
enableJob(KisSimpleStrokeStrategy::JOB_FINISH);
}
void KisImageNodeDeleteTest::testDeleteNodeInStroke()
{
qDebug() << "start";
QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());
qDebug() << "doc created";
const KoColorSpace *cs8 = KoColorSpaceRegistry::instance()->rgb8();
doc->newImage("", 100, 100, cs8, KoColor(), KisConfig::BackgroundStyle::RASTER_LAYER, 1, "", 96.0);
KisImageSP image = new KisImage(0, 1000, 1000, cs8, "stest");
KisShapeLayerSP vector1 = new KisShapeLayer(doc->shapeController(), image, "", OPACITY_OPAQUE_U8);
KoShape *shape = new ClonableShape;
vector1->addShape(shape);
image->addNode(vector1, image->root());
qDebug() << "start testing";
KisStrokeId stroke = image->startStroke(new TestStrokeStrategy(vector1, shape));
image->addJob(stroke, new KisStrokeJobData(KisStrokeJobData::BARRIER, KisStrokeJobData::EXCLUSIVE));
image->endStroke(stroke);
image->waitForDone();
qDebug() << "test for vector layer finished";
}
KISTEST_MAIN(KisImageNodeDeleteTest)
/*
* Copyright (c) 2019 Tusooa Zhu <tusooa@vista.aero>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_IMAGE_NODE_DELETE_TEST_H_
#define KIS_IMAGE_NODE_DELETE_TEST_H_
#include <QtTest>
class KisImageNodeDeleteTest: public QObject
{
Q_OBJECT
private Q_SLOTS:
void testDeleteNodeInStroke();
};
#endif
......@@ -125,13 +125,6 @@ void KisNodeReplaceBasedStrokeStrategy::finishStrokeCallback()
KUndo2CommandSP cmd(new Private::NodeReplaceCommand(m_d->affectedNode, m_d->originalState, name()));
m_d->postExecUndoAdapter->addCommand(cmd);
} else {
/// HACK alert: we have to delete the node in the gui thread
KisNode *node = m_d->originalState.data();
node->ref();
m_d->originalState.clear();
node->deref();
node->deleteLater();
}
}
......
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