Undocommand move a label of rotated point.
--HG-- branch : feature
This commit is contained in:
parent
80b415f258
commit
fc4054e49e
|
@ -38,6 +38,7 @@
|
|||
#include "../../../visualization/line/vistoolrotation.h"
|
||||
#include "../vwidgets/vsimplepoint.h"
|
||||
#include "../vwidgets/vsimplecurve.h"
|
||||
#include "../../../undocommands/rotationmovelabel.h"
|
||||
|
||||
const QString VToolRotation::TagName = QStringLiteral("operation");
|
||||
const QString VToolRotation::TagItem = QStringLiteral("item");
|
||||
|
@ -702,9 +703,9 @@ 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 MoveLabel(doc, point->mx(), point->my(), id, scene());
|
||||
// connect(moveLabel, &MoveLabel::ChangePosition, this, &VToolSinglePoint::DoChangePosition);
|
||||
// qApp->getUndoStack()->push(moveLabel);
|
||||
auto moveLabel = new RotationMoveLabel(this->id, doc, point->mx(), point->my(), id, scene());
|
||||
connect(moveLabel, &RotationMoveLabel::ChangePosition, this, &VToolRotation::DoChangePosition);
|
||||
qApp->getUndoStack()->push(moveLabel);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
177
src/libs/vtools/undocommands/rotationmovelabel.cpp
Normal file
177
src/libs/vtools/undocommands/rotationmovelabel.cpp
Normal file
|
@ -0,0 +1,177 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file moverotationlabel.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 "rotationmovelabel.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),
|
||||
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);
|
||||
if (element.isElement())
|
||||
{
|
||||
m_oldMx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, "0.0"));
|
||||
m_oldMy = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, "0.0"));
|
||||
|
||||
qCDebug(vUndo, "Label old Mx %f", m_oldMx);
|
||||
qCDebug(vUndo, "Label old My %f", m_oldMy);
|
||||
}
|
||||
else
|
||||
{
|
||||
qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
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)
|
||||
{
|
||||
const RotationMoveLabel *moveCommand = static_cast<const RotationMoveLabel *>(command);
|
||||
SCASSERT(moveCommand != nullptr);
|
||||
|
||||
if (moveCommand->GetToolId() != m_idTool && moveCommand->GetPointId() != nodeId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
qCDebug(vUndo, "Mergin undo.");
|
||||
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;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int RotationMoveLabel::id() const
|
||||
{
|
||||
return static_cast<int>(UndoCommand::RotationMoveLabel);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void RotationMoveLabel::Do(double mx, double my)
|
||||
{
|
||||
qCDebug(vUndo, "New mx %f", mx);
|
||||
qCDebug(vUndo, "New my %f", my);
|
||||
|
||||
QDomElement domElement = GetDestinationObject(m_idTool, nodeId);
|
||||
if (not domElement.isNull() && domElement.isElement())
|
||||
{
|
||||
doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(mx)));
|
||||
doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(my)));
|
||||
}
|
||||
else
|
||||
{
|
||||
qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QDomElement RotationMoveLabel::GetDestinationObject(quint32 idTool, quint32 idPoint) const
|
||||
{
|
||||
const QDomElement tool = doc->elementById(idTool);
|
||||
if (tool.isElement())
|
||||
{
|
||||
QDomElement correctDest;
|
||||
const QDomNodeList nodeList = tool.childNodes();
|
||||
for (qint32 i = 0; i < nodeList.size(); ++i)
|
||||
{
|
||||
const QDomElement dest = nodeList.at(i).toElement();
|
||||
if (not dest.isNull() && dest.isElement() && dest.tagName() == VToolRotation::TagDestination)
|
||||
{
|
||||
correctDest = dest;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (not correctDest.isNull())
|
||||
{
|
||||
const QDomNodeList destObjects = correctDest.childNodes();
|
||||
for (qint32 i = 0; i < destObjects.size(); ++i)
|
||||
{
|
||||
const QDomElement obj = destObjects.at(i).toElement();
|
||||
if (not obj.isNull() && obj.isElement())
|
||||
{
|
||||
const quint32 id = doc->GetParametrUInt(obj, AttrIdObject, NULL_ID_STR);
|
||||
if (idPoint == id)
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QDomElement();
|
||||
}
|
91
src/libs/vtools/undocommands/rotationmovelabel.h
Normal file
91
src/libs/vtools/undocommands/rotationmovelabel.h
Normal file
|
@ -0,0 +1,91 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file moverotationlabel.h
|
||||
** @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/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef ROTATIONMOVELABEL_H
|
||||
#define ROTATIONMOVELABEL_H
|
||||
|
||||
#include "vundocommand.h"
|
||||
|
||||
class QGraphicsScene;
|
||||
|
||||
class RotationMoveLabel : public VUndoCommand
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, QGraphicsScene *scene,
|
||||
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);
|
||||
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
|
||||
{
|
||||
return m_idTool;
|
||||
}
|
||||
|
||||
#endif // ROTATIONMOVELABEL_H
|
|
@ -20,7 +20,8 @@ HEADERS += \
|
|||
$$PWD/movelabel.h \
|
||||
$$PWD/movedoublelabel.h \
|
||||
$$PWD/addgroup.h \
|
||||
$$PWD/delgroup.h
|
||||
$$PWD/delgroup.h \
|
||||
$$PWD/rotationmovelabel.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/addtocalc.cpp \
|
||||
|
@ -41,4 +42,5 @@ SOURCES += \
|
|||
$$PWD/movelabel.cpp \
|
||||
$$PWD/movedoublelabel.cpp \
|
||||
$$PWD/addgroup.cpp \
|
||||
$$PWD/delgroup.cpp
|
||||
$$PWD/delgroup.cpp \
|
||||
$$PWD/rotationmovelabel.cpp
|
||||
|
|
|
@ -49,7 +49,8 @@ enum class UndoCommand: char { AddPatternPiece,
|
|||
DeletePatternPiece,
|
||||
RenamePP,
|
||||
MoveLabel,
|
||||
MoveDoubleLabel
|
||||
MoveDoubleLabel,
|
||||
RotationMoveLabel
|
||||
};
|
||||
|
||||
class VPattern;
|
||||
|
|
Loading…
Reference in New Issue
Block a user