From c8a041e4f26120f2acd08daf7d856d8012af8c3f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 13 May 2016 18:05:35 +0300 Subject: [PATCH] Refactoring undocommands move label. --HG-- branch : feature --- .../drawTools/operation/vtoolrotation.cpp | 4 +- .../tooldoublepoint/vtooldoublepoint.cpp | 7 +- .../toolsinglepoint/vtoolsinglepoint.cpp | 4 +- .../undocommands/label/moveabstractlabel.cpp | 73 ++++++++++++ .../moveabstractlabel.h} | 61 +++++----- .../{ => label}/movedoublelabel.cpp | 109 +++++------------- .../{ => label}/movedoublelabel.h | 54 +++------ .../undocommands/{ => label}/movelabel.cpp | 60 +++------- .../vtools/undocommands/label/movelabel.h | 49 ++++++++ .../{ => label}/rotationmovelabel.cpp | 47 ++------ .../{ => label}/rotationmovelabel.h | 46 ++------ src/libs/vtools/undocommands/undocommands.pri | 14 ++- 12 files changed, 238 insertions(+), 290 deletions(-) create mode 100644 src/libs/vtools/undocommands/label/moveabstractlabel.cpp rename src/libs/vtools/undocommands/{movelabel.h => label/moveabstractlabel.h} (62%) rename src/libs/vtools/undocommands/{ => label}/movedoublelabel.cpp (55%) rename src/libs/vtools/undocommands/{ => label}/movedoublelabel.h (60%) rename src/libs/vtools/undocommands/{ => label}/movelabel.cpp (64%) create mode 100644 src/libs/vtools/undocommands/label/movelabel.h rename src/libs/vtools/undocommands/{ => label}/rotationmovelabel.cpp (80%) rename src/libs/vtools/undocommands/{ => label}/rotationmovelabel.h (61%) diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index 3e0e62cd0..9adf237bf 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -38,7 +38,7 @@ #include "../../../visualization/line/vistoolrotation.h" #include "../vwidgets/vsimplepoint.h" #include "../vwidgets/vsimplecurve.h" -#include "../../../undocommands/rotationmovelabel.h" +#include "../../../undocommands/label/rotationmovelabel.h" const QString VToolRotation::TagName = QStringLiteral("operation"); const QString VToolRotation::TagItem = QStringLiteral("item"); @@ -703,7 +703,7 @@ void VToolRotation::DoChangePosition(quint32 id, qreal mx, qreal my) void VToolRotation::UpdateNamePosition(quint32 id) { const QSharedPointer point = VAbstractTool::data.GeometricObject(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); qApp->getUndoStack()->push(moveLabel); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index 8e7729788..fd4c267ac 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -29,7 +29,7 @@ #include "vtooldoublepoint.h" #include "../vwidgets/vsimplepoint.h" #include "../vgeometry/vpointf.h" -#include "../../../../undocommands/movedoublelabel.h" +#include "../../../../undocommands/label/movedoublelabel.h" #include @@ -244,7 +244,7 @@ void VToolDoublePoint::UpdateNamePosition(quint32 id) { const VPointF *p1 = VAbstractTool::data.GeometricObject(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); qApp->getUndoStack()->push(moveLabel); } @@ -252,8 +252,7 @@ void VToolDoublePoint::UpdateNamePosition(quint32 id) { const VPointF *p2 = VAbstractTool::data.GeometricObject(p2id).data(); - auto moveLabel = new MoveDoubleLabel(doc, p2->mx(), p2->my(), DoublePoint::SecondPoint, this->id, p2id, - scene()); + auto moveLabel = new MoveDoubleLabel(doc, p2->mx(), p2->my(), DoublePoint::SecondPoint, this->id, p2id); connect(moveLabel, &MoveDoubleLabel::ChangePosition, this, &VToolDoublePoint::DoChangePosition); qApp->getUndoStack()->push(moveLabel); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index be9c4edb9..f69bbc565 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -30,7 +30,7 @@ #include "../vmisc/logging.h" #include "../vgeometry/vpointf.h" #include "../vwidgets/vgraphicssimpletextitem.h" -#include "../../../../undocommands/movelabel.h" +#include "../../../../undocommands/label/movelabel.h" #include @@ -122,7 +122,7 @@ void VToolSinglePoint::NameChangePosition(const QPointF &pos) void VToolSinglePoint::UpdateNamePosition(quint32 id) { const QSharedPointer point = VAbstractTool::data.GeometricObject(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); qApp->getUndoStack()->push(moveLabel); } diff --git a/src/libs/vtools/undocommands/label/moveabstractlabel.cpp b/src/libs/vtools/undocommands/label/moveabstractlabel.cpp new file mode 100644 index 000000000..c44a1868d --- /dev/null +++ b/src/libs/vtools/undocommands/label/moveabstractlabel.cpp @@ -0,0 +1,73 @@ +/************************************************************************ + ** + ** @file moveabstractlabel.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 "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); + } +} diff --git a/src/libs/vtools/undocommands/movelabel.h b/src/libs/vtools/undocommands/label/moveabstractlabel.h similarity index 62% rename from src/libs/vtools/undocommands/movelabel.h rename to src/libs/vtools/undocommands/label/moveabstractlabel.h index a3a04167d..da52003f9 100644 --- a/src/libs/vtools/undocommands/movelabel.h +++ b/src/libs/vtools/undocommands/label/moveabstractlabel.h @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file movelabel.h + ** @file moveabstractlabel.h ** @author Roman Telezhynskyi - ** @date 25 12, 2014 + ** @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) 2013-2015 Valentina project + ** Copyright (C) 2016 Valentina project ** All Rights Reserved. ** ** Valentina is free software: you can redistribute it and/or modify @@ -26,56 +26,55 @@ ** *************************************************************************/ -#ifndef MOVELABEL_H -#define MOVELABEL_H +#ifndef MOVEABSTRACTLABEL_H +#define MOVEABSTRACTLABEL_H -#include "vundocommand.h" +#include "../vundocommand.h" -class QGraphicsScene; - -class MoveLabel : public VUndoCommand +class MoveAbstractLabel : public VUndoCommand { Q_OBJECT public: - MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, - QUndoCommand *parent = 0); - virtual ~MoveLabel() Q_DECL_OVERRIDE; + MoveAbstractLabel(VAbstractPattern *doc, quint32 pointId, double x, double y, QUndoCommand *parent = nullptr); + virtual ~MoveAbstractLabel(); + virtual void undo() 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; - double getNewMx() const; - double getNewMy() const; - void Do(double mx, double my); + + quint32 GetPointId() const; + double GetNewMx() const; + double GetNewMy() const; + signals: 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: - Q_DISABLE_COPY(MoveLabel) - double oldMx; - double oldMy; - double newMx; - double newMy; - bool isRedo; - QGraphicsScene *scene; + Q_DISABLE_COPY(MoveAbstractLabel) }; //--------------------------------------------------------------------------------------------------------------------- -inline quint32 MoveLabel::getPointId() const +inline quint32 MoveAbstractLabel::GetPointId() const { 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 diff --git a/src/libs/vtools/undocommands/movedoublelabel.cpp b/src/libs/vtools/undocommands/label/movedoublelabel.cpp similarity index 55% rename from src/libs/vtools/undocommands/movedoublelabel.cpp rename to src/libs/vtools/undocommands/label/movedoublelabel.cpp index d2c8fe6bb..960a49409 100644 --- a/src/libs/vtools/undocommands/movedoublelabel.cpp +++ b/src/libs/vtools/undocommands/label/movedoublelabel.cpp @@ -27,21 +27,14 @@ *************************************************************************/ #include "movedoublelabel.h" -#include "../tools/vabstracttool.h" -#include "../../vwidgets/vmaingraphicsview.h" - -#include -#include +#include "../vmisc/vabstractapplication.h" //--------------------------------------------------------------------------------------------------------------------- MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const double &y, DoublePoint type, - quint32 tooId, quint32 pointId, QGraphicsScene *scene, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), - oldMx(0.0), oldMy(0.0), - newMx(x), newMy(y), - scene(scene), type(type), - pointId(pointId), - isRedo(false) + quint32 toolId, quint32 pointId, QUndoCommand *parent) + : MoveAbstractLabel(doc, pointId, x, y, parent), + m_type(type), + m_idTool(toolId) { if (type == DoublePoint::FirstPoint) { @@ -51,44 +44,25 @@ MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const d { setText(tr("move the second dart label")); } - nodeId = tooId; - qCDebug(vUndo, "Point id %u", nodeId); - if (type == DoublePoint::FirstPoint) - { - 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); + const QDomElement domElement = doc->elementById(m_idTool); if (domElement.isElement()) { if (type == DoublePoint::FirstPoint) { - oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx1, "0.0")); - 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")); - } + m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx1, "0.0")); + m_oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy1, "0.0")); - if (type == DoublePoint::FirstPoint) - { - qCDebug(vUndo, "Label old Mx1 %f", oldMx); - qCDebug(vUndo, "Label old My1 %f", oldMy); + qCDebug(vUndo, "Label old Mx1 %f", m_oldMx); + qCDebug(vUndo, "Label old My1 %f", m_oldMy); } else { - qCDebug(vUndo, "Label old Mx2 %f", oldMx); - qCDebug(vUndo, "Label old My2 %f", oldMy); + m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx2, "0.0")); + 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 @@ -102,52 +76,31 @@ MoveDoubleLabel::MoveDoubleLabel(VAbstractPattern *doc, const double &x, const d 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) { const MoveDoubleLabel *moveCommand = static_cast(command); SCASSERT(moveCommand != nullptr); - if (moveCommand->getPointId() != nodeId || moveCommand->getPointType() != type || - moveCommand->getLabelId() != pointId) + if (moveCommand->GetPointId() != nodeId || + moveCommand->GetPointType() != m_type || + moveCommand->GetToolId() != m_idTool) { return false; } - newMx = moveCommand->getNewMx(); - newMy = moveCommand->getNewMy(); + m_newMx = moveCommand->GetNewMx(); + m_newMy = moveCommand->GetNewMy(); - if (type == DoublePoint::FirstPoint) + if (m_type == DoublePoint::FirstPoint) { - qCDebug(vUndo, "Label new Mx1 %f", newMx); - qCDebug(vUndo, "Label new My1 %f", newMy); + qCDebug(vUndo, "Label new Mx1 %f", m_newMx); + qCDebug(vUndo, "Label new My1 %f", m_newMy); } else { - qCDebug(vUndo, "Label new Mx2 %f", newMx); - qCDebug(vUndo, "Label new My2 %f", newMy); + qCDebug(vUndo, "Label new Mx2 %f", m_newMx); + qCDebug(vUndo, "Label new My2 %f", m_newMy); } return true; } @@ -158,16 +111,10 @@ int MoveDoubleLabel::id() const return static_cast(UndoCommand::MoveDoubleLabel); } -//--------------------------------------------------------------------------------------------------------------------- -quint32 MoveDoubleLabel::getLabelId() const -{ - return pointId; -} - //--------------------------------------------------------------------------------------------------------------------- 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 my1 %f", my); @@ -178,10 +125,10 @@ void MoveDoubleLabel::Do(double mx, double my) qCDebug(vUndo, "New my2 %f", my); } - QDomElement domElement = doc->elementById(nodeId); + QDomElement domElement = doc->elementById(m_idTool); if (domElement.isElement()) { - if (type == DoublePoint::FirstPoint) + if (m_type == DoublePoint::FirstPoint) { doc->SetAttribute(domElement, AttrMx1, QString().setNum(qApp->fromPixel(mx))); doc->SetAttribute(domElement, AttrMy1, QString().setNum(qApp->fromPixel(my))); diff --git a/src/libs/vtools/undocommands/movedoublelabel.h b/src/libs/vtools/undocommands/label/movedoublelabel.h similarity index 60% rename from src/libs/vtools/undocommands/movedoublelabel.h rename to src/libs/vtools/undocommands/label/movedoublelabel.h index b26728add..19bd4604a 100644 --- a/src/libs/vtools/undocommands/movedoublelabel.h +++ b/src/libs/vtools/undocommands/label/movedoublelabel.h @@ -29,65 +29,41 @@ #ifndef MOVEDOUBLELABEL_H #define MOVEDOUBLELABEL_H -#include "vundocommand.h" - -class QGraphicsScene; +#include "moveabstractlabel.h" enum class DoublePoint: char { FirstPoint, SecondPoint }; -class MoveDoubleLabel : public VUndoCommand +class MoveDoubleLabel : public MoveAbstractLabel { Q_OBJECT public: 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 void undo() 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 getLabelId() const; - double getNewMx() const; - double getNewMy() const; - DoublePoint getPointType() const; - void Do(double mx, double my); -signals: - void ChangePosition(quint32 id, qreal mx, qreal my); + + quint32 GetToolId() const; + DoublePoint GetPointType() const; +protected: + virtual void Do(double mx, double my) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(MoveDoubleLabel) - double oldMx; - double oldMy; - double newMx; - double newMy; - QGraphicsScene *scene; - DoublePoint type; - quint32 pointId; - bool isRedo; + DoublePoint m_type; + quint32 m_idTool; }; //--------------------------------------------------------------------------------------------------------------------- -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; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline double MoveDoubleLabel::getNewMx() const -{ - return newMx; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline double MoveDoubleLabel::getNewMy() const -{ - return newMy; + return m_idTool; } #endif // MOVEDOUBLELABEL_H diff --git a/src/libs/vtools/undocommands/movelabel.cpp b/src/libs/vtools/undocommands/label/movelabel.cpp similarity index 64% rename from src/libs/vtools/undocommands/movelabel.cpp rename to src/libs/vtools/undocommands/label/movelabel.cpp index c5c8dfea4..82b75289a 100644 --- a/src/libs/vtools/undocommands/movelabel.cpp +++ b/src/libs/vtools/undocommands/label/movelabel.cpp @@ -27,33 +27,22 @@ *************************************************************************/ #include "movelabel.h" -#include "../tools/vabstracttool.h" -#include "../../vwidgets/vmaingraphicsview.h" - -#include -#include +#include "../vmisc/vabstractapplication.h" //--------------------------------------------------------------------------------------------------------------------- -MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, - QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), oldMx(0.0), oldMy(0.0), newMx(x), newMy(y), isRedo(false), scene(scene) +MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QUndoCommand *parent) + : MoveAbstractLabel(doc, id, x, y, parent) { setText(tr("move point label")); - nodeId = id; - qCDebug(vUndo, "Point id %u", nodeId); - qCDebug(vUndo, "Label new Mx %f", newMx); - qCDebug(vUndo, "Label new My %f", newMy); - - SCASSERT(scene != nullptr); - QDomElement domElement = doc->elementById(id); + QDomElement domElement = doc->elementById(nodeId); if (domElement.isElement()) { - oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0")); - oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0")); + m_oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0")); + m_oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0")); - qCDebug(vUndo, "Label old Mx %f", oldMx); - qCDebug(vUndo, "Label old My %f", oldMy); + qCDebug(vUndo, "Label old Mx %f", m_oldMx); + qCDebug(vUndo, "Label old My %f", m_oldMy); } else { @@ -66,45 +55,22 @@ MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, co 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) { const MoveLabel *moveCommand = static_cast(command); SCASSERT(moveCommand != nullptr); - const quint32 id = moveCommand->getPointId(); - if (id != nodeId) + if (moveCommand->GetPointId() != nodeId) { return false; } qCDebug(vUndo, "Mergin undo."); - newMx = moveCommand->getNewMx(); - newMy = moveCommand->getNewMy(); - qCDebug(vUndo, "Label new Mx %f", newMx); - qCDebug(vUndo, "Label new My %f", newMy); + m_newMx = moveCommand->GetNewMx(); + m_newMy = moveCommand->GetNewMy(); + qCDebug(vUndo, "Label new Mx %f", m_newMx); + qCDebug(vUndo, "Label new My %f", m_newMy); return true; } diff --git a/src/libs/vtools/undocommands/label/movelabel.h b/src/libs/vtools/undocommands/label/movelabel.h new file mode 100644 index 000000000..3b5887919 --- /dev/null +++ b/src/libs/vtools/undocommands/label/movelabel.h @@ -0,0 +1,49 @@ +/************************************************************************ + ** + ** @file movelabel.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 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 diff --git a/src/libs/vtools/undocommands/rotationmovelabel.cpp b/src/libs/vtools/undocommands/label/rotationmovelabel.cpp similarity index 80% rename from src/libs/vtools/undocommands/rotationmovelabel.cpp rename to src/libs/vtools/undocommands/label/rotationmovelabel.cpp index 12712a264..0d73a9450 100644 --- a/src/libs/vtools/undocommands/rotationmovelabel.cpp +++ b/src/libs/vtools/undocommands/label/rotationmovelabel.cpp @@ -27,30 +27,19 @@ *************************************************************************/ #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, - QGraphicsScene *scene, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), - m_oldMx(0.0), - m_oldMy(0.0), - m_newMx(x), - m_newMy(y), - m_isRedo(false), - m_scene(scene), + QUndoCommand *parent) + : MoveAbstractLabel(doc, idPoint, x, y, parent), m_idTool(idTool) { setText(tr("move point label")); - nodeId = idPoint; + qCDebug(vUndo, "Tool id %u", m_idTool); - qCDebug(vUndo, "Point id %u", nodeId); - qCDebug(vUndo, "Label new Mx %f", m_newMx); - qCDebug(vUndo, "Label new My %f", m_newMy); - - SCASSERT(scene != nullptr); - QDomElement element = GetDestinationObject(m_idTool, nodeId); + const QDomElement element = GetDestinationObject(m_idTool, nodeId); if (element.isElement()) { 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) { @@ -105,8 +72,8 @@ bool RotationMoveLabel::mergeWith(const QUndoCommand *command) } qCDebug(vUndo, "Mergin undo."); - m_newMx = moveCommand->getNewMx(); - m_newMy = moveCommand->getNewMy(); + m_newMx = moveCommand->GetNewMx(); + m_newMy = moveCommand->GetNewMy(); qCDebug(vUndo, "Label new Mx %f", m_newMx); qCDebug(vUndo, "Label new My %f", m_newMy); return true; diff --git a/src/libs/vtools/undocommands/rotationmovelabel.h b/src/libs/vtools/undocommands/label/rotationmovelabel.h similarity index 61% rename from src/libs/vtools/undocommands/rotationmovelabel.h rename to src/libs/vtools/undocommands/label/rotationmovelabel.h index fe19ffe0c..ba156eb01 100644 --- a/src/libs/vtools/undocommands/rotationmovelabel.h +++ b/src/libs/vtools/undocommands/label/rotationmovelabel.h @@ -29,59 +29,29 @@ #ifndef ROTATIONMOVELABEL_H #define ROTATIONMOVELABEL_H -#include "vundocommand.h" +#include "moveabstractlabel.h" -class QGraphicsScene; - -class RotationMoveLabel : public VUndoCommand +class RotationMoveLabel : public MoveAbstractLabel { Q_OBJECT 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); virtual ~RotationMoveLabel(); - virtual void undo() 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 GetToolId() const; - double getNewMx() const; - double getNewMy() const; -signals: - void ChangePosition(quint32 id, qreal mx, qreal my); + + quint32 GetToolId() const; +protected: + virtual void Do(double mx, double my) Q_DECL_OVERRIDE; private: 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; - void Do(double mx, double my); 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 { diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index ffd3417e4..a20f58d15 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -17,11 +17,12 @@ HEADERS += \ $$PWD/deletedetail.h \ $$PWD/vundocommand.h \ $$PWD/renamepp.h \ - $$PWD/movelabel.h \ - $$PWD/movedoublelabel.h \ + $$PWD/label/movelabel.h \ + $$PWD/label/movedoublelabel.h \ $$PWD/addgroup.h \ $$PWD/delgroup.h \ - $$PWD/rotationmovelabel.h + $$PWD/label/rotationmovelabel.h \ + undocommands/label/moveabstractlabel.h SOURCES += \ $$PWD/addtocalc.cpp \ @@ -39,8 +40,9 @@ SOURCES += \ $$PWD/deletedetail.cpp \ $$PWD/vundocommand.cpp \ $$PWD/renamepp.cpp \ - $$PWD/movelabel.cpp \ - $$PWD/movedoublelabel.cpp \ + $$PWD/label/movelabel.cpp \ + $$PWD/label/movedoublelabel.cpp \ $$PWD/addgroup.cpp \ $$PWD/delgroup.cpp \ - $$PWD/rotationmovelabel.cpp + $$PWD/label/rotationmovelabel.cpp \ + undocommands/label/moveabstractlabel.cpp