From 12cbc8b56669d3411b4212b09a3e7a2e5581f8a6 Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 14 Jun 2014 09:37:25 +0300 Subject: [PATCH] New undo command DelTool. --HG-- branch : feature --- src/app/tools/vabstracttool.cpp | 59 ++++++--------------- src/app/undocommands/deltool.cpp | 75 +++++++++++++++++++++++++++ src/app/undocommands/deltool.h | 56 ++++++++++++++++++++ src/app/undocommands/undocommands.h | 3 +- src/app/undocommands/undocommands.pri | 6 ++- 5 files changed, 152 insertions(+), 47 deletions(-) create mode 100644 src/app/undocommands/deltool.cpp create mode 100644 src/app/undocommands/deltool.h diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index a206fe89e..2717fa812 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -29,6 +29,9 @@ #include "vabstracttool.h" #include "../xml/vpattern.h" #include +#include +#include "../undocommands/deltool.h" +#include "../widgets/vapplication.h" const QString VAbstractTool::AttrType = QStringLiteral("type"); const QString VAbstractTool::AttrMx = QStringLiteral("mx"); @@ -241,52 +244,20 @@ QPointF VAbstractTool::addVector(const QPointF &p, const QPointF &p1, const QPoi */ void VAbstractTool::DeleteTool(QGraphicsItem *tool) { - if (_referens <= 1) + QMessageBox msgBox; + msgBox.setText(tr("Confirm the deletion.")); + msgBox.setInformativeText(tr("Do you really want delete?")); + msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.setIcon(QMessageBox::Question); + if (msgBox.exec() == QMessageBox::Cancel) { - QMessageBox msgBox; - msgBox.setText(tr("Confirm the deletion.")); - msgBox.setInformativeText(tr("Do you really want delete?")); - msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setIcon(QMessageBox::Question); - if (msgBox.exec() == QMessageBox::Cancel) - { - return; - } - //remove from xml file - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - QDomNode element = domElement.parentNode(); - if (element.isNull() == false) - { - if (element.isElement()) - { - RemoveReferens();//deincrement referens - element.removeChild(domElement);//remove form file - QGraphicsScene *scene = tool->scene(); - if (scene != 0)//some tools haven't scene - { - scene->removeItem(tool);//remove form scene - } - doc->LiteParseTree(); - emit toolhaveChange();//set enabled save button - } - else - { - qDebug()<<"parent isn't element"<elementById(QString().setNum(id)); + if (domElement.isElement()) + { + xml = domElement.cloneNode().toElement(); + parentNode = domElement.parentNode(); + previousNode = domElement.previousSibling(); + } + else + { + qDebug()<<"Can't get tool by id = "<elementById(QString().setNum(toolId)); + if (domElement.isElement()) + { + parentNode.removeChild(domElement); + emit NeedFullParsing(); + } + else + { + qDebug()<<"Can't get tool by id = "< + ** @date 13 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 DELTOOL_H +#define DELTOOL_H + +#include +#include + +class VPattern; + +class DelTool : public QObject, public QUndoCommand +{ + Q_OBJECT +public: + DelTool(VPattern *doc, quint32 id, QUndoCommand *parent = 0); + virtual ~DelTool(); + virtual void undo(); + virtual void redo(); +signals: + void NeedFullParsing(); +private: + Q_DISABLE_COPY(DelTool) + QDomElement xml; + QDomNode parentNode; + QDomNode previousNode; + VPattern *doc; + quint32 toolId; +}; + +#endif // DELTOOL_H diff --git a/src/app/undocommands/undocommands.h b/src/app/undocommands/undocommands.h index 5c3b8310b..79dedd9f5 100644 --- a/src/app/undocommands/undocommands.h +++ b/src/app/undocommands/undocommands.h @@ -36,7 +36,8 @@ enum class UndoCommand: char { AddPatternPiece, MoveSPoint, SaveToolOptions, SaveDetailOptions, - MoveDetail + MoveDetail, + DeleteTool }; #endif // UNDOCOMMANDS_H diff --git a/src/app/undocommands/undocommands.pri b/src/app/undocommands/undocommands.pri index c3c0f7a34..fd2c46986 100644 --- a/src/app/undocommands/undocommands.pri +++ b/src/app/undocommands/undocommands.pri @@ -7,7 +7,8 @@ HEADERS += \ undocommands/savetooloptions.h \ undocommands/undocommands.h \ undocommands/savedetailoptions.h \ - undocommands/movedetail.h + undocommands/movedetail.h \ + undocommands/deltool.h SOURCES += \ @@ -18,5 +19,6 @@ SOURCES += \ undocommands/movesplinepath.cpp \ undocommands/savetooloptions.cpp \ undocommands/savedetailoptions.cpp \ - undocommands/movedetail.cpp + undocommands/movedetail.cpp \ + undocommands/deltool.cpp