From cc6ed85407d95ffbd3fa300daa08eda28a3bfc81 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 9 Jun 2014 20:39:18 +0300 Subject: [PATCH] New undo command MoveSpline. --HG-- branch : feature --- src/app/app.pro | 1 + src/app/tools/drawTools/vdrawtool.cpp | 6 +- src/app/tools/drawTools/vtoolsinglepoint.cpp | 17 +-- src/app/tools/drawTools/vtoolspline.cpp | 16 +- src/app/undocommands/addpatternpiece.cpp | 82 +++++++++++ src/app/undocommands/addpatternpiece.h | 59 ++++++++ src/app/undocommands/addtocalc.cpp | 102 +++++++++++++ src/app/undocommands/addtocalc.h | 56 +++++++ src/app/undocommands/movespline.cpp | 104 +++++++++++++ src/app/undocommands/movespline.h | 81 ++++++++++ .../movespoint.cpp} | 138 +----------------- .../movespoint.h} | 58 +------- src/app/undocommands/undocommands.pri | 13 ++ src/app/xml/xml.pri | 6 +- 14 files changed, 524 insertions(+), 215 deletions(-) create mode 100644 src/app/undocommands/addpatternpiece.cpp create mode 100644 src/app/undocommands/addpatternpiece.h create mode 100644 src/app/undocommands/addtocalc.cpp create mode 100644 src/app/undocommands/addtocalc.h create mode 100644 src/app/undocommands/movespline.cpp create mode 100644 src/app/undocommands/movespline.h rename src/app/{xml/vundocommands.cpp => undocommands/movespoint.cpp} (51%) rename src/app/{xml/vundocommands.h => undocommands/movespoint.h} (65%) create mode 100644 src/app/undocommands/undocommands.pri diff --git a/src/app/app.pro b/src/app/app.pro index 27519ff73..40ba0d1a0 100644 --- a/src/app/app.pro +++ b/src/app/app.pro @@ -41,6 +41,7 @@ include(geometry/geometry.pri) include(tools/tools.pri) include(widgets/widgets.pri) include(xml/xml.pri) +include(undocommands/undocommands.pri) SOURCES += \ main.cpp \ diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 253384ed9..7cfa9665e 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -31,7 +31,7 @@ #include #include "dialogs/tools/dialogeditwrongformula.h" #include "container/calculator.h" -#include "../../xml/vundocommands.h" +#include "../../undocommands/addtocalc.h" qreal VDrawTool::factor = 1; @@ -190,7 +190,7 @@ qreal VDrawTool::CheckFormula(QString &formula, VContainer *data) */ void VDrawTool::AddToCalculation(const QDomElement &domElement) { - AddToCal *addToCal = new AddToCal(domElement, doc); - connect(addToCal, &AddToCal::NeedFullParsing, doc, &VPattern::NeedFullParsing); + AddToCalc *addToCal = new AddToCalc(domElement, doc); + connect(addToCal, &AddToCalc::NeedFullParsing, doc, &VPattern::NeedFullParsing); qApp->getUndoStack()->push(addToCal); } diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 59c870614..78479971f 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -29,7 +29,8 @@ #include "vtoolsinglepoint.h" #include "../../dialogs/tools/dialogsinglepoint.h" #include "../../widgets/vgraphicssimpletextitem.h" -#include "../../xml/vundocommands.h" +#include "../../undocommands/movespoint.h" +#include "../../undocommands/addpatternpiece.h" #include "../../geometry/vpointf.h" const QString VToolSinglePoint::ToolType = QStringLiteral("single"); @@ -141,20 +142,6 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, MoveSPoint *moveSP = new MoveSPoint(doc, newPos.x(), newPos.y(), id, this->scene()); connect(moveSP, &MoveSPoint::NeedLiteParsing, doc, &VPattern::LiteParseTree); qApp->getUndoStack()->push(moveSP); - -// QDomElement domElement = doc->elementById(QString().setNum(id)); -// if (domElement.isElement()) -// { -// doc->SetAttribute(domElement, AttrX, QString().setNum(qApp->fromPixel(newPos.x()))); -// doc->SetAttribute(domElement, AttrY, QString().setNum(qApp->fromPixel(newPos.y()))); - -// QList list = this->scene()->views(); -// VAbstractTool::NewSceneRect(this->scene(), list[0]); - -// //I don't now why but signal does not work. -// doc->LiteParseTree(); -// emit toolhaveChange(); -// } } return QGraphicsItem::itemChange(change, value); } diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 0e0a5e844..3bb061074 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -29,6 +29,7 @@ #include "vtoolspline.h" #include "../../geometry/vspline.h" #include "../../dialogs/tools/dialogspline.h" +#include "../../undocommands/movespline.h" const QString VToolSpline::ToolType = QStringLiteral("simple"); @@ -158,17 +159,10 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const Sp { spl = VSpline(spline->GetP1(), spline->GetP2(), pos, spline->GetP4(), spline->GetKcurve()); } - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrAngle1, QString().setNum(spl.GetAngle1())); - doc->SetAttribute(domElement, AttrAngle2, QString().setNum(spl.GetAngle2())); - doc->SetAttribute(domElement, AttrKAsm1, QString().setNum(spl.GetKasm1())); - doc->SetAttribute(domElement, AttrKAsm2, QString().setNum(spl.GetKasm2())); - doc->SetAttribute(domElement, AttrKCurve, QString().setNum(spl.GetKcurve())); - emit FullUpdateTree(); - emit toolhaveChange(); - } + + MoveSpline *moveSpl = new MoveSpline(doc, spline, spl, id, this->scene()); + connect(moveSpl, &MoveSpline::NeedLiteParsing, doc, &VPattern::LiteParseTree); + qApp->getUndoStack()->push(moveSpl); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/undocommands/addpatternpiece.cpp b/src/app/undocommands/addpatternpiece.cpp new file mode 100644 index 000000000..76b87d584 --- /dev/null +++ b/src/app/undocommands/addpatternpiece.cpp @@ -0,0 +1,82 @@ +/************************************************************************ + ** + ** @file addpatternpiece.cpp + ** @author Roman Telezhynskyi + ** @date 9 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 "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) + : QObject(), QUndoCommand(parent), xml(xml), doc(doc), namePP(namePP), redoFlag(false), mPath(mPath) +{ + setText(tr("Add pattern piece %1").arg(namePP)); +} + +//--------------------------------------------------------------------------------------------------------------------- +AddPatternPiece::~AddPatternPiece() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void AddPatternPiece::undo() +{ + if (countPP <= 1) + { + emit ClearScene(); + } + else + { + QDomElement rootElement = doc->documentElement(); + QDomElement patternPiece = doc->GetPPElement(namePP); + rootElement.removeChild(patternPiece); + emit NeedFullParsing(); + } + --countPP; +} + +//--------------------------------------------------------------------------------------------------------------------- +void AddPatternPiece::redo() +{ + ++countPP; + if (countPP == 1 && mPath.isEmpty() == false) + { + doc->CreateEmptyFile(mPath); + } + + QDomElement rootElement = doc->documentElement(); + + rootElement.appendChild(xml); + doc->haveLiteChange(); + + if (redoFlag) + { + emit NeedFullParsing(); + } + redoFlag = true; +} diff --git a/src/app/undocommands/addpatternpiece.h b/src/app/undocommands/addpatternpiece.h new file mode 100644 index 000000000..24f240239 --- /dev/null +++ b/src/app/undocommands/addpatternpiece.h @@ -0,0 +1,59 @@ +/************************************************************************ + ** + ** @file addpatternpiece.h + ** @author Roman Telezhynskyi + ** @date 9 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 ADDPATTERNPIECE_H +#define ADDPATTERNPIECE_H + +#include +#include + +class VPattern; + +class AddPatternPiece : public QObject, public QUndoCommand +{ + Q_OBJECT +public: + AddPatternPiece(const QDomElement &xml, VPattern *doc, const QString &namePP, const QString &mPath, + QUndoCommand *parent = 0); + virtual ~AddPatternPiece(); + virtual void undo(); + virtual void redo(); +signals: + void ClearScene(); + void NeedFullParsing(); +private: + Q_DISABLE_COPY(AddPatternPiece) + const QDomElement xml; + VPattern *doc; + static int countPP; + QString namePP; + bool redoFlag; + QString mPath; +}; + +#endif // ADDPATTERNPIECE_H diff --git a/src/app/undocommands/addtocalc.cpp b/src/app/undocommands/addtocalc.cpp new file mode 100644 index 000000000..c8d9b3dd3 --- /dev/null +++ b/src/app/undocommands/addtocalc.cpp @@ -0,0 +1,102 @@ +/************************************************************************ + ** + ** @file addtocalc.cpp + ** @author Roman Telezhynskyi + ** @date 9 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 "addtocalc.h" +#include "../xml/vpattern.h" + +//--------------------------------------------------------------------------------------------------------------------- +AddToCalc::AddToCalc(const QDomElement &xml, VPattern *doc, QUndoCommand *parent) + : QObject(), QUndoCommand(parent), xml(xml), doc(doc), nameActivDraw(doc->GetNameActivDraw()), + cursor(doc->getCursor()), redoFlag(false) +{ + setText(tr("Add object")); +} + +//--------------------------------------------------------------------------------------------------------------------- +AddToCalc::~AddToCalc() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void AddToCalc::undo() +{ + doc->ChangeActivPP(nameActivDraw); + doc->setCursor(cursor); + + QDomElement calcElement; + if (doc->GetActivNodeElement(VPattern::TagCalculation, calcElement)) + { + calcElement.removeChild(xml); + if (cursor > 0) + { + doc->setCursor(0); + } + } + else + { + qDebug()<<"Can't find tag Calculation"<< Q_FUNC_INFO; + } + emit NeedFullParsing(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void AddToCalc::redo() +{ + doc->ChangeActivPP(nameActivDraw); + doc->setCursor(cursor); + + QDomElement calcElement; + if (doc->GetActivNodeElement(VPattern::TagCalculation, calcElement)) + { + if (cursor <= 0) + { + calcElement.appendChild(xml); + } + else + { + QDomElement refElement = doc->elementById(QString().setNum(cursor)); + if (refElement.isElement()) + { + calcElement.insertAfter(xml, refElement); + doc->setCursor(0); + } + else + { + qDebug()<<"Can not find the element after which you want to insert."<< Q_FUNC_INFO; + } + } + } + else + { + qDebug()<<"Can't find tag Calculation"<< Q_FUNC_INFO; + } + if (redoFlag) + { + emit NeedFullParsing(); + } + redoFlag = true; +} diff --git a/src/app/undocommands/addtocalc.h b/src/app/undocommands/addtocalc.h new file mode 100644 index 000000000..143f19aa4 --- /dev/null +++ b/src/app/undocommands/addtocalc.h @@ -0,0 +1,56 @@ +/************************************************************************ + ** + ** @file addtocalc.h + ** @author Roman Telezhynskyi + ** @date 9 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 ADDTOCALC_H +#define ADDTOCALC_H + +#include +#include + +class VPattern; + +class AddToCalc : public QObject, public QUndoCommand +{ + Q_OBJECT +public: + AddToCalc(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0); + 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; +}; + +#endif // ADDTOCALC_H diff --git a/src/app/undocommands/movespline.cpp b/src/app/undocommands/movespline.cpp new file mode 100644 index 000000000..0ce52e3ca --- /dev/null +++ b/src/app/undocommands/movespline.cpp @@ -0,0 +1,104 @@ +/************************************************************************ + ** + ** @file movespline.cpp + ** @author Roman Telezhynskyi + ** @date 9 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 "movespline.h" +#include "../tools/vabstracttool.h" +#include +#include +#include "../xml/vpattern.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) +{ + setText(tr("Move spline")); + + SCASSERT(scene != nullptr); +} + +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; + } +} + +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; + } +} + +bool MoveSpline::mergeWith(const QUndoCommand *command) +{ + const MoveSpline *moveCommand = static_cast(command); + SCASSERT(moveCommand != nullptr); + const quint32 id = moveCommand->getSplineId(); + + if (id != splineId) + { + return false; + } + + newSpline = moveCommand->getNewSpline(); + return true; +} diff --git a/src/app/undocommands/movespline.h b/src/app/undocommands/movespline.h new file mode 100644 index 000000000..e01ec40a5 --- /dev/null +++ b/src/app/undocommands/movespline.h @@ -0,0 +1,81 @@ +/************************************************************************ + ** + ** @file movespline.h + ** @author Roman Telezhynskyi + ** @date 9 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 MOVESPLINE_H +#define MOVESPLINE_H + +#include +#include "../geometry/vspline.h" + +class VPattern; +class QGraphicsScene; + +class MoveSpline : public QObject, public QUndoCommand +{ + Q_OBJECT +public: + MoveSpline(VPattern *doc, const VSpline *oldSpl, const VSpline &spl, const quint32 &id, QGraphicsScene *scene, + QUndoCommand *parent = 0); + virtual ~MoveSpline(); + virtual void undo(); + virtual void redo(); + virtual bool mergeWith(const QUndoCommand *command); + virtual int id() const; + quint32 getSplineId() const; + VSpline getNewSpline() const; +signals: + void NeedLiteParsing(); +private: + Q_DISABLE_COPY(MoveSpline) + enum { Id = 1 }; + VPattern *doc; + VSpline oldSpline; + VSpline newSpline; + quint32 splineId; + QGraphicsScene *scene; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline int MoveSpline::id() const +{ + return Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline quint32 MoveSpline::getSplineId() const +{ + return splineId; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline VSpline MoveSpline::getNewSpline() const +{ + return newSpline; +} + +#endif // MOVESPLINE_H diff --git a/src/app/xml/vundocommands.cpp b/src/app/undocommands/movespoint.cpp similarity index 51% rename from src/app/xml/vundocommands.cpp rename to src/app/undocommands/movespoint.cpp index f38f98eb9..20a2796a6 100644 --- a/src/app/xml/vundocommands.cpp +++ b/src/app/undocommands/movespoint.cpp @@ -1,8 +1,8 @@ /************************************************************************ ** - ** @file vundocommands.cpp + ** @file movespoint.cpp ** @author Roman Telezhynskyi - ** @date 4 6, 2014 + ** @date 9 6, 2014 ** ** @brief ** @copyright @@ -26,137 +26,13 @@ ** *************************************************************************/ -#include "vundocommands.h" -#include -#include "../widgets/vapplication.h" +#include "movespoint.h" +#include +#include +#include "../xml/vpattern.h" #include "../tools/vabstracttool.h" +#include "../widgets/vapplication.h" -//--------------------------------------------------------------------------------------------------------------------- -AddToCal::AddToCal(const QDomElement &xml, VPattern *doc, QUndoCommand *parent) - : QObject(), QUndoCommand(parent), xml(xml), doc(doc), nameActivDraw(doc->GetNameActivDraw()), - cursor(doc->getCursor()), redoFlag(false) -{ - setText(tr("Add object")); -} - -//--------------------------------------------------------------------------------------------------------------------- -AddToCal::~AddToCal() -{} - -//--------------------------------------------------------------------------------------------------------------------- -void AddToCal::undo() -{ - doc->ChangeActivPP(nameActivDraw); - doc->setCursor(cursor); - - QDomElement calcElement; - if (doc->GetActivNodeElement(VPattern::TagCalculation, calcElement)) - { - calcElement.removeChild(xml); - if (cursor > 0) - { - doc->setCursor(0); - } - } - else - { - qDebug()<<"Can't find tag Calculation"<< Q_FUNC_INFO; - } - emit NeedFullParsing(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void AddToCal::redo() -{ - doc->ChangeActivPP(nameActivDraw); - doc->setCursor(cursor); - - QDomElement calcElement; - if (doc->GetActivNodeElement(VPattern::TagCalculation, calcElement)) - { - if (cursor <= 0) - { - calcElement.appendChild(xml); - } - else - { - QDomElement refElement = doc->elementById(QString().setNum(cursor)); - if (refElement.isElement()) - { - calcElement.insertAfter(xml, refElement); - doc->setCursor(0); - } - else - { - qDebug()<<"Can not find the element after which you want to insert."<< Q_FUNC_INFO; - } - } - } - else - { - qDebug()<<"Can't find tag Calculation"<< Q_FUNC_INFO; - } - if (redoFlag) - { - emit NeedFullParsing(); - } - redoFlag = true; -} - -//--------------------------------------------AddPatternPiece---------------------------------------------------------- - -int AddPatternPiece::countPP = 0; - -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) -{ - setText(tr("Add pattern piece %1").arg(namePP)); -} - -//--------------------------------------------------------------------------------------------------------------------- -AddPatternPiece::~AddPatternPiece() -{} - -//--------------------------------------------------------------------------------------------------------------------- -void AddPatternPiece::undo() -{ - if (countPP <= 1) - { - emit ClearScene(); - } - else - { - QDomElement rootElement = doc->documentElement(); - QDomElement patternPiece = doc->GetPPElement(namePP); - rootElement.removeChild(patternPiece); - emit NeedFullParsing(); - } - --countPP; -} - -//--------------------------------------------------------------------------------------------------------------------- -void AddPatternPiece::redo() -{ - ++countPP; - if (countPP == 1 && mPath.isEmpty() == false) - { - doc->CreateEmptyFile(mPath); - } - - QDomElement rootElement = doc->documentElement(); - - rootElement.appendChild(xml); - doc->haveLiteChange(); - - if (redoFlag) - { - emit NeedFullParsing(); - } - redoFlag = true; -} - -//--------------------------------------------MoveSPoint--------------------------------------------------------------- MoveSPoint::MoveSPoint(VPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, QUndoCommand *parent) : QObject(), QUndoCommand(parent), doc(doc), oldX(10.0), oldY(10.0), newX(x), newY(y), sPointId(id), scene(scene) diff --git a/src/app/xml/vundocommands.h b/src/app/undocommands/movespoint.h similarity index 65% rename from src/app/xml/vundocommands.h rename to src/app/undocommands/movespoint.h index e1525fda7..050df6482 100644 --- a/src/app/xml/vundocommands.h +++ b/src/app/undocommands/movespoint.h @@ -1,8 +1,8 @@ /************************************************************************ ** - ** @file vundocommands.h + ** @file movespoint.h ** @author Roman Telezhynskyi - ** @date 4 6, 2014 + ** @date 9 6, 2014 ** ** @brief ** @copyright @@ -26,58 +26,14 @@ ** *************************************************************************/ -#ifndef VUNDOCOMMANDS_H -#define VUNDOCOMMANDS_H +#ifndef MOVESPOINT_H +#define MOVESPOINT_H -#include "vpattern.h" - -#include -#include #include -class AddToCal : public QObject, public QUndoCommand -{ - Q_OBJECT -public: - AddToCal(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0); - virtual ~AddToCal(); - virtual void undo(); - virtual void redo(); -signals: - void NeedFullParsing(); -private: - Q_DISABLE_COPY(AddToCal) - const QDomElement xml; - VPattern *doc; - const QString nameActivDraw; - quint32 cursor; - bool redoFlag; -}; +class VPattern; +class QGraphicsScene; -//-------------------------------------------AddPatternPiece----------------------------------------------------------- -class AddPatternPiece : public QObject, public QUndoCommand -{ - Q_OBJECT -public: - AddPatternPiece(const QDomElement &xml, VPattern *doc, const QString &namePP, const QString &mPath, - QUndoCommand *parent = 0); - virtual ~AddPatternPiece(); - virtual void undo(); - virtual void redo(); -signals: - void ClearScene(); - void NeedFullParsing(); -private: - Q_DISABLE_COPY(AddPatternPiece) - const QDomElement xml; - VPattern *doc; - static int countPP; - QString namePP; - bool redoFlag; - QString mPath; -}; - -//---------------------------------------------MoveSPoint-------------------------------------------------------------- class MoveSPoint : public QObject, public QUndoCommand { Q_OBJECT @@ -130,4 +86,4 @@ inline double MoveSPoint::getNewY() const return newY; } -#endif // VUNDOCOMMANDS_H +#endif // MOVESPOINT_H diff --git a/src/app/undocommands/undocommands.pri b/src/app/undocommands/undocommands.pri new file mode 100644 index 000000000..584d56b1a --- /dev/null +++ b/src/app/undocommands/undocommands.pri @@ -0,0 +1,13 @@ +HEADERS += \ + undocommands/addtocalc.h \ + undocommands/addpatternpiece.h \ + undocommands/movespoint.h \ + undocommands/movespline.h + + +SOURCES += \ + undocommands/addtocalc.cpp \ + undocommands/addpatternpiece.cpp \ + undocommands/movespoint.cpp \ + undocommands/movespline.cpp + diff --git a/src/app/xml/xml.pri b/src/app/xml/xml.pri index 274582dca..d9b56eea9 100644 --- a/src/app/xml/xml.pri +++ b/src/app/xml/xml.pri @@ -3,13 +3,11 @@ HEADERS += \ xml/vdomdocument.h \ xml/vpattern.h \ xml/vstandardmeasurements.h \ - xml/vindividualmeasurements.h \ - xml/vundocommands.h + xml/vindividualmeasurements.h SOURCES += \ xml/vtoolrecord.cpp \ xml/vdomdocument.cpp \ xml/vpattern.cpp \ xml/vstandardmeasurements.cpp \ - xml/vindividualmeasurements.cpp \ - xml/vundocommands.cpp + xml/vindividualmeasurements.cpp