Commit 56b98b76 authored by Tusooa Zhu's avatar Tusooa Zhu 🔼

Create undo command for editing assistants

Adding/removing/editing assistants will now trigger clones of the
assistant list. The undo commands will replace the current
assistant list with the saved ones for undo/redo.
parent c2227e69
......@@ -56,6 +56,7 @@ KisPaintingAssistantHandle::KisPaintingAssistantHandle(const KisPaintingAssistan
, KisShared()
, d(new Private)
{
dbgUI << "KisPaintingAssistantHandle ctor";
}
KisPaintingAssistantHandle& KisPaintingAssistantHandle::operator=(const QPointF & pt)
......@@ -120,6 +121,7 @@ void KisPaintingAssistantHandle::uncache()
}
struct KisPaintingAssistant::Private {
Private() = default;
explicit Private(const Private &rhs);
KisPaintingAssistantHandleSP reuseOrCreateHandle(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap, KisPaintingAssistantHandleSP origHandle, KisPaintingAssistant *q);
QString id;
......@@ -166,13 +168,22 @@ KisPaintingAssistant::Private::Private(const Private &rhs)
KisPaintingAssistantHandleSP KisPaintingAssistant::Private::reuseOrCreateHandle(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap, KisPaintingAssistantHandleSP origHandle, KisPaintingAssistant *q)
{
KisPaintingAssistantHandleSP mappedHandle = handleMap.value();
KisPaintingAssistantHandleSP mappedHandle = handleMap.value(origHandle);
if (!mappedHandle) {
mappedHandle = KisPaintingAssistantHandleSP(new KisPaintingAssistantHandle(origHandle));
mappedHandle->setType(origHandle->handleType());
handleMap.insert(origHandle, mappedHandle);
if (origHandle) {
dbgUI << "handle not found in the map, creating a new one...";
mappedHandle = KisPaintingAssistantHandleSP(new KisPaintingAssistantHandle(*origHandle));
dbgUI << "done";
mappedHandle->setType(origHandle->handleType());
handleMap.insert(origHandle, mappedHandle);
} else {
dbgUI << "orig handle is null, not doing anything";
mappedHandle = KisPaintingAssistantHandleSP();
}
}
if (mappedHandle) {
mappedHandle->registerAssistant(q);
}
mappedHandle.registerAssistant(q);
return mappedHandle;
}
......@@ -214,9 +225,10 @@ KisPaintingAssistant::KisPaintingAssistant(const QString& id, const QString& nam
d->outlineVisible = true;
}
KisPaintingAssistant::KisPaintingAssistant(const KisPaintingAssistant &rhs, QMap<KisPaintingAssistantHandleMap, KisPaintingAssistantHandleSP> &handleMap)
: d(new Private(rhs.d))
KisPaintingAssistant::KisPaintingAssistant(const KisPaintingAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap)
: d(new Private(*(rhs.d)))
{
dbgUI << "creating handles...";
Q_FOREACH (const KisPaintingAssistantHandleSP origHandle, rhs.d->handles) {
d->handles << d->reuseOrCreateHandle(handleMap, origHandle, this);
}
......@@ -233,11 +245,7 @@ KisPaintingAssistant::KisPaintingAssistant(const KisPaintingAssistant &rhs, QMap
_REUSE_H(rightMiddle);
_REUSE_H(leftMiddle);
#undef _REUSE_H
}
KisPaintingAssistantSP KisPaintingAssistant::clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap)
{
return KisPaintingAssistantSP(new KisPaintingAssistant(*this, handleMap));
dbgUI << "done";
}
bool KisPaintingAssistant::isSnappingActive() const
......
......@@ -97,7 +97,7 @@ class KRITAUI_EXPORT KisPaintingAssistant
public:
KisPaintingAssistant(const QString& id, const QString& name);
virtual ~KisPaintingAssistant();
virtual KisPaintingAssistantSP clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
virtual KisPaintingAssistantSP clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap) const = 0;
const QString& id() const;
const QString& name() const;
bool isSnappingActive() const;
......@@ -192,7 +192,7 @@ public:
static double norm2(const QPointF& p);
protected:
explicit KisPaintingAssistant(const KisPaintingAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantSP> &handleMap);
explicit KisPaintingAssistant(const KisPaintingAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
virtual QRect boundingRect() const;
......
/*
* Copyright (c) 2008 Cyrille Berger <cberger@cberger.net>
* Copyright (c) 2010 Geoffry Song <goffrie@gmail.com>
* Copyright (c) 2017 Scott Petrovic <scottpetrovic@gmail.com>
* 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 "AddRemoveAssistantCommand.h"
#include <kis_canvas2.h>
#include <kis_abstract_perspective_grid.h>
#include <KisViewManager.h>
#include <kis_canvas_resource_provider.h>
#include <kis_painting_assistants_decoration.h>
AddRemoveAssistantCommand::AddRemoveAssistantCommand(Type type, QPointer<KisCanvas2> canvas, KisPaintingAssistantSP assistant, KUndo2Command *parent)
: KUndo2Command((type == ADD ? kundo2_i18n("Add Assistant") : kundo2_i18n("Remove Assistant")), parent)
, m_type(type)
, m_canvas(canvas.data())
, m_assistant(assistant)
{
}
AddRemoveAssistantCommand::~AddRemoveAssistantCommand()
{
}
void AddRemoveAssistantCommand::undo()
{
if (m_type == ADD) {
removeAssistant();
} else {
addAssistant();
}
}
void AddRemoveAssistantCommand::redo()
{
if (m_type == ADD) {
addAssistant();
} else {
removeAssistant();
}
}
void AddRemoveAssistantCommand::addAssistant()
{
m_canvas->paintingAssistantsDecoration()->addAssistant(m_assistant);
KisAbstractPerspectiveGrid* grid = dynamic_cast<KisAbstractPerspectiveGrid*>(m_assistant.data());
if (grid) {
m_canvas->viewManager()->canvasResourceProvider()->addPerspectiveGrid(grid);
}
}
void AddRemoveAssistantCommand::removeAssistant()
{
KisAbstractPerspectiveGrid* grid = dynamic_cast<KisAbstractPerspectiveGrid*>(m_assistant.data());
if (grid) {
m_canvas->viewManager()->canvasResourceProvider()->removePerspectiveGrid(grid);
}
m_canvas->paintingAssistantsDecoration()->removeAssistant(m_assistant);
}
......@@ -12,7 +12,7 @@ set(kritaassistanttool_SOURCES
RulerAssistant.cc
SplineAssistant.cc
VanishingPointAssistant.cc
AddRemoveAssistantCommand.cpp
EditAssistantsCommand.cpp
)
ki18n_wrap_ui(kritaassistanttool_SOURCES AssistantsToolOptions.ui )
......
......@@ -29,7 +29,7 @@ class ConcentricEllipseAssistant : public KisPaintingAssistant
{
public:
ConcentricEllipseAssistant();
KisPaintingAssistantSP clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap) override;
KisPaintingAssistantSP clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap) const override;
QPointF adjustPosition(const QPointF& point, const QPointF& strokeBegin) override;
QPointF buttonPosition() const override;
int numHandles() const override { return 3; }
......
/*
* 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 "EditAssistantsCommand.h"
#include <QListIterator>
#include <kis_canvas2.h>
#include <KisView.h>
#include <KisDocument.h>
#include <KisViewManager.h>
#include <kis_canvas_resource_provider.h>
#include <kis_painting_assistants_decoration.h>
EditAssistantsCommand::EditAssistantsCommand(QPointer<KisCanvas2> canvas, AssistantSPList origAssistants, AssistantSPList newAssistants, KUndo2Command *parent)
: KUndo2Command(kundo2_i18n("Edit Assistants"), parent)
, m_canvas(canvas)
, m_origAssistants(origAssistants)
, m_newAssistants(newAssistants)
, m_index(-1)
, m_firstRedo(true)
, m_type(EDIT)
{
}
EditAssistantsCommand::EditAssistantsCommand(QPointer<KisCanvas2> canvas, AssistantSPList origAssistants, AssistantSPList newAssistants, Type type, int index, KUndo2Command *parent)
: KUndo2Command((type == ADD ? kundo2_i18n("Add Assistant") : kundo2_i18n("Remove Assistant")), parent)
, m_canvas(canvas)
, m_origAssistants(origAssistants)
, m_newAssistants(newAssistants)
, m_index(index)
, m_firstRedo(true)
, m_type(type)
{
KIS_ASSERT_RECOVER_RETURN(type != EDIT);
}
void EditAssistantsCommand::replaceWith(AssistantSPList assistants, Type type)
{
AssistantSPList curAssistants = m_canvas->paintingAssistantsDecoration()->assistants();
if (type == EDIT) {
KIS_ASSERT_RECOVER_RETURN(curAssistants.size() == assistants.size());
} else if (type == ADD) {
KIS_ASSERT_RECOVER_RETURN(curAssistants.size() == assistants.size() - 1);
} else { // type == REMOVE
KIS_ASSERT_RECOVER_RETURN(curAssistants.size() == assistants.size() + 1);
}
// when undo/redoing,
// keep locations, don't touch the current display configuration
int i = 0;
for (QListIterator<KisPaintingAssistantSP> cur(curAssistants), dest(assistants); cur.hasNext() && dest.hasNext(); ++i) {
KisPaintingAssistantSP current = cur.next(), target = dest.next();
if (i == m_index) {
if (type == ADD) { // we will add an assistant to the canvas now
target = dest.next(); // pass this one as it is not in `cur'
} else {
current = cur.next();
}
}
KIS_ASSERT_RECOVER_RETURN(current->id() == target->id());
target->setAssistantCustomColor(current->assistantCustomColor());
target->setUseCustomColor(current->useCustomColor());
target->setSnappingActive(current->isSnappingActive());
target->uncache();
}
Q_FOREACH (KisPaintingAssistantSP assistant, curAssistants) {
KisAbstractPerspectiveGrid* grid = dynamic_cast<KisAbstractPerspectiveGrid*>(assistant.data());
if (grid) {
m_canvas->viewManager()->canvasResourceProvider()->removePerspectiveGrid(grid);
}
}
m_canvas->imageView()->document()->setAssistants(assistants);
Q_FOREACH (KisPaintingAssistantSP assistant, assistants) {
KisAbstractPerspectiveGrid* grid = dynamic_cast<KisAbstractPerspectiveGrid*>(assistant.data());
if (grid) {
m_canvas->viewManager()->canvasResourceProvider()->addPerspectiveGrid(grid);
}
}
m_canvas->updateCanvas();
}
void EditAssistantsCommand::undo()
{
replaceWith(m_origAssistants, Type(-m_type));
}
void EditAssistantsCommand::redo()
{
// this is a post-execution command
if (m_firstRedo) {
m_firstRedo = false;
return;
}
replaceWith(m_newAssistants, m_type);
}
......@@ -16,38 +16,33 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef ADD_REMOVE_ASSISTANT_COMMAND_H_
#define ADD_REMOVE_ASSISTANT_COMMAND_H_
#include <QPointer>
#include <kundo2command.h>
#include <kis_painting_assistant.h>
#include <kis_types.h>
#include <QPointer>
class KisCanvas2;
class AddRemoveAssistantCommand : public KUndo2Command
class EditAssistantsCommand : public KUndo2Command
{
using AssistantSPList = QList<KisPaintingAssistantSP>;
public:
enum Type {
ADD,
REMOVE
ADD = -1,
REMOVE = 1,
EDIT = 0
};
AddRemoveAssistantCommand(Type type, QPointer<KisCanvas2> canvas, KisPaintingAssistantSP assistant, KUndo2Command *parent = 0);
~AddRemoveAssistantCommand() override;
EditAssistantsCommand(QPointer<KisCanvas2> canvas, AssistantSPList origAssistants, AssistantSPList newAssistants, KUndo2Command *parent = 0);
EditAssistantsCommand(QPointer<KisCanvas2> canvas, AssistantSPList origAssistants, AssistantSPList newAssistants, Type type, int index, KUndo2Command *parent = 0);
void undo() override;
void redo() override;
private:
void addAssistant();
void removeAssistant();
Type m_type;
void replaceWith(AssistantSPList assistants, Type type = EDIT);
QPointer<KisCanvas2> m_canvas;
KisPaintingAssistantSP m_assistant;
AssistantSPList m_origAssistants, m_newAssistants;
int m_index;
bool m_firstRedo;
Type m_type;
};
#endif
......@@ -35,7 +35,7 @@ EllipseAssistant::EllipseAssistant()
{
}
EllipseAssistant::EllipseAssistant(const EllipseAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandlebSP> &handleMap)
EllipseAssistant::EllipseAssistant(const EllipseAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap)
: KisPaintingAssistant(rhs, handleMap)
, e(rhs.e)
{
......
......@@ -40,7 +40,7 @@ protected:
void drawCache(QPainter& gc, const KisCoordinatesConverter *converter, bool assistantVisible=true) override;
private:
QPointF project(const QPointF& pt) const;
explicit EllipseAssistant(const EllipseAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandlebSP> &handleMap);
explicit EllipseAssistant(const EllipseAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
mutable Ellipse e;
};
......
......@@ -39,7 +39,7 @@ FisheyePointAssistant::FisheyePointAssistant()
{
}
FisheyePointAssistant::FisheyePointAssistant(const FisheyePointAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandlebSP> &handleMap)
FisheyePointAssistant::FisheyePointAssistant(const FisheyePointAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap)
: KisPaintingAssistant(rhs, handleMap)
, e(rhs.e)
, extraE(rhs.extraE)
......
......@@ -47,7 +47,7 @@ protected:
void drawCache(QPainter& gc, const KisCoordinatesConverter *converter, bool assistantVisible=true) override;
private:
QPointF project(const QPointF& pt, const QPointF& strokeBegin);
explicit FisheyePointAssistant(const FisheyePointAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandlebSP> &handleMap);
explicit FisheyePointAssistant(const FisheyePointAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
mutable Ellipse e;
mutable Ellipse extraE;
};
......
......@@ -43,7 +43,7 @@ KisPaintingAssistantSP ParallelRulerAssistant::clone(QMap<KisPaintingAssistantHa
return KisPaintingAssistantSP(new ParallelRulerAssistant(*this, handleMap));
}
ParallelRulerAssistant::ParallelRulerAssistant(const ParallelRulerAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandlebSP> &handleMap)
ParallelRulerAssistant::ParallelRulerAssistant(const ParallelRulerAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap)
: KisPaintingAssistant(rhs, handleMap)
{
}
......
......@@ -46,7 +46,7 @@ protected:
void drawCache(QPainter& gc, const KisCoordinatesConverter *converter, bool assistantVisible=true) override;
private:
QPointF project(const QPointF& pt, const QPointF& strokeBegin);
explicit ParallelRulerAssistant(const ParallelRulerAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandlebSP> &handleMap);
explicit ParallelRulerAssistant(const ParallelRulerAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
};
class ParallelRulerAssistantFactory : public KisPaintingAssistantFactory
......
......@@ -39,7 +39,7 @@ PerspectiveAssistant::PerspectiveAssistant(QObject *parent)
{
}
PerspectiveAssistant::PerspectiveAssistant(const PerspectiveAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandlebSP> &handleMap)
PerspectiveAssistant::PerspectiveAssistant(const PerspectiveAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap)
: KisAbstractPerspectiveGrid(rhs.parent())
, KisPaintingAssistant(rhs, handleMap)
, m_snapLine(rhs.m_snapLine)
......
......@@ -53,7 +53,7 @@ private:
bool quad(QPolygonF& out) const;
// finds the transform from perspective coordinates (a unit square) to the document
bool getTransform(QPolygonF& polyOut, QTransform& transformOut) const;
explicit PerspectiveAssistant(const PerspectiveAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandlebSP> &handleMap);
explicit PerspectiveAssistant(const PerspectiveAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
// which direction to snap to (in transformed coordinates)
QLineF m_snapLine;
......
......@@ -38,10 +38,10 @@ VanishingPointAssistant::VanishingPointAssistant()
{
}
VanishingPointAssistant::VanishingPointAssistant(const VanishingPointAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandlebSP> &handleMap)
VanishingPointAssistant::VanishingPointAssistant(const VanishingPointAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap)
: KisPaintingAssistant(rhs, handleMap)
, m_canvas(rhs.m_canvas)
, m_referenceLineDensity(rhs.referenceLineDensity)
, m_referenceLineDensity(rhs.m_referenceLineDensity)
{
}
......
......@@ -64,7 +64,7 @@ protected:
void drawCache(QPainter& gc, const KisCoordinatesConverter *converter, bool assistantVisible=true) override;
private:
QPointF project(const QPointF& pt, const QPointF& strokeBegin);
explicit VanishingPointAssistant(const VanishingPointAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandlebSP> &handleMap);
explicit VanishingPointAssistant(const VanishingPointAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
KisCanvas2 *m_canvas;
float m_referenceLineDensity = 15.0;
......
......@@ -48,7 +48,7 @@
#include <kis_painting_assistants_decoration.h>
#include "kis_global.h"
#include "VanishingPointAssistant.h"
#include "AddRemoveAssistantCommand.h"
#include "EditAssistantsCommand.h"
#include <kis_undo_adapter.h>
#include <math.h>
......@@ -100,6 +100,8 @@ void KisAssistantTool::deactivate()
void KisAssistantTool::beginPrimaryAction(KoPointerEvent *event)
{
setMode(KisTool::PAINT_MODE);
m_origAssistantList = cloneAssistantList(m_canvas->paintingAssistantsDecoration()->assistants());
bool newAssistantAllowed = true;
KisPaintingAssistantsDecorationSP canvasDecoration = m_canvas->paintingAssistantsDecoration();
......@@ -510,16 +512,21 @@ void KisAssistantTool::endPrimaryAction(KoPointerEvent *event)
{
setMode(KisTool::HOVER_MODE);
if (m_handleDrag) {
if (!(event->modifiers() & Qt::ShiftModifier) && m_handleCombine) {
m_handleCombine->mergeWith(m_handleDrag);
m_handleCombine->uncache();
m_handles = m_canvas->paintingAssistantsDecoration()->handles();
if (m_handleDrag || m_assistantDrag) {
if (m_handleDrag) {
if (!(event->modifiers() & Qt::ShiftModifier) && m_handleCombine) {
m_handleCombine->mergeWith(m_handleDrag);
m_handleCombine->uncache();
m_handles = m_canvas->paintingAssistantsDecoration()->handles();
}
m_handleDrag = m_handleCombine = 0;
} else {
m_assistantDrag.clear();
}
m_handleDrag = m_handleCombine = 0;
} else if (m_assistantDrag) {
m_assistantDrag.clear();
dbgUI << "creating undo command...";
KUndo2Command *command = new EditAssistantsCommand(m_canvas, m_origAssistantList, cloneAssistantList(m_canvas->paintingAssistantsDecoration()->assistants()));
m_canvas->viewManager()->undoAdapter()->addCommand(command);
dbgUI << "done";
} else if(m_internalMode == MODE_DRAGGING_TRANSLATING_TWONODES) {
addAssistant();
m_internalMode = MODE_CREATION;
......@@ -531,19 +538,29 @@ void KisAssistantTool::endPrimaryAction(KoPointerEvent *event)
m_canvas->updateCanvas(); // TODO update only the relevant part of the canvas
}
QList<KisPaintingAssistantSP> cloneAssistantList(const QList<KisPaintingAssistantSP> &list) const
QList<KisPaintingAssistantSP> KisAssistantTool::cloneAssistantList(const QList<KisPaintingAssistantSP> &list) const
{
QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> handleMap;
QList<KisPaintingAssistantSP> clonedList;
dbgUI << "cloning assistants...";
for (auto i = list.begin(); i != list.end(); ++i) {
clonedList << i->clone(handleMap);
clonedList << (*i)->clone(handleMap);
}
dbgUI << "done";
return clonedList;
}
void KisAssistantTool::addAssistant()
{
KUndo2Command *addAssistantCmd = new AddRemoveAssistantCommand(AddRemoveAssistantCommand::ADD, m_canvas, m_newAssistant);
m_canvas->paintingAssistantsDecoration()->addAssistant(m_newAssistant);
KisAbstractPerspectiveGrid* grid = dynamic_cast<KisAbstractPerspectiveGrid*>(m_newAssistant.data());
if (grid) {
m_canvas->viewManager()->canvasResourceProvider()->addPerspectiveGrid(grid);
}
QList<KisPaintingAssistantSP> assistants = m_canvas->paintingAssistantsDecoration()->assistants();
KUndo2Command *addAssistantCmd = new EditAssistantsCommand(m_canvas, m_origAssistantList, cloneAssistantList(assistants), EditAssistantsCommand::ADD, assistants.indexOf(m_newAssistant));
m_canvas->viewManager()->undoAdapter()->addCommand(addAssistantCmd);
m_handles = m_canvas->paintingAssistantsDecoration()->handles();
......@@ -555,7 +572,15 @@ void KisAssistantTool::addAssistant()
void KisAssistantTool::removeAssistant(KisPaintingAssistantSP assistant)
{
KUndo2Command *removeAssistantCmd = new AddRemoveAssistantCommand(AddRemoveAssistantCommand::REMOVE, m_canvas, assistant);
QList<KisPaintingAssistantSP> assistants = m_canvas->paintingAssistantsDecoration()->assistants();
KisAbstractPerspectiveGrid* grid = dynamic_cast<KisAbstractPerspectiveGrid*>(assistant.data());
if (grid) {
m_canvas->viewManager()->canvasResourceProvider()->removePerspectiveGrid(grid);
}
m_canvas->paintingAssistantsDecoration()->removeAssistant(assistant);
KUndo2Command *removeAssistantCmd = new EditAssistantsCommand(m_canvas, m_origAssistantList, cloneAssistantList(m_canvas->paintingAssistantsDecoration()->assistants()), EditAssistantsCommand::REMOVE, assistants.indexOf(assistant));
m_canvas->viewManager()->undoAdapter()->addCommand(removeAssistantCmd);
m_handles = m_canvas->paintingAssistantsDecoration()->handles();
......
......@@ -151,6 +151,7 @@ private:
PerspectiveAssistantEditionMode m_internalMode;
KisPaintingAssistantHandleSP m_selectedNode1, m_selectedNode2, m_higlightedNode;
int m_assistantHelperYOffset; // used by the assistant editor icons for placement on the canvas.
QList<KisPaintingAssistantSP> m_origAssistantList;
};
......
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