Refactoring undocommands move label.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-05-13 18:05:35 +03:00
parent fc4054e49e
commit c8a041e4f2
12 changed files with 238 additions and 290 deletions

View File

@ -38,7 +38,7 @@
#include "../../../visualization/line/vistoolrotation.h" #include "../../../visualization/line/vistoolrotation.h"
#include "../vwidgets/vsimplepoint.h" #include "../vwidgets/vsimplepoint.h"
#include "../vwidgets/vsimplecurve.h" #include "../vwidgets/vsimplecurve.h"
#include "../../../undocommands/rotationmovelabel.h" #include "../../../undocommands/label/rotationmovelabel.h"
const QString VToolRotation::TagName = QStringLiteral("operation"); const QString VToolRotation::TagName = QStringLiteral("operation");
const QString VToolRotation::TagItem = QStringLiteral("item"); const QString VToolRotation::TagItem = QStringLiteral("item");
@ -703,7 +703,7 @@ void VToolRotation::DoChangePosition(quint32 id, qreal mx, qreal my)
void VToolRotation::UpdateNamePosition(quint32 id) void VToolRotation::UpdateNamePosition(quint32 id)
{ {
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id); const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
auto moveLabel = new RotationMoveLabel(this->id, doc, point->mx(), point->my(), id, scene()); auto moveLabel = new RotationMoveLabel(this->id, doc, point->mx(), point->my(), id);
connect(moveLabel, &RotationMoveLabel::ChangePosition, this, &VToolRotation::DoChangePosition); connect(moveLabel, &RotationMoveLabel::ChangePosition, this, &VToolRotation::DoChangePosition);
qApp->getUndoStack()->push(moveLabel); qApp->getUndoStack()->push(moveLabel);
} }

View File

@ -29,7 +29,7 @@
#include "vtooldoublepoint.h" #include "vtooldoublepoint.h"
#include "../vwidgets/vsimplepoint.h" #include "../vwidgets/vsimplepoint.h"
#include "../vgeometry/vpointf.h" #include "../vgeometry/vpointf.h"
#include "../../../../undocommands/movedoublelabel.h" #include "../../../../undocommands/label/movedoublelabel.h"
#include <QKeyEvent> #include <QKeyEvent>
@ -244,7 +244,7 @@ void VToolDoublePoint::UpdateNamePosition(quint32 id)
{ {
const VPointF *p1 = VAbstractTool::data.GeometricObject<VPointF>(p1id).data(); const VPointF *p1 = VAbstractTool::data.GeometricObject<VPointF>(p1id).data();
auto moveLabel = new MoveDoubleLabel(doc, p1->mx(), p1->my(), DoublePoint::FirstPoint, this->id, p1id, scene()); auto moveLabel = new MoveDoubleLabel(doc, p1->mx(), p1->my(), DoublePoint::FirstPoint, this->id, p1id);
connect(moveLabel, &MoveDoubleLabel::ChangePosition, this, &VToolDoublePoint::DoChangePosition); connect(moveLabel, &MoveDoubleLabel::ChangePosition, this, &VToolDoublePoint::DoChangePosition);
qApp->getUndoStack()->push(moveLabel); qApp->getUndoStack()->push(moveLabel);
} }
@ -252,8 +252,7 @@ void VToolDoublePoint::UpdateNamePosition(quint32 id)
{ {
const VPointF *p2 = VAbstractTool::data.GeometricObject<VPointF>(p2id).data(); const VPointF *p2 = VAbstractTool::data.GeometricObject<VPointF>(p2id).data();
auto moveLabel = new MoveDoubleLabel(doc, p2->mx(), p2->my(), DoublePoint::SecondPoint, this->id, p2id, auto moveLabel = new MoveDoubleLabel(doc, p2->mx(), p2->my(), DoublePoint::SecondPoint, this->id, p2id);
scene());
connect(moveLabel, &MoveDoubleLabel::ChangePosition, this, &VToolDoublePoint::DoChangePosition); connect(moveLabel, &MoveDoubleLabel::ChangePosition, this, &VToolDoublePoint::DoChangePosition);
qApp->getUndoStack()->push(moveLabel); qApp->getUndoStack()->push(moveLabel);
} }

View File

