diff --git a/src/app/tools/drawTools/vabstractspline.cpp b/src/app/tools/drawTools/vabstractspline.cpp index b1705a21a..a9b983c70 100644 --- a/src/app/tools/drawTools/vabstractspline.cpp +++ b/src/app/tools/drawTools/vabstractspline.cpp @@ -154,7 +154,7 @@ void VAbstractSpline::keyReleaseEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Delete: - DeleteTool(this); + DeleteTool(); break; default: break; diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index 958a9225f..d138e71ce 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -134,7 +134,7 @@ protected: { if (selectedAction == actionRemove) { - DeleteTool(tool); + DeleteTool(); } } } diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 6612affdd..e7d85ee78 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -349,7 +349,7 @@ void VToolArc::keyReleaseEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Delete: - DeleteTool(this); + DeleteTool(); break; default: break; diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index b210a8458..3ecc506cd 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -315,7 +315,7 @@ void VToolLine::keyReleaseEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Delete: - DeleteTool(this); + DeleteTool(); break; default: break; diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index c6d7b0697..e2350396e 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -279,7 +279,7 @@ void VToolPoint::keyReleaseEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Delete: - DeleteTool(this); + DeleteTool(); break; default: break; diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 6e494063b..db965984f 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -31,6 +31,7 @@ #include "../../widgets/vgraphicssimpletextitem.h" #include "../../undocommands/movespoint.h" #include "../../undocommands/addpatternpiece.h" +#include "../../undocommands/deletepatternpiece.h" #include "../../geometry/vpointf.h" const QString VToolSinglePoint::ToolType = QStringLiteral("single"); @@ -181,6 +182,15 @@ void VToolSinglePoint::decrementReferens() } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::DeleteTool() +{ + DeletePatternPiece *deletePP = new DeletePatternPiece(doc, namePP); + connect(deletePP, &DeletePatternPiece::ClearScene, doc, &VPattern::ClearScene); + connect(deletePP, &DeletePatternPiece::NeedFullParsing, doc, &VPattern::NeedFullParsing); + qApp->getUndoStack()->push(deletePP); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -215,7 +225,7 @@ void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color) */ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) { - ContextMenu(this, event, false); + ContextMenu(this, event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index 5766f5adc..99fdfaead 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -64,7 +64,7 @@ protected: * @brief DeleteTool delete tool from file and scene. This tool can't be deleted by now. * @param tool tool what me delete. */ - virtual void DeleteTool(QGraphicsItem *tool){Q_UNUSED(tool)} + virtual void DeleteTool(); virtual void SaveDialog(QDomElement &domElement); private: QString namePP; diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index 2717fa812..81951fde2 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -242,7 +242,7 @@ QPointF VAbstractTool::addVector(const QPointF &p, const QPointF &p1, const QPoi * @brief DeleteTool full delete object form scene and file. * @param tool tool */ -void VAbstractTool::DeleteTool(QGraphicsItem *tool) +void VAbstractTool::DeleteTool() { QMessageBox msgBox; msgBox.setText(tr("Confirm the deletion.")); diff --git a/src/app/tools/vabstracttool.h b/src/app/tools/vabstracttool.h index 40750b2d2..29d2bbf47 100644 --- a/src/app/tools/vabstracttool.h +++ b/src/app/tools/vabstracttool.h @@ -145,7 +145,7 @@ protected: * @brief RemoveReferens decrement value of reference. */ virtual void RemoveReferens(){} - virtual void DeleteTool(QGraphicsItem *tool); + virtual void DeleteTool(); Qt::PenStyle LineStyle(); private: Q_DISABLE_COPY(VAbstractTool) diff --git a/src/app/tools/vtooldetail.cpp b/src/app/tools/vtooldetail.cpp index 8fed40c9e..4e75fc3ea 100644 --- a/src/app/tools/vtooldetail.cpp +++ b/src/app/tools/vtooldetail.cpp @@ -266,7 +266,7 @@ void VToolDetail::Create(const quint32 &_id, const VDetail &newDetail, VMainGrap */ void VToolDetail::Remove() { - DeleteTool(this); + DeleteTool(); } //--------------------------------------------------------------------------------------------------------------------- @@ -399,7 +399,7 @@ void VToolDetail::keyReleaseEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Delete: - DeleteTool(this); + DeleteTool(); break; default: break; @@ -453,7 +453,7 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } if (selectedAction == actionRemove) { - DeleteTool(this); + DeleteTool(); } } diff --git a/src/app/undocommands/addpatternpiece.cpp b/src/app/undocommands/addpatternpiece.cpp index 76b87d584..8c1d41bd8 100644 --- a/src/app/undocommands/addpatternpiece.cpp +++ b/src/app/undocommands/addpatternpiece.cpp @@ -29,8 +29,6 @@ #include "addpatternpiece.h" #include "../xml/vpattern.h" -int AddPatternPiece::countPP = 0; - //--------------------------------------------------------------------------------------------------------------------- AddPatternPiece::AddPatternPiece(const QDomElement &xml, VPattern *doc, const QString &namePP, const QString &mPath, QUndoCommand *parent) @@ -46,7 +44,7 @@ AddPatternPiece::~AddPatternPiece() //--------------------------------------------------------------------------------------------------------------------- void AddPatternPiece::undo() { - if (countPP <= 1) + if (CountPP() <= 1) { emit ClearScene(); } @@ -57,14 +55,12 @@ void AddPatternPiece::undo() rootElement.removeChild(patternPiece); emit NeedFullParsing(); } - --countPP; } //--------------------------------------------------------------------------------------------------------------------- void AddPatternPiece::redo() { - ++countPP; - if (countPP == 1 && mPath.isEmpty() == false) + if (CountPP() == 0 && mPath.isEmpty() == false) { doc->CreateEmptyFile(mPath); } @@ -72,7 +68,6 @@ void AddPatternPiece::redo() QDomElement rootElement = doc->documentElement(); rootElement.appendChild(xml); - doc->haveLiteChange(); if (redoFlag) { @@ -80,3 +75,16 @@ void AddPatternPiece::redo() } redoFlag = true; } + +//--------------------------------------------------------------------------------------------------------------------- +int AddPatternPiece::CountPP() +{ + QDomElement rootElement = doc->documentElement(); + if (rootElement.isNull()) + { + return 0; + } + + const QDomNodeList elements = rootElement.elementsByTagName( VPattern::TagDraw ); + return elements.count(); +} diff --git a/src/app/undocommands/addpatternpiece.h b/src/app/undocommands/addpatternpiece.h index 24f240239..8267cb64e 100644 --- a/src/app/undocommands/addpatternpiece.h +++ b/src/app/undocommands/addpatternpiece.h @@ -50,10 +50,10 @@ private: Q_DISABLE_COPY(AddPatternPiece) const QDomElement xml; VPattern *doc; - static int countPP; QString namePP; bool redoFlag; QString mPath; + int CountPP(); }; #endif // ADDPATTERNPIECE_H diff --git a/src/app/undocommands/deletepatternpiece.cpp b/src/app/undocommands/deletepatternpiece.cpp new file mode 100644 index 000000000..a04508023 --- /dev/null +++ b/src/app/undocommands/deletepatternpiece.cpp @@ -0,0 +1,91 @@ +/************************************************************************ + ** + ** @file deletepatternpiece.cpp + ** @author Roman Telezhynskyi + ** @date 14 6, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina 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 Valentina. If not, see . + ** + *************************************************************************/ + +#include "deletepatternpiece.h" +#include "../xml/vpattern.h" +#include "addpatternpiece.h" + +//--------------------------------------------------------------------------------------------------------------------- +DeletePatternPiece::DeletePatternPiece(VPattern *doc, const QString &namePP, QUndoCommand *parent) + : QObject(), QUndoCommand(parent), doc(doc), namePP(namePP), patternPiece(QDomElement()), mPath(QString()), + previousNode(QDomNode()) +{ + setText(tr("Delete pattern piece %1").arg(namePP)); + + QDomElement patternP= doc->GetPPElement(namePP); + patternPiece = patternP.cloneNode().toElement(); + mPath = doc->MPath(); + previousNode = patternP.previousSibling();//find previous pattern piece +} + +//--------------------------------------------------------------------------------------------------------------------- +DeletePatternPiece::~DeletePatternPiece() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void DeletePatternPiece::undo() +{ + if (CountPP() == 0) + { + doc->CreateEmptyFile(mPath); + } + + QDomElement rootElement = doc->documentElement(); + rootElement.insertAfter(patternPiece, previousNode); + + emit NeedFullParsing(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DeletePatternPiece::redo() +{ + if (CountPP() <= 1) + { + emit ClearScene(); + } + else + { + QDomElement rootElement = doc->documentElement(); + QDomElement patternPiece = doc->GetPPElement(namePP); + rootElement.removeChild(patternPiece); + emit NeedFullParsing(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +int DeletePatternPiece::CountPP() +{ + QDomElement rootElement = doc->documentElement(); + if (rootElement.isNull()) + { + return 0; + } + + const QDomNodeList elements = rootElement.elementsByTagName( VPattern::TagDraw ); + return elements.count(); +} diff --git a/src/app/undocommands/deletepatternpiece.h b/src/app/undocommands/deletepatternpiece.h new file mode 100644 index 000000000..cc62b0183 --- /dev/null +++ b/src/app/undocommands/deletepatternpiece.h @@ -0,0 +1,58 @@ +/************************************************************************ + ** + ** @file deletepatternpiece.h + ** @author Roman Telezhynskyi + ** @date 14 6, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina 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 Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DELETEPATTERNPIECE_H +#define DELETEPATTERNPIECE_H + +#include +#include + +class VPattern; + +class DeletePatternPiece : public QObject, public QUndoCommand +{ + Q_OBJECT +public: + DeletePatternPiece(VPattern *doc, const QString &namePP, QUndoCommand *parent = 0); + virtual ~DeletePatternPiece(); + virtual void undo(); + virtual void redo(); +signals: + void ClearScene(); + void NeedFullParsing(); +private: + Q_DISABLE_COPY(DeletePatternPiece) + VPattern *doc; + QString namePP; + QDomElement patternPiece; + QString mPath; + QDomNode previousNode; + int CountPP(); +}; + +#endif // DELETEPATTERNPIECE_H diff --git a/src/app/undocommands/undocommands.h b/src/app/undocommands/undocommands.h index 79dedd9f5..ed7f7c93a 100644 --- a/src/app/undocommands/undocommands.h +++ b/src/app/undocommands/undocommands.h @@ -37,7 +37,8 @@ enum class UndoCommand: char { AddPatternPiece, SaveToolOptions, SaveDetailOptions, MoveDetail, - DeleteTool + DeleteTool, + DeletePatternPiece }; #endif // UNDOCOMMANDS_H diff --git a/src/app/undocommands/undocommands.pri b/src/app/undocommands/undocommands.pri index fd2c46986..2903b4934 100644 --- a/src/app/undocommands/undocommands.pri +++ b/src/app/undocommands/undocommands.pri @@ -8,7 +8,8 @@ HEADERS += \ undocommands/undocommands.h \ undocommands/savedetailoptions.h \ undocommands/movedetail.h \ - undocommands/deltool.h + undocommands/deltool.h \ + undocommands/deletepatternpiece.h SOURCES += \ @@ -20,5 +21,6 @@ SOURCES += \ undocommands/savetooloptions.cpp \ undocommands/savedetailoptions.cpp \ undocommands/movedetail.cpp \ - undocommands/deltool.cpp + undocommands/deltool.cpp \ + undocommands/deletepatternpiece.cpp