diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index ff1e95df2..9075359a6 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -183,7 +183,7 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons UpdateControlPoints(spl, newSplPath, indexSpline); MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, id, this->scene()); - connect(moveSplPath, &MoveSplinePath::NeedLiteParsing, doc, &VPattern::LiteParseTree); + connect(moveSplPath, &VUndoCommand::NeedLiteParsing, doc, &VPattern::LiteParseTree); qApp->getUndoStack()->push(moveSplPath); } diff --git a/src/app/undocommands/adddet.cpp b/src/app/undocommands/adddet.cpp index 2b001e695..e4b29ebf6 100644 --- a/src/app/undocommands/adddet.cpp +++ b/src/app/undocommands/adddet.cpp @@ -31,9 +31,10 @@ //--------------------------------------------------------------------------------------------------------------------- AddDet::AddDet(const QDomElement &xml, VPattern *doc, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), xml(xml), doc(doc), redoFlag(false) + : VUndoCommand(xml, doc, parent) { setText(tr("Add detail")); + nodeId = doc->GetParametrId(xml); } //--------------------------------------------------------------------------------------------------------------------- @@ -47,7 +48,20 @@ void AddDet::undo() QDomElement element; if (doc->GetActivNodeElement(VPattern::TagDetails, element)) { - element.removeChild(xml); + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); + if (domElement.isElement()) + { + if (element.removeChild(domElement).isNull()) + { + qDebug()<<"Can't delete node"; + return; + } + } + else + { + qDebug()<<"Can't get node by id = "< -#include +#include "vundocommand.h" class VPattern; -class AddDet : public QObject, public QUndoCommand +class AddDet : public VUndoCommand { Q_OBJECT public: @@ -44,13 +43,8 @@ public: virtual void undo(); // cppcheck-suppress unusedFunction virtual void redo(); -signals: - void NeedFullParsing(); private: Q_DISABLE_COPY(AddDet) - const QDomElement xml; - VPattern *doc; - bool redoFlag; }; #endif // ADDDET_H diff --git a/src/app/undocommands/adddetnode.cpp b/src/app/undocommands/adddetnode.cpp index 8221162de..bf3e456c1 100644 --- a/src/app/undocommands/adddetnode.cpp +++ b/src/app/undocommands/adddetnode.cpp @@ -31,9 +31,10 @@ //--------------------------------------------------------------------------------------------------------------------- AddDetNode::AddDetNode(const QDomElement &xml, VPattern *doc, QUndoCommand *parent) - : QUndoCommand(parent), xml(xml), doc(doc) + : VUndoCommand(xml, doc, parent) { setText(QObject::tr("Add node")); + nodeId = doc->GetParametrId(xml); } //--------------------------------------------------------------------------------------------------------------------- @@ -46,7 +47,20 @@ void AddDetNode::undo() QDomElement modelingElement; if (doc->GetActivNodeElement(VPattern::TagModeling, modelingElement)) { - modelingElement.removeChild(xml); + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); + if (domElement.isElement()) + { + if (modelingElement.removeChild(domElement).isNull()) + { + qDebug()<<"Can't delete node"; + return; + } + } + else + { + qDebug()<<"Can't get node by id = "< -#include +#include "vundocommand.h" -class VPattern; - -class AddDetNode : public QUndoCommand +class AddDetNode : public VUndoCommand { + Q_OBJECT public: AddDetNode(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0); virtual ~AddDetNode(); @@ -43,8 +41,6 @@ public: virtual void redo(); private: Q_DISABLE_COPY(AddDetNode) - const QDomElement xml; - VPattern *doc; }; #endif // ADDDETNODE_H diff --git a/src/app/undocommands/addpatternpiece.cpp b/src/app/undocommands/addpatternpiece.cpp index f77d91ec7..65c2e6cb9 100644 --- a/src/app/undocommands/addpatternpiece.cpp +++ b/src/app/undocommands/addpatternpiece.cpp @@ -32,9 +32,8 @@ //--------------------------------------------------------------------------------------------------------------------- AddPatternPiece::AddPatternPiece(const QDomElement &xml, VPattern *doc, const QString &namePP, const QString &mPath, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), xml(xml), doc(doc), namePP(namePP), redoFlag(false), mPath(mPath) + : VUndoCommand(xml, doc, parent), namePP(namePP), mPath(mPath) { - SCASSERT(xml.isNull() == false); SCASSERT(namePP.isEmpty() == false); SCASSERT(mPath.isEmpty() == false); setText(tr("Add pattern piece %1").arg(namePP)); @@ -72,9 +71,5 @@ void AddPatternPiece::redo() rootElement.appendChild(xml); - if (redoFlag) - { - emit NeedFullParsing(); - } - redoFlag = true; + RedoFullParsing(); } diff --git a/src/app/undocommands/addpatternpiece.h b/src/app/undocommands/addpatternpiece.h index 661d7de92..035816de7 100644 --- a/src/app/undocommands/addpatternpiece.h +++ b/src/app/undocommands/addpatternpiece.h @@ -29,12 +29,9 @@ #ifndef ADDPATTERNPIECE_H #define ADDPATTERNPIECE_H -#include -#include +#include "vundocommand.h" -class VPattern; - -class AddPatternPiece : public QObject, public QUndoCommand +class AddPatternPiece : public VUndoCommand { Q_OBJECT public: @@ -43,15 +40,9 @@ public: virtual ~AddPatternPiece(); virtual void undo(); virtual void redo(); -signals: - void ClearScene(); - void NeedFullParsing(); private: Q_DISABLE_COPY(AddPatternPiece) - const QDomElement xml; - VPattern *doc; QString namePP; - bool redoFlag; QString mPath; }; diff --git a/src/app/undocommands/addtocalc.cpp b/src/app/undocommands/addtocalc.cpp index 62baf2062..1da22a24a 100644 --- a/src/app/undocommands/addtocalc.cpp +++ b/src/app/undocommands/addtocalc.cpp @@ -31,10 +31,10 @@ //--------------------------------------------------------------------------------------------------------------------- AddToCalc::AddToCalc(const QDomElement &xml, VPattern *doc, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), xml(xml), doc(doc), nameActivDraw(doc->GetNameActivDraw()), - cursor(doc->getCursor()), redoFlag(false) + : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivDraw()), cursor(doc->getCursor()) { setText(tr("Add object")); + nodeId = doc->GetParametrId(xml); } //--------------------------------------------------------------------------------------------------------------------- @@ -50,10 +50,19 @@ void AddToCalc::undo() QDomElement calcElement; if (doc->GetActivNodeElement(VPattern::TagCalculation, calcElement)) { - calcElement.removeChild(xml); - if (cursor > 0) + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); + if (domElement.isElement()) { - doc->setCursor(0); + if (calcElement.removeChild(domElement).isNull()) + { + qDebug()<<"Can't delete node"; + return; + } + } + else + { + qDebug()<<"Can't get tool by id = "< 0) + { + doc->setCursor(0); + } emit NeedFullParsing(); } @@ -97,9 +110,5 @@ void AddToCalc::redo() qDebug()<<"Can't find tag Calculation"<< Q_FUNC_INFO; return; } - if (redoFlag) - { - emit NeedFullParsing(); - } - redoFlag = true; + RedoFullParsing(); } diff --git a/src/app/undocommands/addtocalc.h b/src/app/undocommands/addtocalc.h index 143f19aa4..e09e18cb5 100644 --- a/src/app/undocommands/addtocalc.h +++ b/src/app/undocommands/addtocalc.h @@ -29,12 +29,9 @@ #ifndef ADDTOCALC_H #define ADDTOCALC_H -#include -#include +#include "vundocommand.h" -class VPattern; - -class AddToCalc : public QObject, public QUndoCommand +class AddToCalc : public VUndoCommand { Q_OBJECT public: @@ -42,15 +39,10 @@ public: virtual ~AddToCalc(); virtual void undo(); virtual void redo(); -signals: - void NeedFullParsing(); private: Q_DISABLE_COPY(AddToCalc) - const QDomElement xml; - VPattern *doc; - const QString nameActivDraw; - quint32 cursor; - bool redoFlag; + const QString nameActivDraw; + quint32 cursor; }; #endif // ADDTOCALC_H diff --git a/src/app/undocommands/adduniondetails.cpp b/src/app/undocommands/adduniondetails.cpp index 3dc577bb3..99d1b4759 100644 --- a/src/app/undocommands/adduniondetails.cpp +++ b/src/app/undocommands/adduniondetails.cpp @@ -31,9 +31,10 @@ //--------------------------------------------------------------------------------------------------------------------- AddUnionDetails::AddUnionDetails(const QDomElement &xml, VPattern *doc, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), xml(xml), doc(doc), redoFlag(false) + : VUndoCommand(xml, doc, parent) { setText(tr("Add union details")); + nodeId = doc->GetParametrId(xml); } //--------------------------------------------------------------------------------------------------------------------- @@ -46,7 +47,20 @@ void AddUnionDetails::undo() QDomElement modelingElement; if (doc->GetActivNodeElement(VPattern::TagModeling, modelingElement)) { - modelingElement.removeChild(xml); + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); + if (domElement.isElement()) + { + if (modelingElement.removeChild(domElement).isNull()) + { + qDebug()<<"Can't delete node"; + return; + } + } + else + { + qDebug()<<"Can't get node by id = "< -#include +#include "vundocommand.h" -class VPattern; - -class AddUnionDetails : public QObject, public QUndoCommand +class AddUnionDetails : public VUndoCommand { Q_OBJECT public: @@ -42,13 +39,8 @@ public: virtual ~AddUnionDetails(); virtual void undo(); virtual void redo(); -signals: - void NeedFullParsing(); private: Q_DISABLE_COPY(AddUnionDetails) - const QDomElement xml; - VPattern *doc; - bool redoFlag; }; #endif // ADDUNIONDETAILS_H diff --git a/src/app/undocommands/deletedetail.cpp b/src/app/undocommands/deletedetail.cpp index 2a0c9345e..65a21a108 100644 --- a/src/app/undocommands/deletedetail.cpp +++ b/src/app/undocommands/deletedetail.cpp @@ -32,9 +32,10 @@ //--------------------------------------------------------------------------------------------------------------------- DeleteDetail::DeleteDetail(VPattern *doc, quint32 id, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), xml(QDomElement()), doc(doc), detId(id), parentNode(QDomNode()) + : VUndoCommand(xml, doc, parent), parentNode(QDomNode()) { setText(tr("Delete tool")); + nodeId = id; QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { @@ -43,7 +44,7 @@ DeleteDetail::DeleteDetail(VPattern *doc, quint32 id, QUndoCommand *parent) } else { - qDebug()<<"Can't get detail by id = "<GetPPElement(namePP); + QDomElement patternP = doc->GetPPElement(namePP); patternPiece = patternP.cloneNode().toElement(); mPath = doc->MPath(); - previousNode = patternP.previousSibling();//find previous pattern piece + QDomNode previousPP = patternP.previousSibling();//find previous pattern piece + previousPPName = doc->GetParametrString(previousPP.toElement(), VPattern::AttrName, ""); } //--------------------------------------------------------------------------------------------------------------------- @@ -51,7 +52,8 @@ DeletePatternPiece::~DeletePatternPiece() void DeletePatternPiece::undo() { QDomElement rootElement = doc->documentElement(); - rootElement.insertAfter(patternPiece, previousNode); + QDomNode previousPP = doc->GetPPElement(previousPPName); + rootElement.insertAfter(patternPiece, previousPP); emit NeedFullParsing(); doc->ChangedActivPP(namePP); diff --git a/src/app/undocommands/deletepatternpiece.h b/src/app/undocommands/deletepatternpiece.h index fa5d14cd6..4c4c21564 100644 --- a/src/app/undocommands/deletepatternpiece.h +++ b/src/app/undocommands/deletepatternpiece.h @@ -29,12 +29,9 @@ #ifndef DELETEPATTERNPIECE_H #define DELETEPATTERNPIECE_H -#include -#include +#include "vundocommand.h" -class VPattern; - -class DeletePatternPiece : public QObject, public QUndoCommand +class DeletePatternPiece : public VUndoCommand { Q_OBJECT public: @@ -42,15 +39,12 @@ public: virtual ~DeletePatternPiece(); virtual void undo(); virtual void redo(); -signals: - void NeedFullParsing(); private: Q_DISABLE_COPY(DeletePatternPiece) - VPattern *doc; QString namePP; QDomElement patternPiece; QString mPath; - QDomNode previousNode; + QString previousPPName; }; #endif // DELETEPATTERNPIECE_H diff --git a/src/app/undocommands/deltool.cpp b/src/app/undocommands/deltool.cpp index 831f70b9b..f7634f82d 100644 --- a/src/app/undocommands/deltool.cpp +++ b/src/app/undocommands/deltool.cpp @@ -33,10 +33,10 @@ //--------------------------------------------------------------------------------------------------------------------- DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), xml(QDomElement()), parentNode(QDomNode()), doc(doc), toolId(id), - cursor(doc->getCursor()) + : VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), cursor(doc->getCursor()) { setText(tr("Delete tool")); + nodeId = id; QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { @@ -45,7 +45,7 @@ DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent) } else { - qDebug()<<"Can't get tool by id = "<elementById(QString().setNum(id)); @@ -51,7 +50,7 @@ MoveDetail::MoveDetail(VPattern *doc, const double &x, const double &y, const qu } else { - qDebug()<<"Can't find detail with id ="<< detId << Q_FUNC_INFO; + qDebug()<<"Can't find detail with id ="<< nodeId << Q_FUNC_INFO; return; } } @@ -63,11 +62,10 @@ MoveDetail::~MoveDetail() //--------------------------------------------------------------------------------------------------------------------- void MoveDetail::undo() { - QDomElement domElement = doc->elementById(QString().setNum(detId)); + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); if (domElement.isElement()) { - doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(oldX))); - doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(oldY))); + SaveCoordinates(domElement, oldX, oldY); emit NeedLiteParsing(); @@ -76,7 +74,7 @@ void MoveDetail::undo() } else { - qDebug()<<"Can't find detail with id ="<< detId << Q_FUNC_INFO; + qDebug()<<"Can't find detail with id ="<< nodeId << Q_FUNC_INFO; return; } } @@ -84,11 +82,10 @@ void MoveDetail::undo() //--------------------------------------------------------------------------------------------------------------------- void MoveDetail::redo() { - QDomElement domElement = doc->elementById(QString().setNum(detId)); + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); if (domElement.isElement()) { - doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(newX))); - doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(newY))); + SaveCoordinates(domElement, newX, newY); if (redoFlag) { @@ -101,7 +98,7 @@ void MoveDetail::redo() } else { - qDebug()<<"Can't find detail with id ="<< detId << Q_FUNC_INFO; + qDebug()<<"Can't find detail with id ="<< nodeId << Q_FUNC_INFO; return; } } @@ -114,7 +111,7 @@ bool MoveDetail::mergeWith(const QUndoCommand *command) SCASSERT(moveCommand != nullptr); const quint32 id = moveCommand->getDetId(); - if (id != detId) + if (id != nodeId) { return false; } @@ -129,3 +126,10 @@ int MoveDetail::id() const { return static_cast(UndoCommand::MoveDetail); } + +//--------------------------------------------------------------------------------------------------------------------- +void MoveDetail::SaveCoordinates(QDomElement &domElement, double x, double y) +{ + doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(x))); + doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(y))); +} diff --git a/src/app/undocommands/movedetail.h b/src/app/undocommands/movedetail.h index d8871e6ee..54b439b5d 100644 --- a/src/app/undocommands/movedetail.h +++ b/src/app/undocommands/movedetail.h @@ -29,12 +29,11 @@ #ifndef MOVEDETAIL_H #define MOVEDETAIL_H -#include +#include "vundocommand.h" -class VPattern; class QGraphicsScene; -class MoveDetail : public QObject, public QUndoCommand +class MoveDetail : public VUndoCommand { Q_OBJECT public: @@ -49,24 +48,20 @@ public: quint32 getDetId() const; double getNewX() const; double getNewY() const; -signals: - void NeedLiteParsing(); private: Q_DISABLE_COPY(MoveDetail) - VPattern *doc; double oldX; double oldY; double newX; double newY; - quint32 detId; QGraphicsScene *scene; - bool redoFlag; + void SaveCoordinates(QDomElement &domElement, double x, double y); }; //--------------------------------------------------------------------------------------------------------------------- inline quint32 MoveDetail::getDetId() const { - return detId; + return nodeId; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/undocommands/movespline.cpp b/src/app/undocommands/movespline.cpp index d6f557a7d..98f176ba9 100644 --- a/src/app/undocommands/movespline.cpp +++ b/src/app/undocommands/movespline.cpp @@ -31,14 +31,14 @@ #include #include #include "../xml/vpattern.h" -#include "undocommands.h" //--------------------------------------------------------------------------------------------------------------------- MoveSpline::MoveSpline(VPattern *doc, const VSpline *oldSpl, const VSpline &newSpl, const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), doc(doc), oldSpline(*oldSpl), newSpline(newSpl), splineId(id), scene(scene) + : VUndoCommand(QDomElement(), doc, parent), oldSpline(*oldSpl), newSpline(newSpl), scene(scene) { setText(tr("Move spline")); + nodeId = id; SCASSERT(scene != nullptr); } @@ -50,49 +50,13 @@ MoveSpline::~MoveSpline() //--------------------------------------------------------------------------------------------------------------------- void MoveSpline::undo() { - QDomElement domElement = doc->elementById(QString().setNum(splineId)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, VAbstractTool::AttrAngle1, QString().setNum(oldSpline.GetAngle1())); - doc->SetAttribute(domElement, VAbstractTool::AttrAngle2, QString().setNum(oldSpline.GetAngle2())); - doc->SetAttribute(domElement, VAbstractTool::AttrKAsm1, QString().setNum(oldSpline.GetKasm1())); - doc->SetAttribute(domElement, VAbstractTool::AttrKAsm2, QString().setNum(oldSpline.GetKasm2())); - doc->SetAttribute(domElement, VAbstractTool::AttrKCurve, QString().setNum(oldSpline.GetKcurve())); - - emit NeedLiteParsing(); - - QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); - } - else - { - qDebug()<<"Can't find spline with id ="<< splineId << Q_FUNC_INFO; - return; - } + Do(oldSpline); } //--------------------------------------------------------------------------------------------------------------------- void MoveSpline::redo() { - QDomElement domElement = doc->elementById(QString().setNum(splineId)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, VAbstractTool::AttrAngle1, QString().setNum(newSpline.GetAngle1())); - doc->SetAttribute(domElement, VAbstractTool::AttrAngle2, QString().setNum(newSpline.GetAngle2())); - doc->SetAttribute(domElement, VAbstractTool::AttrKAsm1, QString().setNum(newSpline.GetKasm1())); - doc->SetAttribute(domElement, VAbstractTool::AttrKAsm2, QString().setNum(newSpline.GetKasm2())); - doc->SetAttribute(domElement, VAbstractTool::AttrKCurve, QString().setNum(newSpline.GetKcurve())); - - emit NeedLiteParsing(); - - QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); - } - else - { - qDebug()<<"Can't find spline with id ="<< splineId << Q_FUNC_INFO; - return; - } + Do(newSpline); } //--------------------------------------------------------------------------------------------------------------------- @@ -102,7 +66,7 @@ bool MoveSpline::mergeWith(const QUndoCommand *command) SCASSERT(moveCommand != nullptr); const quint32 id = moveCommand->getSplineId(); - if (id != splineId) + if (id != nodeId) { return false; } @@ -116,3 +80,27 @@ int MoveSpline::id() const { return static_cast(UndoCommand::MoveSpline); } + +//--------------------------------------------------------------------------------------------------------------------- +void MoveSpline::Do(const VSpline &spl) +{ + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); + if (domElement.isElement()) + { + doc->SetAttribute(domElement, VAbstractTool::AttrAngle1, QString().setNum(spl.GetAngle1())); + doc->SetAttribute(domElement, VAbstractTool::AttrAngle2, QString().setNum(spl.GetAngle2())); + doc->SetAttribute(domElement, VAbstractTool::AttrKAsm1, QString().setNum(spl.GetKasm1())); + doc->SetAttribute(domElement, VAbstractTool::AttrKAsm2, QString().setNum(spl.GetKasm2())); + doc->SetAttribute(domElement, VAbstractTool::AttrKCurve, QString().setNum(spl.GetKcurve())); + + emit NeedLiteParsing(); + + QList list = scene->views(); + VAbstractTool::NewSceneRect(scene, list[0]); + } + else + { + qDebug()<<"Can't find spline with id ="<< nodeId << Q_FUNC_INFO; + return; + } +} diff --git a/src/app/undocommands/movespline.h b/src/app/undocommands/movespline.h index 24045858b..96f252065 100644 --- a/src/app/undocommands/movespline.h +++ b/src/app/undocommands/movespline.h @@ -29,13 +29,12 @@ #ifndef MOVESPLINE_H #define MOVESPLINE_H -#include +#include "vundocommand.h" #include "../geometry/vspline.h" -class VPattern; class QGraphicsScene; -class MoveSpline : public QObject, public QUndoCommand +class MoveSpline : public VUndoCommand { Q_OBJECT public: @@ -48,21 +47,18 @@ public: virtual int id() const; quint32 getSplineId() const; VSpline getNewSpline() const; -signals: - void NeedLiteParsing(); private: Q_DISABLE_COPY(MoveSpline) - VPattern *doc; VSpline oldSpline; VSpline newSpline; - quint32 splineId; QGraphicsScene *scene; + void Do(const VSpline &spl); }; //--------------------------------------------------------------------------------------------------------------------- inline quint32 MoveSpline::getSplineId() const { - return splineId; + return nodeId; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/undocommands/movesplinepath.cpp b/src/app/undocommands/movesplinepath.cpp index 535b85770..de167c142 100644 --- a/src/app/undocommands/movesplinepath.cpp +++ b/src/app/undocommands/movesplinepath.cpp @@ -29,15 +29,14 @@ #include "movesplinepath.h" #include #include "../tools/drawTools/vtoolsplinepath.h" -#include "undocommands.h" //--------------------------------------------------------------------------------------------------------------------- MoveSplinePath::MoveSplinePath(VPattern *doc, const VSplinePath &oldSplPath, const VSplinePath &newSplPath, const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), doc(doc), oldSplinePath(oldSplPath), newSplinePath(newSplPath), splinePathId(id), - scene(scene) + : VUndoCommand(QDomElement(), doc, parent), oldSplinePath(oldSplPath), newSplinePath(newSplPath), scene(scene) { setText(tr("Move spline path")); + nodeId = id; SCASSERT(scene != nullptr); } @@ -49,43 +48,13 @@ MoveSplinePath::~MoveSplinePath() //--------------------------------------------------------------------------------------------------------------------- void MoveSplinePath::undo() { - QDomElement domElement = doc->elementById(QString().setNum(splinePathId)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, VToolSplinePath::AttrKCurve, QString().setNum(oldSplinePath.getKCurve())); - VToolSplinePath::UpdatePathPoint(doc, domElement, oldSplinePath); - - emit NeedLiteParsing(); - - QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); - } - else - { - qDebug()<<"Can't find spline path with id ="<< splinePathId << Q_FUNC_INFO; - return; - } + Do(oldSplinePath); } //--------------------------------------------------------------------------------------------------------------------- void MoveSplinePath::redo() { - QDomElement domElement = doc->elementById(QString().setNum(splinePathId)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, VToolSplinePath::AttrKCurve, QString().setNum(newSplinePath.getKCurve())); - VToolSplinePath::UpdatePathPoint(doc, domElement, newSplinePath); - - emit NeedLiteParsing(); - - QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); - } - else - { - qDebug()<<"Can't find spline path with id ="<< splinePathId << Q_FUNC_INFO; - return; - } + Do(newSplinePath); } //--------------------------------------------------------------------------------------------------------------------- @@ -95,7 +64,7 @@ bool MoveSplinePath::mergeWith(const QUndoCommand *command) SCASSERT(moveCommand != nullptr); const quint32 id = moveCommand->getSplinePathId(); - if (id != splinePathId) + if (id != nodeId) { return false; } @@ -109,3 +78,24 @@ int MoveSplinePath::id() const { return static_cast(UndoCommand::MoveSplinePath); } + +//--------------------------------------------------------------------------------------------------------------------- +void MoveSplinePath::Do(const VSplinePath &splPath) +{ + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); + if (domElement.isElement()) + { + doc->SetAttribute(domElement, VToolSplinePath::AttrKCurve, QString().setNum(splPath.getKCurve())); + VToolSplinePath::UpdatePathPoint(doc, domElement, splPath); + + emit NeedLiteParsing(); + + QList list = scene->views(); + VAbstractTool::NewSceneRect(scene, list[0]); + } + else + { + qDebug()<<"Can't find spline path with id ="<< nodeId << Q_FUNC_INFO; + return; + } +} diff --git a/src/app/undocommands/movesplinepath.h b/src/app/undocommands/movesplinepath.h index aab71cc0b..509a07ddd 100644 --- a/src/app/undocommands/movesplinepath.h +++ b/src/app/undocommands/movesplinepath.h @@ -29,13 +29,12 @@ #ifndef MOVESPLINEPATH_H #define MOVESPLINEPATH_H -#include +#include "vundocommand.h" #include "../geometry/vsplinepath.h" -class VPattern; class QGraphicsScene; -class MoveSplinePath : public QObject, public QUndoCommand +class MoveSplinePath : public VUndoCommand { Q_OBJECT public: @@ -48,21 +47,18 @@ public: virtual int id() const; quint32 getSplinePathId() const; VSplinePath getNewSplinePath() const; -signals: - void NeedLiteParsing(); private: Q_DISABLE_COPY(MoveSplinePath) - VPattern *doc; VSplinePath oldSplinePath; VSplinePath newSplinePath; - quint32 splinePathId; QGraphicsScene *scene; + void Do(const VSplinePath &splPath); }; //--------------------------------------------------------------------------------------------------------------------- inline quint32 MoveSplinePath::getSplinePathId() const { - return splinePathId; + return nodeId; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/undocommands/movespoint.cpp b/src/app/undocommands/movespoint.cpp index 1a3c2abe5..cb87d369f 100644 --- a/src/app/undocommands/movespoint.cpp +++ b/src/app/undocommands/movespoint.cpp @@ -32,14 +32,14 @@ #include "../xml/vpattern.h" #include "../tools/vabstracttool.h" #include "../widgets/vapplication.h" -#include "undocommands.h" //--------------------------------------------------------------------------------------------------------------------- MoveSPoint::MoveSPoint(VPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), doc(doc), oldX(0.0), oldY(0.0), newX(x), newY(y), sPointId(id), scene(scene) + : VUndoCommand(QDomElement(), doc, parent), oldX(0.0), oldY(0.0), newX(x), newY(y), scene(scene) { setText(tr("Move single point")); + nodeId = id; SCASSERT(scene != nullptr); QDomElement domElement = doc->elementById(QString().setNum(id)); @@ -50,7 +50,7 @@ MoveSPoint::MoveSPoint(VPattern *doc, const double &x, const double &y, const qu } else { - qDebug()<<"Can't find spoint with id ="<< sPointId << Q_FUNC_INFO; + qDebug()<<"Can't find spoint with id ="<< nodeId << Q_FUNC_INFO; return; } } @@ -62,43 +62,13 @@ MoveSPoint::~MoveSPoint() //--------------------------------------------------------------------------------------------------------------------- void MoveSPoint::undo() { - QDomElement domElement = doc->elementById(QString().setNum(sPointId)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, VAbstractTool::AttrX, QString().setNum(qApp->fromPixel(oldX))); - doc->SetAttribute(domElement, VAbstractTool::AttrY, QString().setNum(qApp->fromPixel(oldY))); - - emit NeedLiteParsing(); - - QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); - } - else - { - qDebug()<<"Can't find spoint with id ="<< sPointId << Q_FUNC_INFO; - return; - } + Do(oldX, oldY); } //--------------------------------------------------------------------------------------------------------------------- void MoveSPoint::redo() { - QDomElement domElement = doc->elementById(QString().setNum(sPointId)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, VAbstractTool::AttrX, QString().setNum(qApp->fromPixel(newX))); - doc->SetAttribute(domElement, VAbstractTool::AttrY, QString().setNum(qApp->fromPixel(newY))); - - emit NeedLiteParsing(); - - QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); - } - else - { - qDebug()<<"Can't find spoint with id ="<< sPointId << Q_FUNC_INFO; - return; - } + Do(newX, newY); } //--------------------------------------------------------------------------------------------------------------------- @@ -108,7 +78,7 @@ bool MoveSPoint::mergeWith(const QUndoCommand *command) SCASSERT(moveCommand != nullptr); const quint32 id = moveCommand->getSPointId(); - if (id != sPointId) + if (id != nodeId) { return false; } @@ -123,3 +93,24 @@ int MoveSPoint::id() const { return static_cast(UndoCommand::MoveSPoint); } + +//--------------------------------------------------------------------------------------------------------------------- +void MoveSPoint::Do(double x, double y) +{ + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); + if (domElement.isElement()) + { + doc->SetAttribute(domElement, VAbstractTool::AttrX, QString().setNum(qApp->fromPixel(x))); + doc->SetAttribute(domElement, VAbstractTool::AttrY, QString().setNum(qApp->fromPixel(y))); + + emit NeedLiteParsing(); + + QList list = scene->views(); + VAbstractTool::NewSceneRect(scene, list[0]); + } + else + { + qDebug()<<"Can't find spoint with id ="<< nodeId << Q_FUNC_INFO; + return; + } +} diff --git a/src/app/undocommands/movespoint.h b/src/app/undocommands/movespoint.h index 17a5c869f..e9825b19c 100644 --- a/src/app/undocommands/movespoint.h +++ b/src/app/undocommands/movespoint.h @@ -29,12 +29,11 @@ #ifndef MOVESPOINT_H #define MOVESPOINT_H -#include +#include "vundocommand.h" -class VPattern; class QGraphicsScene; -class MoveSPoint : public QObject, public QUndoCommand +class MoveSPoint : public VUndoCommand { Q_OBJECT public: @@ -48,23 +47,20 @@ public: quint32 getSPointId() const; double getNewX() const; double getNewY() const; -signals: - void NeedLiteParsing(); + void Do(double x, double y); private: Q_DISABLE_COPY(MoveSPoint) - VPattern *doc; double oldX; double oldY; double newX; double newY; - quint32 sPointId; QGraphicsScene *scene; }; //--------------------------------------------------------------------------------------------------------------------- inline quint32 MoveSPoint::getSPointId() const { - return sPointId; + return nodeId; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/undocommands/savedetailoptions.cpp b/src/app/undocommands/savedetailoptions.cpp index a6b11c4dd..678551866 100644 --- a/src/app/undocommands/savedetailoptions.cpp +++ b/src/app/undocommands/savedetailoptions.cpp @@ -27,15 +27,15 @@ *************************************************************************/ #include "savedetailoptions.h" -#include "undocommands.h" #include "../tools/nodeDetails/vabstractnode.h" #include SaveDetailOptions::SaveDetailOptions(const VDetail &oldDet, const VDetail &newDet, VPattern *doc, const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), oldDet(oldDet), newDet(newDet), doc(doc), detId(id), scene(scene) + : VUndoCommand(QDomElement(), doc, parent), oldDet(oldDet), newDet(newDet), scene(scene) { setText(tr("Save detail option")); + nodeId = id; } //--------------------------------------------------------------------------------------------------------------------- @@ -45,13 +45,10 @@ SaveDetailOptions::~SaveDetailOptions() //--------------------------------------------------------------------------------------------------------------------- void SaveDetailOptions::undo() { - QDomElement domElement = doc->elementById(QString().setNum(detId)); + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); if (domElement.isElement()) { - doc->SetAttribute(domElement, VAbstractTool::AttrName, oldDet.getName()); - doc->SetAttribute(domElement, VToolDetail::AttrSupplement, QString().setNum(oldDet.getSeamAllowance())); - doc->SetAttribute(domElement, VToolDetail::AttrClosed, QString().setNum(oldDet.getClosed())); - doc->SetAttribute(domElement, VToolDetail::AttrWidth, QString().setNum(oldDet.getWidth())); + SaveDet(domElement, oldDet); doc->RemoveAllChild(domElement); for (ptrdiff_t i = 0; i < oldDet.CountNode(); ++i) { @@ -75,7 +72,7 @@ void SaveDetailOptions::undo() } else { - qDebug()<<"Can't find detail with id ="<< detId << Q_FUNC_INFO; + qDebug()<<"Can't find detail with id ="<< nodeId << Q_FUNC_INFO; return; } } @@ -83,13 +80,10 @@ void SaveDetailOptions::undo() //--------------------------------------------------------------------------------------------------------------------- void SaveDetailOptions::redo() { - QDomElement domElement = doc->elementById(QString().setNum(detId)); + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); if (domElement.isElement()) { - doc->SetAttribute(domElement, VAbstractTool::AttrName, newDet.getName()); - doc->SetAttribute(domElement, VToolDetail::AttrSupplement, QString().setNum(newDet.getSeamAllowance())); - doc->SetAttribute(domElement, VToolDetail::AttrClosed, QString().setNum(newDet.getClosed())); - doc->SetAttribute(domElement, VToolDetail::AttrWidth, QString().setNum(newDet.getWidth())); + SaveDet(domElement, newDet); doc->RemoveAllChild(domElement); for (ptrdiff_t i = 0; i < newDet.CountNode(); ++i) { @@ -113,7 +107,7 @@ void SaveDetailOptions::redo() } else { - qDebug()<<"Can't find detail with id ="<< detId << Q_FUNC_INFO; + qDebug()<<"Can't find detail with id ="<< nodeId << Q_FUNC_INFO; return; } } @@ -125,7 +119,7 @@ bool SaveDetailOptions::mergeWith(const QUndoCommand *command) SCASSERT(saveCommand != nullptr); const quint32 id = saveCommand->getDetId(); - if (id != detId) + if (id != nodeId) { return false; } @@ -139,3 +133,12 @@ int SaveDetailOptions::id() const { return static_cast(UndoCommand::SaveDetailOptions); } + +//--------------------------------------------------------------------------------------------------------------------- +void SaveDetailOptions::SaveDet(QDomElement &domElement, const VDetail &det) +{ + doc->SetAttribute(domElement, VAbstractTool::AttrName, det.getName()); + doc->SetAttribute(domElement, VToolDetail::AttrSupplement, QString().setNum(det.getSeamAllowance())); + doc->SetAttribute(domElement, VToolDetail::AttrClosed, QString().setNum(det.getClosed())); + doc->SetAttribute(domElement, VToolDetail::AttrWidth, QString().setNum(det.getWidth())); +} diff --git a/src/app/undocommands/savedetailoptions.h b/src/app/undocommands/savedetailoptions.h index 3f8cda414..cfb1ab0f8 100644 --- a/src/app/undocommands/savedetailoptions.h +++ b/src/app/undocommands/savedetailoptions.h @@ -29,14 +29,12 @@ #ifndef SAVEDETAILOPTIONS_H #define SAVEDETAILOPTIONS_H -#include -#include +#include "vundocommand.h" #include "../tools/vtooldetail.h" -class VPattern; class QGraphicsScene; -class SaveDetailOptions : public QObject, public QUndoCommand +class SaveDetailOptions : public VUndoCommand { Q_OBJECT public: @@ -49,21 +47,18 @@ public: virtual int id() const; quint32 getDetId() const; VDetail getNewDet() const; -signals: - void NeedLiteParsing(); private: Q_DISABLE_COPY(SaveDetailOptions) const VDetail oldDet; VDetail newDet; - VPattern *doc; - const quint32 detId; QGraphicsScene *scene; + void SaveDet(QDomElement &domElement, const VDetail &det); }; //--------------------------------------------------------------------------------------------------------------------- inline quint32 SaveDetailOptions::getDetId() const { - return detId; + return nodeId; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/undocommands/savetooloptions.cpp b/src/app/undocommands/savetooloptions.cpp index 12bbd704c..a3113e1cc 100644 --- a/src/app/undocommands/savetooloptions.cpp +++ b/src/app/undocommands/savetooloptions.cpp @@ -29,14 +29,14 @@ #include "savetooloptions.h" #include "../options.h" #include "../xml/vpattern.h" -#include "undocommands.h" //--------------------------------------------------------------------------------------------------------------------- SaveToolOptions::SaveToolOptions(const QDomElement &oldXml, const QDomElement &newXml, VPattern *doc, const quint32 &id, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), oldXml(oldXml), newXml(newXml), doc(doc), toolId(id) + : VUndoCommand(QDomElement(), doc, parent), oldXml(oldXml), newXml(newXml) { setText(tr("Save tool option")); + nodeId = id; } //--------------------------------------------------------------------------------------------------------------------- @@ -46,7 +46,7 @@ SaveToolOptions::~SaveToolOptions() //--------------------------------------------------------------------------------------------------------------------- void SaveToolOptions::undo() { - QDomElement domElement = doc->elementById(QString().setNum(toolId)); + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); if (domElement.isElement()) { domElement.parentNode().replaceChild(oldXml, domElement); @@ -55,7 +55,7 @@ void SaveToolOptions::undo() } else { - qDebug()<<"Can't find tool with id ="<< toolId << Q_FUNC_INFO; + qDebug()<<"Can't find tool with id ="<< nodeId << Q_FUNC_INFO; return; } } @@ -63,7 +63,7 @@ void SaveToolOptions::undo() //--------------------------------------------------------------------------------------------------------------------- void SaveToolOptions::redo() { - QDomElement domElement = doc->elementById(QString().setNum(toolId)); + QDomElement domElement = doc->elementById(QString().setNum(nodeId)); if (domElement.isElement()) { domElement.parentNode().replaceChild(newXml, domElement); @@ -72,7 +72,7 @@ void SaveToolOptions::redo() } else { - qDebug()<<"Can't find tool with id ="<< toolId << Q_FUNC_INFO; + qDebug()<<"Can't find tool with id ="<< nodeId << Q_FUNC_INFO; return; } } @@ -84,7 +84,7 @@ bool SaveToolOptions::mergeWith(const QUndoCommand *command) SCASSERT(saveCommand != nullptr); const quint32 id = saveCommand->getToolId(); - if (id != toolId) + if (id != nodeId) { return false; } diff --git a/src/app/undocommands/savetooloptions.h b/src/app/undocommands/savetooloptions.h index c370127a8..7a32ebf40 100644 --- a/src/app/undocommands/savetooloptions.h +++ b/src/app/undocommands/savetooloptions.h @@ -29,12 +29,9 @@ #ifndef SAVETOOLOPTIONS_H #define SAVETOOLOPTIONS_H -#include -#include +#include "vundocommand.h" -class VPattern; - -class SaveToolOptions : public QObject, public QUndoCommand +class SaveToolOptions : public VUndoCommand { Q_OBJECT public: @@ -53,8 +50,6 @@ private: Q_DISABLE_COPY(SaveToolOptions) const QDomElement oldXml; QDomElement newXml; - VPattern *doc; - const quint32 toolId; }; //--------------------------------------------------------------------------------------------------------------------- @@ -66,7 +61,7 @@ inline QDomElement SaveToolOptions::getNewXml() const //--------------------------------------------------------------------------------------------------------------------- inline quint32 SaveToolOptions::getToolId() const { - return toolId; + return nodeId; } #endif // SAVETOOLOPTIONS_H diff --git a/src/app/undocommands/undocommands.pri b/src/app/undocommands/undocommands.pri index 22d36e3f7..8e0987448 100644 --- a/src/app/undocommands/undocommands.pri +++ b/src/app/undocommands/undocommands.pri @@ -5,7 +5,6 @@ HEADERS += \ undocommands/movespline.h \ undocommands/movesplinepath.h \ undocommands/savetooloptions.h \ - undocommands/undocommands.h \ undocommands/savedetailoptions.h \ undocommands/movedetail.h \ undocommands/deltool.h \ @@ -13,7 +12,8 @@ HEADERS += \ undocommands/adddetnode.h \ undocommands/adddet.h \ undocommands/adduniondetails.h \ - undocommands/deletedetail.h + undocommands/deletedetail.h \ + undocommands/vundocommand.h SOURCES += \ @@ -30,5 +30,6 @@ SOURCES += \ undocommands/adddetnode.cpp \ undocommands/adddet.cpp \ undocommands/adduniondetails.cpp \ - undocommands/deletedetail.cpp + undocommands/deletedetail.cpp \ + undocommands/vundocommand.cpp diff --git a/src/app/undocommands/vundocommand.cpp b/src/app/undocommands/vundocommand.cpp new file mode 100644 index 000000000..f3fc7de7a --- /dev/null +++ b/src/app/undocommands/vundocommand.cpp @@ -0,0 +1,54 @@ +/************************************************************************ + ** + ** @file vundocommand.cpp + ** @author Roman Telezhynskyi + ** @date 16 7, 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 "vundocommand.h" +#include "../xml/vpattern.h" + +//--------------------------------------------------------------------------------------------------------------------- +VUndoCommand::VUndoCommand(const QDomElement &xml, VPattern *doc, QUndoCommand *parent) + :QObject(), QUndoCommand(parent), xml(xml), doc(doc), nodeId(0), redoFlag(false) +{ + SCASSERT(xml.isNull() == false); + SCASSERT(doc != nullptr); +} + +//--------------------------------------------------------------------------------------------------------------------- +VUndoCommand::~VUndoCommand() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VUndoCommand::RedoFullParsing() +{ + if (redoFlag) + { + emit NeedFullParsing(); + } + redoFlag = true; +} diff --git a/src/app/undocommands/undocommands.h b/src/app/undocommands/vundocommand.h similarity index 71% rename from src/app/undocommands/undocommands.h rename to src/app/undocommands/vundocommand.h index ed7f7c93a..b99be4a3e 100644 --- a/src/app/undocommands/undocommands.h +++ b/src/app/undocommands/vundocommand.h @@ -1,8 +1,8 @@ /************************************************************************ ** - ** @file undocommands.h + ** @file vundocommand.h ** @author Roman Telezhynskyi - ** @date 11 6, 2014 + ** @date 16 7, 2014 ** ** @brief ** @copyright @@ -26,8 +26,11 @@ ** *************************************************************************/ -#ifndef UNDOCOMMANDS_H -#define UNDOCOMMANDS_H +#ifndef VUNDOCOMMAND_H +#define VUNDOCOMMAND_H + +#include +#include enum class UndoCommand: char { AddPatternPiece, AddToCalc, @@ -41,4 +44,26 @@ enum class UndoCommand: char { AddPatternPiece, DeletePatternPiece }; -#endif // UNDOCOMMANDS_H +class VPattern; + +class VUndoCommand : public QObject, public QUndoCommand +{ + Q_OBJECT +public: + VUndoCommand(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0); + virtual ~VUndoCommand(); +signals: + void ClearScene(); + void NeedFullParsing(); + void NeedLiteParsing(); +protected: + QDomElement xml; + VPattern *doc; + quint32 nodeId; + bool redoFlag; + void RedoFullParsing(); +private: + Q_DISABLE_COPY(VUndoCommand) +}; + +#endif // VUNDOCOMMAND_H diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 59ec3d45b..7ebbbc6e6 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -112,6 +112,7 @@ public: bool CheckNamePP(const QString& name) const; int CountPP() const; QRectF ActiveDrawBoundingRect() const; + quint32 GetParametrId(const QDomElement& domElement) const; signals: /** * @brief ChangedActivDraw change active pattern peace. @@ -198,7 +199,6 @@ private: void ParseToolsElement(VMainGraphicsScene *scene, const QDomElement& domElement, const Document &parse, const QString& type); void ParseIncrementsElement(const QDomNode& node); - quint32 GetParametrId(const QDomElement& domElement) const; void CollectId(const QDomElement &node, QVector &vector)const; void PrepareForParse(const Document &parse); void UpdateMeasurements();