diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index acd5eeb26..59d09a375 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -31,6 +31,7 @@ #include "../../../undocommands/label/operationshowlabel.h" #include "../../../undocommands/savetooloptions.h" #include "../../../undocommands/undogroup.h" +#include "../../../undocommands/deltool.h" #include "../vgeometry/vpointf.h" const QString VAbstractOperation::TagItem = QStringLiteral("item"); @@ -619,6 +620,34 @@ void VAbstractOperation::ApplyToolOptions(const QList &oldDependencies, } } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::PerformDelete() +{ + vidtype group = doc->GroupLinkedToTool(m_id); + bool deleteGroup = group != null_id; + + qCDebug(vTool, "Begin deleting."); + if (deleteGroup) + { + qApp->getUndoStack()->beginMacro(tr("delete operation")); + + qCDebug(vTool, "Deleting the linked group."); + DelGroup *delGroup = new DelGroup(doc, group); + connect(delGroup, &DelGroup::UpdateGroups, doc, &VAbstractPattern::UpdateVisiblityGroups); + qApp->getUndoStack()->push(delGroup); + } + + qCDebug(vTool, "Deleting the tool."); + DelTool *delTool = new DelTool(doc, m_id); + connect(delTool, &DelTool::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); + qApp->getUndoStack()->push(delTool); + + if (deleteGroup) + { + qApp->getUndoStack()->endMacro(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractOperation::UpdateNamePosition(quint32 id, const QPointF &pos) { diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h index 83ea6e69b..6d452f181 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -143,6 +143,7 @@ protected: virtual void ChangeLabelVisibility(quint32 id, bool visible) override; virtual void ApplyToolOptions(const QList &oldDependencies, const QList &newDependencies, const QDomElement &oldDomElement, const QDomElement &newDomElement) override; + virtual void PerformDelete() override; void UpdateNamePosition(quint32 id, const QPointF &pos); void SaveSourceDestination(QDomElement &tag); diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 17b459939..0488f935a 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -224,10 +224,7 @@ void VAbstractTool::DeleteToolWithConfirm(bool ask) } } - qCDebug(vTool, "Begin deleting."); - DelTool *delTool = new DelTool(doc, m_id); - connect(delTool, &DelTool::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); - qApp->getUndoStack()->push(delTool); + PerformDelete(); // Throw exception, this will help prevent case when we forget to immediately quit function. VExceptionToolWasDeleted e("Tool was used after deleting."); @@ -239,6 +236,15 @@ void VAbstractTool::DeleteToolWithConfirm(bool ask) } } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractTool::PerformDelete() +{ + qCDebug(vTool, "Begin deleting."); + DelTool *delTool = new DelTool(doc, m_id); + connect(delTool, &DelTool::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); + qApp->getUndoStack()->push(delTool); +} + //--------------------------------------------------------------------------------------------------------------------- int VAbstractTool::ConfirmDeletion() { diff --git a/src/libs/vtools/tools/vabstracttool.h b/src/libs/vtools/tools/vabstracttool.h index 00f467654..80d6135b2 100644 --- a/src/libs/vtools/tools/vabstracttool.h +++ b/src/libs/vtools/tools/vabstracttool.h @@ -159,6 +159,7 @@ protected: */ virtual void RemoveReferens() {} virtual void DeleteToolWithConfirm(bool ask = true); + virtual void PerformDelete(); static int ConfirmDeletion(); template