@ -30,7 +30,7 @@
#include "../vmisc/logging.h" #include "../vmisc/logging.h"
#include "../vgeometry/vpointf.h" #include "../vgeometry/vpointf.h"
#include "../vwidgets/vgraphicssimpletextitem.h" #include "../vwidgets/vgraphicssimpletextitem.h"
#include "../../../../undocommands/movelabel.h" #include "../../../../undocommands/label/movelabel.h"
#include <QKeyEvent> #include <QKeyEvent>
@ -122,7 +122,7 @@ void VToolSinglePoint::NameChangePosition(const QPointF &pos)
void VToolSinglePoint::UpdateNamePosition(quint32 id) void VToolSinglePoint::UpdateNamePosition(quint32 id)
{ {
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id); const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
auto moveLabel = new MoveLabel(doc, point->mx(), point->my(), id, scene()); auto moveLabel = new MoveLabel(doc, point->mx(), point->my(), id);
connect(moveLabel, &MoveLabel::ChangePosition, this, &VToolSinglePoint::DoChangePosition); connect(moveLabel, &MoveLabel::ChangePosition, this, &VToolSinglePoint::DoChangePosition);
qApp->getUndoStack()->push(moveLabel); qApp->getUndoStack()->push(moveLabel);
} }

View File

@ -0,0 +1,73 @@
/************************************************************************
**
** @file moveabstractlabel.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 13 5, 2016
**
** @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) 2016 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 "moveabstractlabel.h"
//---------------------------------------------------------------------------------------------------------------------
MoveAbstractLabel::MoveAbstractLabel(VAbstractPattern *doc, quint32 pointId, double x, double y,
QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent),
m_oldMx(0.0),
m_oldMy(0.0),
m_newMx(x),
m_newMy(y),
m_isRedo(false)
{
nodeId = pointId;
qCDebug(vUndo, "Point id %u", nodeId);
qCDebug(vUndo, "Label new Mx %f", m_newMx);
qCDebug(vUndo, "Label new My %f", m_newMy);
}
//---------------------------------------------------------------------------------------------------------------------
MoveAbstractLabel::~MoveAbstractLabel()
{
}
//---------------------------------------------------------------------------------------------------------------------
void MoveAbstractLabel::undo()
{
qCDebug(vUndo, "Undo.");
Do(m_oldMx, m_oldMy);
m_isRedo = true;
emit ChangePosition(nodeId, m_oldMx, m_oldMy);
}
//---------------------------------------------------------------------------------------------------------------------
void MoveAbstractLabel::redo()
{
qCDebug(vUndo, "Redo.");
Do(m_newMx, m_newMy);
if (m_isRedo)
{
emit ChangePosition(nodeId, m_newMx, m_newMy);
}
}

View File

@ -1,14 +1,14 @@
/************************************************************************ /************************************************************************
** **
** @file movelabel.h ** @file moveabstractlabel.h
** @author Roman Telezhynskyi <dismine(at)gmail.com> ** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 25 12, 2014 ** @date 13 5, 2016
** **
** @brief ** @brief
** @copyright ** @copyright
** This source code is part of the Valentine project, a pattern making ** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing. ** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013-2015 Valentina project ** Copyright (C) 2016 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved. ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
** **
** Valentina is free software: you can redistribute it and/or modify ** Valentina is free software: you can redistribute it and/or modify
@ -26,56 +26,55 @@
** **
*************************************************************************/ *************************************************************************/
#ifndef MOVELABEL_H #ifndef MOVEABSTRACTLABEL_H
#define MOVELABEL_H #define MOVEABSTRACTLABEL_H
#include "vundocommand.h" #include "../vundocommand.h"
class QGraphicsScene; class MoveAbstractLabel : public VUndoCommand
class MoveLabel : public VUndoCommand
{ {
Q_OBJECT Q_OBJECT
public: public:
MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, MoveAbstractLabel(VAbstractPattern *doc, quint32 pointId, double x, double y, QUndoCommand *parent = nullptr);
QUndoCommand *parent = 0); virtual ~MoveAbstractLabel();
virtual ~MoveLabel() Q_DECL_OVERRIDE;
virtual void undo() Q_DECL_OVERRIDE; virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE;
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
virtual int id() const Q_DECL_OVERRIDE; quint32 GetPointId() const;
quint32 getPointId() const; double GetNewMx() const;
double getNewMx() const; double GetNewMy() const;
double getNewMy() const;
void Do(double mx, double my);
signals: signals:
void ChangePosition(quint32 id, qreal mx, qreal my); void ChangePosition(quint32 id, qreal mx, qreal my);
protected:
double m_oldMx;
double m_oldMy;
double m_newMx;
double m_newMy;
bool m_isRedo;
virtual void Do(double mx, double my)=0;
private: private:
Q_DISABLE_COPY(MoveLabel) Q_DISABLE_COPY(MoveAbstractLabel)
double oldMx;
double oldMy;
double newMx;
double newMy;
bool isRedo;
QGraphicsScene *scene;
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline quint32 MoveLabel::getPointId() const inline quint32 MoveAbstractLabel::GetPointId() const
{ {
return nodeId; return nodeId;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline double MoveLabel::getNewMx() const inline double MoveAbstractLabel::GetNewMx() const
{ {
return newMx; return m_newMx;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline double MoveLabel::getNewMy() const inline double MoveAbstractLabel::GetNewMy() const
{ {
return newMy; return m_newMy;
} }
#endif // MOVELABEL_H #endif // MOVEABSTRACTLABEL_H

View File

@ -27,21 +27,14 @@
*************************************************************************/ *************************************************************************/
#include "movedoublelabel.h" #include "movedoublelabel.h"
#include "../tools/vabstracttool.h" #include "../vmisc/vabstractapplication.h"
#include "../../vwidgets/vmaingraphicsview.h"
#include <QGraphicsScene>
#include <QDomElement>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, DoublePoint type, MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, DoublePoint type,
quint32 tooId, quint32 pointId, QGraphicsScene *scene, QUndoCommand *parent) quint32 toolId, quint32 pointId, QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent), : MoveAbstractLabel(doc, pointId, x, y, parent),
oldMx(0.0), oldMy(0.0), m_type(type),
newMx(x), newMy(y), m_idTool(toolId)
scene(scene), type(type),
pointId(pointId),
isRedo(false)
{ {
if (type == DoublePoint::FirstPoint) if (type == DoublePoint::FirstPoint)
{ {
@ -51,44 +44,25 @@ MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const d
{ {
setText(tr("move the second dart label")); setText(tr("move the second dart label"));
} }
nodeId = tooId;
qCDebug(vUndo, "Point id %u", nodeId);
if (type == DoublePoint::FirstPoint) const QDomElement domElement = doc->elementById(m_idTool);
{
qCDebug(vUndo, "Label new Mx1 %f", newMx);
qCDebug(vUndo, "Label new My1 %f", newMy);
}
else
{
qCDebug(vUndo, "Label new Mx2 %f", newMx);
qCDebug(vUndo, "Label new My2 %f", newMy);
}
SCASSERT(scene != nullptr);
QDomElement domElement = doc->elementById(tooId);
if (domElement.isElement()) if (domElement.isElement())
{ {
if (type == DoublePoint::FirstPoint) if (type == DoublePoint::FirstPoint)
{ {
oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx1, "0.0")); m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx1, "0.0"));
oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy1, "0.0")); m_oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy1, "0.0"));
}
else
{
oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx2, "0.0"));
oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy2, "0.0"));
}
if (type == DoublePoint::FirstPoint) qCDebug(vUndo, "Label old Mx1 %f", m_oldMx);
{ qCDebug(vUndo, "Label old My1 %f", m_oldMy);
qCDebug(vUndo, "Label old Mx1 %f", oldMx);
qCDebug(vUndo, "Label old My1 %f", oldMy);
} }
else else
{ {
qCDebug(vUndo, "Label old Mx2 %f", oldMx); m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx2, "0.0"));
qCDebug(vUndo, "Label old My2 %f", oldMy); m_oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy2, "0.0"));
qCDebug(vUndo, "Label old Mx2 %f", m_oldMx);
qCDebug(vUndo, "Label old My2 %f", m_oldMy);
} }
} }
else else
@ -102,52 +76,31 @@ MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const d
MoveDoubleLabel::~MoveDoubleLabel() MoveDoubleLabel::~MoveDoubleLabel()
{} {}
//---------------------------------------------------------------------------------------------------------------------
void MoveDoubleLabel::undo()
{
qCDebug(vUndo, "Undo.");
Do(oldMx, oldMy);
isRedo = true;
emit ChangePosition(pointId, oldMx, oldMy);
}
//---------------------------------------------------------------------------------------------------------------------
void MoveDoubleLabel::redo()
{
qCDebug(vUndo, "Redo.");
Do(newMx, newMy);
if (isRedo)
{
emit ChangePosition(pointId, newMx, newMy);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool MoveDoubleLabel::mergeWith(const QUndoCommand *command) bool MoveDoubleLabel::mergeWith(const QUndoCommand *command)
{ {
const MoveDoubleLabel *moveCommand = static_cast<const MoveDoubleLabel *>(command); const MoveDoubleLabel *moveCommand = static_cast<const MoveDoubleLabel *>(command);
SCASSERT(moveCommand != nullptr); SCASSERT(moveCommand != nullptr);
if (moveCommand->getPointId() != nodeId || moveCommand->getPointType() != type || if (moveCommand->GetPointId() != nodeId ||
moveCommand->getLabelId() != pointId) moveCommand->GetPointType() != m_type ||
moveCommand->GetToolId() != m_idTool)
{ {
return false; return false;
} }
newMx = moveCommand->getNewMx(); m_newMx = moveCommand->GetNewMx();
newMy = moveCommand->getNewMy(); m_newMy = moveCommand->GetNewMy();
if (type == DoublePoint::FirstPoint) if (m_type == DoublePoint::FirstPoint)
{ {
qCDebug(vUndo, "Label new Mx1 %f", newMx); qCDebug(vUndo, "Label new Mx1 %f", m_newMx);
qCDebug(vUndo, "Label new My1 %f", newMy); qCDebug(vUndo, "Label new My1 %f", m_newMy);
} }
else else
{ {
qCDebug(vUndo, "Label new Mx2 %f", newMx); qCDebug(vUndo, "Label new Mx2 %f", m_newMx);
qCDebug(vUndo, "Label new My2 %f", newMy); qCDebug(vUndo, "Label new My2 %f", m_newMy);
} }
return true; return true;
} }
@ -158,16 +111,10 @@ int MoveDoubleLabel::id() const
return static_cast<int>(UndoCommand::MoveDoubleLabel); return static_cast<int>(UndoCommand::MoveDoubleLabel);
} }
//---------------------------------------------------------------------------------------------------------------------
quint32 MoveDoubleLabel::getLabelId() const
{
return pointId;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MoveDoubleLabel::Do(double mx, double my) void MoveDoubleLabel::Do(double mx, double my)
{ {
if (type == DoublePoint::FirstPoint) if (m_type == DoublePoint::FirstPoint)
{ {
qCDebug(vUndo, "New mx1 %f", mx); qCDebug(vUndo, "New mx1 %f", mx);
qCDebug(vUndo, "New my1 %f", my); qCDebug(vUndo, "New my1 %f", my);
@ -178,10 +125,10 @@ void MoveDoubleLabel::Do(double mx, double my)
qCDebug(vUndo, "New my2 %f", my); qCDebug(vUndo, "New my2 %f", my);
} }
QDomElement domElement = doc->elementById(nodeId); QDomElement domElement = doc->elementById(m_idTool);
if (domElement.isElement()) if (domElement.isElement())
{ {
if (type == DoublePoint::FirstPoint) if (m_type == DoublePoint::FirstPoint)
{ {
doc->SetAttribute(domElement, AttrMx1, QString().setNum(qApp->fromPixel(mx))); doc->SetAttribute(domElement, AttrMx1, QString().setNum(qApp->fromPixel(mx)));
doc->SetAttribute(domElement, AttrMy1, QString().setNum(qApp->fromPixel(my))); doc->SetAttribute(domElement, AttrMy1, QString().setNum(qApp->fromPixel(my)));

View File

@ -29,65 +29,41 @@
#ifndef MOVEDOUBLELABEL_H #ifndef MOVEDOUBLELABEL_H
#define MOVEDOUBLELABEL_H #define MOVEDOUBLELABEL_H
#include "vundocommand.h" #include "moveabstractlabel.h"
class QGraphicsScene;
enum class DoublePoint: char { FirstPoint, SecondPoint }; enum class DoublePoint: char { FirstPoint, SecondPoint };
class MoveDoubleLabel : public VUndoCommand class MoveDoubleLabel : public MoveAbstractLabel
{ {
Q_OBJECT Q_OBJECT
public: public:
MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, DoublePoint type, MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, DoublePoint type,
quint32 tooId, quint32 pointId, QGraphicsScene *scene, QUndoCommand *parent = 0); quint32 toolId, quint32 pointId, QUndoCommand *parent = 0);
virtual ~MoveDoubleLabel() Q_DECL_OVERRIDE; virtual ~MoveDoubleLabel() Q_DECL_OVERRIDE;
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
virtual int id() const Q_DECL_OVERRIDE; virtual int id() const Q_DECL_OVERRIDE;
quint32 getPointId() const;
quint32 getLabelId() const; quint32 GetToolId() const;
double getNewMx() const; DoublePoint GetPointType() const;
double getNewMy() const; protected:
DoublePoint getPointType() const; virtual void Do(double mx, double my) Q_DECL_OVERRIDE;
void Do(double mx, double my);
signals:
void ChangePosition(quint32 id, qreal mx, qreal my);
private: private:
Q_DISABLE_COPY(MoveDoubleLabel) Q_DISABLE_COPY(MoveDoubleLabel)
double oldMx; DoublePoint m_type;
double oldMy; quint32 m_idTool;
double newMx;
double newMy;
QGraphicsScene *scene;
DoublePoint type;
quint32 pointId;
bool isRedo;
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline quint32 MoveDoubleLabel::getPointId() const inline DoublePoint MoveDoubleLabel::GetPointType() const
{ {
return nodeId; return m_type;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline DoublePoint MoveDoubleLabel::getPointType() const inline quint32 MoveDoubleLabel::GetToolId() const
{ {
return type; return m_idTool;
}
//---------------------------------------------------------------------------------------------------------------------
inline double MoveDoubleLabel::getNewMx() const
{
return newMx;
}
//---------------------------------------------------------------------------------------------------------------------
inline double MoveDoubleLabel::getNewMy() const
{
return newMy;
} }
#endif // MOVEDOUBLELABEL_H #endif // MOVEDOUBLELABEL_H

View File

@ -27,33 +27,22 @@
*************************************************************************/ *************************************************************************/
#include "movelabel.h" #include "movelabel.h"
#include "../tools/vabstracttool.h" #include "../vmisc/vabstractapplication.h"
#include "../../vwidgets/vmaingraphicsview.h"
#include <QGraphicsScene>
#include <QDomElement>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QUndoCommand *parent)
QUndoCommand *parent) : MoveAbstractLabel(doc, id, x, y, parent)
: VUndoCommand(QDomElement(), doc, parent), oldMx(0.0), oldMy(0.0), newMx(x), newMy(y), isRedo(false), scene(scene)
{ {
setText(tr("move point label")); setText(tr("move point label"));
nodeId = id;
qCDebug(vUndo, "Point id %u", nodeId);
qCDebug(vUndo, "Label new Mx %f", newMx); QDomElement domElement = doc->elementById(nodeId);
qCDebug(vUndo, "Label new My %f", newMy);
SCASSERT(scene != nullptr);
QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0")); m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0"));
oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0")); m_oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0"));
qCDebug(vUndo, "Label old Mx %f", oldMx); qCDebug(vUndo, "Label old Mx %f", m_oldMx);
qCDebug(vUndo, "Label old My %f", oldMy); qCDebug(vUndo, "Label old My %f", m_oldMy);
} }
else else
{ {
@ -66,45 +55,22 @@ MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, co
MoveLabel::~MoveLabel() MoveLabel::~MoveLabel()
{} {}
//---------------------------------------------------------------------------------------------------------------------
void MoveLabel::undo()
{
qCDebug(vUndo, "Undo.");
Do(oldMx, oldMy);
isRedo = true;
emit ChangePosition(nodeId, oldMx, oldMy);
}
//---------------------------------------------------------------------------------------------------------------------
void MoveLabel::redo()
{
qCDebug(vUndo, "Redo.");
Do(newMx, newMy);
if (isRedo)
{
emit ChangePosition(nodeId, newMx, newMy);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool MoveLabel::mergeWith(const QUndoCommand *command) bool MoveLabel::mergeWith(const QUndoCommand *command)
{ {
const MoveLabel *moveCommand = static_cast<const MoveLabel *>(command); const MoveLabel *moveCommand = static_cast<const MoveLabel *>(command);
SCASSERT(moveCommand != nullptr); SCASSERT(moveCommand != nullptr);
const quint32 id = moveCommand->getPointId();
if (id != nodeId) if (moveCommand->GetPointId() != nodeId)
{ {
return false; return false;
} }
qCDebug(vUndo, "Mergin undo."); qCDebug(vUndo, "Mergin undo.");
newMx = moveCommand->getNewMx(); m_newMx = moveCommand->GetNewMx();
newMy = moveCommand->getNewMy(); m_newMy = moveCommand->GetNewMy();
qCDebug(vUndo, "Label new Mx %f", newMx); qCDebug(vUndo, "Label new Mx %f", m_newMx);
qCDebug(vUndo, "Label new My %f", newMy); qCDebug(vUndo, "Label new My %f", m_newMy);
return true; return true;
} }

View File

@ -0,0 +1,49 @@
/************************************************************************
**
** @file movelabel.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 25 12, 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) 2013-2015 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 MOVELABEL_H
#define MOVELABEL_H
#include "moveabstractlabel.h"
class MoveLabel : public MoveAbstractLabel
{
Q_OBJECT
public:
MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QUndoCommand *parent = 0);
virtual ~MoveLabel();
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
virtual int id() const Q_DECL_OVERRIDE;
protected:
virtual void Do(double mx, double my) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(MoveLabel)
};
#endif // MOVELABEL_H

View File

@ -27,30 +27,19 @@
*************************************************************************/ *************************************************************************/
#include "rotationmovelabel.h" #include "rotationmovelabel.h"
#include "../tools/drawTools/operation/vtoolrotation.h" #include "../../tools/drawTools/operation/vtoolrotation.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
RotationMoveLabel::RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, RotationMoveLabel::RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint,
QGraphicsScene *scene, QUndoCommand *parent) QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent), : MoveAbstractLabel(doc, idPoint, x, y, parent),
m_oldMx(0.0),
m_oldMy(0.0),
m_newMx(x),
m_newMy(y),
m_isRedo(false),
m_scene(scene),
m_idTool(idTool) m_idTool(idTool)
{ {
setText(tr("move point label")); setText(tr("move point label"));
nodeId = idPoint;
qCDebug(vUndo, "Tool id %u", m_idTool); qCDebug(vUndo, "Tool id %u", m_idTool);
qCDebug(vUndo, "Point id %u", nodeId);
qCDebug(vUndo, "Label new Mx %f", m_newMx); const QDomElement element = GetDestinationObject(m_idTool, nodeId);
qCDebug(vUndo, "Label new My %f", m_newMy);
SCASSERT(scene != nullptr);
QDomElement element = GetDestinationObject(m_idTool, nodeId);
if (element.isElement()) if (element.isElement())
{ {
m_oldMx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, "0.0")); m_oldMx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, "0.0"));
@ -71,28 +60,6 @@ RotationMoveLabel::~RotationMoveLabel()
{ {
} }
//---------------------------------------------------------------------------------------------------------------------
void RotationMoveLabel::undo()
{
qCDebug(vUndo, "Undo.");
Do(m_oldMx, m_oldMy);
m_isRedo = true;
emit ChangePosition(nodeId, m_oldMx, m_oldMy);
}
//---------------------------------------------------------------------------------------------------------------------
void RotationMoveLabel::redo()
{
qCDebug(vUndo, "Redo.");
Do(m_newMx, m_newMy);
if (m_isRedo)
{
emit ChangePosition(nodeId, m_newMx, m_newMy);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool RotationMoveLabel::mergeWith(const QUndoCommand *command) bool RotationMoveLabel::mergeWith(const QUndoCommand *command)
{ {
@ -105,8 +72,8 @@ bool RotationMoveLabel::mergeWith(const QUndoCommand *command)
} }
qCDebug(vUndo, "Mergin undo."); qCDebug(vUndo, "Mergin undo.");
m_newMx = moveCommand->getNewMx(); m_newMx = moveCommand->GetNewMx();
m_newMy = moveCommand->getNewMy(); m_newMy = moveCommand->GetNewMy();
qCDebug(vUndo, "Label new Mx %f", m_newMx); qCDebug(vUndo, "Label new Mx %f", m_newMx);
qCDebug(vUndo, "Label new My %f", m_newMy); qCDebug(vUndo, "Label new My %f", m_newMy);
return true; return true;

View File

@ -29,59 +29,29 @@
#ifndef ROTATIONMOVELABEL_H #ifndef ROTATIONMOVELABEL_H
#define ROTATIONMOVELABEL_H #define ROTATIONMOVELABEL_H
#include "vundocommand.h" #include "moveabstractlabel.h"
class QGraphicsScene; class RotationMoveLabel : public MoveAbstractLabel
class RotationMoveLabel : public VUndoCommand
{ {
Q_OBJECT Q_OBJECT
public: public:
RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, QGraphicsScene *scene, RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint,
QUndoCommand *parent = nullptr); QUndoCommand *parent = nullptr);
virtual ~RotationMoveLabel(); virtual ~RotationMoveLabel();
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
virtual int id() const Q_DECL_OVERRIDE; virtual int id() const Q_DECL_OVERRIDE;
quint32 GetPointId() const;
quint32 GetToolId() const; quint32 GetToolId() const;
double getNewMx() const; protected:
double getNewMy() const; virtual void Do(double mx, double my) Q_DECL_OVERRIDE;
signals:
void ChangePosition(quint32 id, qreal mx, qreal my);
private: private:
Q_DISABLE_COPY(RotationMoveLabel) Q_DISABLE_COPY(RotationMoveLabel)
double m_oldMx;
double m_oldMy;
double m_newMx;
double m_newMy;
bool m_isRedo;
QGraphicsScene *m_scene;
quint32 m_idTool; quint32 m_idTool;
void Do(double mx, double my);
QDomElement GetDestinationObject(quint32 idTool, quint32 idPoint) const; QDomElement GetDestinationObject(quint32 idTool, quint32 idPoint) const;
}; };
//---------------------------------------------------------------------------------------------------------------------
inline quint32 RotationMoveLabel::GetPointId() const
{
return nodeId;
}
//---------------------------------------------------------------------------------------------------------------------
inline double RotationMoveLabel::getNewMx() const
{
return m_newMx;
}
//---------------------------------------------------------------------------------------------------------------------
inline double RotationMoveLabel::getNewMy() const
{
return m_newMy;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline quint32 RotationMoveLabel::GetToolId() const inline quint32 RotationMoveLabel::GetToolId() const
{ {

View File

@ -17,11 +17,12 @@ HEADERS += \
$$PWD/deletedetail.h \ $$PWD/deletedetail.h \
$$PWD/vundocommand.h \ $$PWD/vundocommand.h \
$$PWD/renamepp.h \ $$PWD/renamepp.h \
$$PWD/movelabel.h \ $$PWD/label/movelabel.h \
$$PWD/movedoublelabel.h \ $$PWD/label/movedoublelabel.h \
$$PWD/addgroup.h \ $$PWD/addgroup.h \
$$PWD/delgroup.h \ $$PWD/delgroup.h \
$$PWD/rotationmovelabel.h $$PWD/label/rotationmovelabel.h \
undocommands/label/moveabstractlabel.h
SOURCES += \ SOURCES += \
$$PWD/addtocalc.cpp \ $$PWD/addtocalc.cpp \
@ -39,8 +40,9 @@ SOURCES += \
$$PWD/deletedetail.cpp \ $$PWD/deletedetail.cpp \
$$PWD/vundocommand.cpp \ $$PWD/vundocommand.cpp \
$$PWD/renamepp.cpp \ $$PWD/renamepp.cpp \
$$PWD/movelabel.cpp \ $$PWD/label/movelabel.cpp \
$$PWD/movedoublelabel.cpp \ $$PWD/label/movedoublelabel.cpp \
$$PWD/addgroup.cpp \ $$PWD/addgroup.cpp \
$$PWD/delgroup.cpp \ $$PWD/delgroup.cpp \
$$PWD/rotationmovelabel.cpp $$PWD/label/rotationmovelabel.cpp \
undocommands/label/moveabstractlabel.cpp