New undo command MoveSpline.
--HG-- branch : feature
This commit is contained in:
parent
0783cc24e1
commit
cc6ed85407
|
@ -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 \
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <qmuparsererror.h>
|
||||
#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);
|
||||
}
|
||||
|
|
|
@ -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<QGraphicsView*> 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
82
src/app/undocommands/addpatternpiece.cpp
Normal file
82
src/app/undocommands/addpatternpiece.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file addpatternpiece.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @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
|
||||
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#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;
|
||||
}
|
59
src/app/undocommands/addpatternpiece.h
Normal file
59
src/app/undocommands/addpatternpiece.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file addpatternpiece.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @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
|
||||
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef ADDPATTERNPIECE_H
|
||||
#define ADDPATTERNPIECE_H
|
||||
|
||||
#include <QDomElement>
|
||||
#include <QUndoCommand>
|
||||
|
||||
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
|
102
src/app/undocommands/addtocalc.cpp
Normal file
102
src/app/undocommands/addtocalc.cpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file addtocalc.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @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
|
||||
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#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;
|
||||
}
|
56
src/app/undocommands/addtocalc.h
Normal file
56
src/app/undocommands/addtocalc.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file addtocalc.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @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
|
||||
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef ADDTOCALC_H
|
||||
#define ADDTOCALC_H
|
||||
|
||||
#include <QDomElement>
|
||||
#include <QUndoCommand>
|
||||
|
||||
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
|
104
src/app/undocommands/movespline.cpp
Normal file
104
src/app/undocommands/movespline.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file movespline.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @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
|
||||
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#include "movespline.h"
|
||||
#include "../tools/vabstracttool.h"
|
||||
#include <QDomElement>
|
||||
#include <QGraphicsView>
|
||||
#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<QGraphicsView*> 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<QGraphicsView*> 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<const MoveSpline *>(command);
|
||||
SCASSERT(moveCommand != nullptr);
|
||||
const quint32 id = moveCommand->getSplineId();
|
||||
|
||||
if (id != splineId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
newSpline = moveCommand->getNewSpline();
|
||||
return true;
|
||||
}
|
81
src/app/undocommands/movespline.h
Normal file
81
src/app/undocommands/movespline.h
Normal file
|
@ -0,0 +1,81 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file movespline.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @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
|
||||
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef MOVESPLINE_H
|
||||
#define MOVESPLINE_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
#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
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vundocommands.cpp
|
||||
** @file movespoint.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 4 6, 2014
|
||||
** @date 9 6, 2014
|
||||
**
|
||||
** @brief
|
||||
** @copyright
|
||||
|
@ -26,137 +26,13 @@
|
|||
**
|
||||
*************************************************************************/
|
||||
|
||||
#include "vundocommands.h"
|
||||
#include <QDebug>
|
||||
#include "../widgets/vapplication.h"
|
||||
#include "movespoint.h"
|
||||
#include <QGraphicsScene>
|
||||
#include <QDomElement>
|
||||
#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)
|
|
@ -1,8 +1,8 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vundocommands.h
|
||||
** @file movespoint.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @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 <QDomElement>
|
||||
#include <QGraphicsScene>
|
||||
#include <QUndoCommand>
|
||||
|
||||
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
|
13
src/app/undocommands/undocommands.pri
Normal file
13
src/app/undocommands/undocommands.pri
Normal file
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user