Refactoring undocommands move label.
--HG-- branch : feature
This commit is contained in:
parent
fc4054e49e
commit
c8a041e4f2
|
@ -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<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);
|
||||
qApp->getUndoStack()->push(moveLabel);
|
||||
}
|
||||
|
|
|
@ -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 <QKeyEvent>
|
||||
|
||||
|
@ -244,7 +244,7 @@ void VToolDoublePoint::UpdateNamePosition(quint32 id)
|
|||
{
|
||||
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);
|
||||
qApp->getUndoStack()->push(moveLabel);
|
||||
}
|
||||
|
@ -252,8 +252,7 @@ void VToolDoublePoint::UpdateNamePosition(quint32 id)
|
|||
{
|
||||
const VPointF *p2 = VAbstractTool::data.GeometricObject<VPointF>(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);
|
||||
}
|
||||
|
|
|
@ -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 <QKeyEvent>
|
||||
|
||||
|
@ -122,7 +122,7 @@ void VToolSinglePoint::NameChangePosition(const QPointF &pos)
|
|||
void VToolSinglePoint::UpdateNamePosition(quint32 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);
|
||||
qApp->getUndoStack()->push(moveLabel);
|
||||
}
|
||||
|
|
73
src/libs/vtools/undocommands/label/moveabstractlabel.cpp
Normal file
73
src/libs/vtools/undocommands/label/moveabstractlabel.cpp
Normal 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);
|
||||
}
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file movelabel.h
|
||||
** @file moveabstractlabel.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @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
|
||||
** <https://bitbucket.org/dismine/valentina> 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
|
|
@ -27,21 +27,14 @@
|
|||
*************************************************************************/
|
||||
|
||||
#include "movedoublelabel.h"
|
||||
#include "../tools/vabstracttool.h"
|
||||
#include "../../vwidgets/vmaingraphicsview.h"
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QDomElement>
|
||||
#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<const MoveDoubleLabel *>(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<int>(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)));
|
|
@ -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
|
|
@ -27,33 +27,22 @@
|
|||
*************************************************************************/
|
||||
|
||||
#include "movelabel.h"
|
||||
#include "../tools/vabstracttool.h"
|
||||
#include "../../vwidgets/vmaingraphicsview.h"
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QDomElement>
|
||||
#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<const MoveLabel *>(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;
|
||||
}
|
||||
|
49
src/libs/vtools/undocommands/label/movelabel.h
Normal file
49
src/libs/vtools/undocommands/label/movelabel.h
Normal 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
|
|
@ -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;
|
|
@ -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
|
||||
{
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user