diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index 407deccba..ec15a3987 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -137,7 +137,7 @@ protected: } if (selectedAction == actionRemove) { - DeleteTool(tool); + DeleteTool(); } } } diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 612271189..2327502c8 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -184,9 +184,8 @@ void VToolSinglePoint::decrementReferens() } //--------------------------------------------------------------------------------------------------------------------- -void VToolSinglePoint::DeleteTool(QGraphicsItem *tool, bool ask) +void VToolSinglePoint::DeleteTool(bool ask) { - Q_UNUSED(tool) if (ask) { QMessageBox msgBox; diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index ff515fe54..78b7b0ebd 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -59,7 +59,7 @@ protected: virtual void RefreshDataInFile(); QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void decrementReferens(); - virtual void DeleteTool(QGraphicsItem *tool, bool ask = true); + virtual void DeleteTool(bool ask = true); virtual void SaveDialog(QDomElement &domElement); private: QString namePP; diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index 36445b1f1..2c5fbc37a 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -242,9 +242,8 @@ 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, bool ask) +void VAbstractTool::DeleteTool(bool ask) { - DelTool *delTool = new DelTool(doc, id, tool); if (ask) { QMessageBox msgBox; @@ -257,9 +256,9 @@ void VAbstractTool::DeleteTool(QGraphicsItem *tool, bool ask) { return; } - /*Ugly hack. If UnionDetails delete detail no need emit FullParsing */ - connect(delTool, &DelTool::NeedFullParsing, doc, &VPattern::NeedFullParsing); } + DelTool *delTool = new DelTool(doc, id); + connect(delTool, &DelTool::NeedFullParsing, doc, &VPattern::NeedFullParsing); qApp->getUndoStack()->push(delTool); } diff --git a/src/app/tools/vabstracttool.h b/src/app/tools/vabstracttool.h index 27ceac280..dda072331 100644 --- a/src/app/tools/vabstracttool.h +++ b/src/app/tools/vabstracttool.h @@ -146,7 +146,7 @@ protected: * @brief RemoveReferens decrement value of reference. */ virtual void RemoveReferens(){} - virtual void DeleteTool(QGraphicsItem *tool, bool ask = true); + virtual void DeleteTool(bool ask = true); Qt::PenStyle LineStyle(); private: Q_DISABLE_COPY(VAbstractTool) diff --git a/src/app/tools/vtooldetail.cpp b/src/app/tools/vtooldetail.cpp index 7d7b2127e..e42edb6b7 100644 --- a/src/app/tools/vtooldetail.cpp +++ b/src/app/tools/vtooldetail.cpp @@ -38,9 +38,11 @@ #include #include #include +#include #include "../undocommands/savedetailoptions.h" #include "../undocommands/movedetail.h" #include "../undocommands/adddet.h" +#include "../undocommands/deletedetail.h" const QString VToolDetail::TagName = QStringLiteral("detail"); const QString VToolDetail::TagNode = QStringLiteral("node"); @@ -273,7 +275,7 @@ void VToolDetail::Create(const quint32 &_id, const VDetail &newDetail, VMainGrap */ void VToolDetail::Remove(bool ask) { - DeleteTool(this, ask); + DeleteTool(ask); } //--------------------------------------------------------------------------------------------------------------------- @@ -552,6 +554,27 @@ void VToolDetail::RefreshGeometry() this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); } +void VToolDetail::DeleteTool(bool ask) +{ + DeleteDetail *delDet = new DeleteDetail(doc, id); + if (ask) + { + 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; + } + /*Ugly hack. If UnionDetails delete detail no need emit FullParsing */ + connect(delDet, &DeleteDetail::NeedFullParsing, doc, &VPattern::NeedFullParsing); + } + qApp->getUndoStack()->push(delDet); +} + //--------------------------------------------------------------------------------------------------------------------- template //cppcheck-suppress unusedFunction diff --git a/src/app/tools/vtooldetail.h b/src/app/tools/vtooldetail.h index 6af80a685..b29b6c969 100644 --- a/src/app/tools/vtooldetail.h +++ b/src/app/tools/vtooldetail.h @@ -109,6 +109,7 @@ private: * @param node node of detail. */ void InitTool(VMainGraphicsScene *scene, const VNodeDetail &node); + virtual void DeleteTool(bool ask = true); }; #endif // VTOOLDETAIL_H diff --git a/src/app/tools/vtooluniondetails.cpp b/src/app/tools/vtooluniondetails.cpp index f2f5dfe74..b9cd16e9c 100644 --- a/src/app/tools/vtooluniondetails.cpp +++ b/src/app/tools/vtooluniondetails.cpp @@ -467,7 +467,7 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data, * @param angle angle rotation. */ void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate, - const qreal angle) + const qreal &angle) { point->setX(point->x()+dx); point->setY(point->y()+dy); @@ -496,6 +496,7 @@ void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VP qApp->getUndoStack()->beginMacro("union details"); Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, doc, data, Document::FullParse, Source::FromGui); + qApp->getUndoStack()->endMacro(); } //--------------------------------------------------------------------------------------------------------------------- @@ -650,11 +651,6 @@ void VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDeta } } while (igetUndoStack()->endMacro(); - } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/vtooluniondetails.h b/src/app/tools/vtooluniondetails.h index 78cdbf388..bc610a0c3 100644 --- a/src/app/tools/vtooluniondetails.h +++ b/src/app/tools/vtooluniondetails.h @@ -75,7 +75,7 @@ public: quint32 &idCount, const qreal &dx = 0, const qreal &dy = 0, const quint32 &pRotate = 0, const qreal &angle = 0); static void BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate, - const qreal angle); + const qreal &angle); public slots: /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/app/undocommands/deletedetail.cpp b/src/app/undocommands/deletedetail.cpp new file mode 100644 index 000000000..f6196604a --- /dev/null +++ b/src/app/undocommands/deletedetail.cpp @@ -0,0 +1,83 @@ +/************************************************************************ + ** + ** @file deletedetail.cpp + ** @author Roman Telezhynskyi + ** @date 16 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 "deletedetail.h" +#include "../xml/vpattern.h" +#include "../tools/vtooldetail.h" + +//--------------------------------------------------------------------------------------------------------------------- +DeleteDetail::DeleteDetail(VPattern *doc, quint32 id, QUndoCommand *parent) + : QObject(), QUndoCommand(parent), xml(QDomElement()), doc(doc), detId(id), parentNode(QDomNode()) +{ + setText(tr("Delete tool")); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + xml = domElement.cloneNode().toElement(); + parentNode = domElement.parentNode(); + } + else + { + qDebug()<<"Can't get detail by id = "<elementById(QString().setNum(detId)); + if (domElement.isElement()) + { + parentNode.removeChild(domElement); + + QHash* tools = doc->getTools(); + SCASSERT(tools != nullptr); + VToolDetail *toolDet = qobject_cast(tools->value(detId)); + SCASSERT(toolDet != nullptr); + toolDet->hide(); + + emit NeedFullParsing(); + } + else + { + qDebug()<<"Can't get detail by id = "< + ** @date 16 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 DELETEDETAIL_H +#define DELETEDETAIL_H + +#include +#include + +class VPattern; +class QGraphicsItem; + +class DeleteDetail : public QObject, public QUndoCommand +{ + Q_OBJECT +public: + DeleteDetail(VPattern *doc, quint32 id, QUndoCommand *parent = 0); + virtual ~DeleteDetail(); + virtual void undo(); + virtual void redo(); +signals: + void NeedFullParsing(); +private: + Q_DISABLE_COPY(DeleteDetail) + QDomElement xml; + VPattern *doc; + quint32 detId; + QDomNode parentNode; +}; + +#endif // DELETEDETAIL_H diff --git a/src/app/undocommands/deltool.cpp b/src/app/undocommands/deltool.cpp index 4b3594717..831f70b9b 100644 --- a/src/app/undocommands/deltool.cpp +++ b/src/app/undocommands/deltool.cpp @@ -29,11 +29,12 @@ #include "deltool.h" #include "../xml/vpattern.h" #include +#include "../tools/vtooldetail.h" //--------------------------------------------------------------------------------------------------------------------- -DelTool::DelTool(VPattern *doc, quint32 id, QGraphicsItem *tool, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), xml(QDomElement()), parentNode(QDomNode()), previousNode(QDomNode()), - doc(doc), toolId(id), tool(tool) +DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent) + : QObject(), QUndoCommand(parent), xml(QDomElement()), parentNode(QDomNode()), doc(doc), toolId(id), + cursor(doc->getCursor()) { setText(tr("Delete tool")); QDomElement domElement = doc->elementById(QString().setNum(id)); @@ -41,7 +42,6 @@ DelTool::DelTool(VPattern *doc, quint32 id, QGraphicsItem *tool, QUndoCommand *p { xml = domElement.cloneNode().toElement(); parentNode = domElement.parentNode(); - previousNode = domElement.previousSibling(); } else { @@ -57,7 +57,18 @@ DelTool::~DelTool() //--------------------------------------------------------------------------------------------------------------------- void DelTool::undo() { - parentNode.insertAfter(xml, previousNode); + if (cursor <= 0) + { + parentNode.appendChild(xml); + } + else + { + QDomElement refElement = doc->elementById(QString().setNum(cursor)); + if (refElement.isElement()) + { + parentNode.insertAfter(xml, refElement); + } + } emit NeedFullParsing(); } @@ -68,7 +79,6 @@ void DelTool::redo() if (domElement.isElement()) { parentNode.removeChild(domElement); - tool->hide(); emit NeedFullParsing(); } else diff --git a/src/app/undocommands/deltool.h b/src/app/undocommands/deltool.h index 856f95aa3..77e15e4d9 100644 --- a/src/app/undocommands/deltool.h +++ b/src/app/undocommands/deltool.h @@ -39,7 +39,7 @@ class DelTool : public QObject, public QUndoCommand { Q_OBJECT public: - DelTool(VPattern *doc, quint32 id, QGraphicsItem *tool, QUndoCommand *parent = 0); + DelTool(VPattern *doc, quint32 id, QUndoCommand *parent = 0); virtual ~DelTool(); virtual void undo(); virtual void redo(); @@ -49,10 +49,9 @@ private: Q_DISABLE_COPY(DelTool) QDomElement xml; QDomNode parentNode; - QDomNode previousNode; VPattern *doc; quint32 toolId; - QGraphicsItem *tool; + quint32 cursor; }; #endif // DELTOOL_H diff --git a/src/app/undocommands/movedetail.cpp b/src/app/undocommands/movedetail.cpp index 1470b058d..84270c8ac 100644 --- a/src/app/undocommands/movedetail.cpp +++ b/src/app/undocommands/movedetail.cpp @@ -68,7 +68,6 @@ void MoveDetail::undo() { doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(oldX))); doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(oldY))); - qDebug()<<"undo move detail"<SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(newX))); doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(newY))); - qDebug()<<"redo move detail"<