Fix bug with returning a piece to original position.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-10-27 12:28:08 +03:00
parent dd5b276e5d
commit 91b4c7c8fa
2 changed files with 28 additions and 34 deletions

View File

@ -69,46 +69,14 @@ MovePiece::MovePiece(VAbstractPattern *doc, const double &x, const double &y, co
void MovePiece::undo() void MovePiece::undo()
{ {
qCDebug(vUndo, "Undo."); qCDebug(vUndo, "Undo.");
Do(m_oldX, m_oldY);
QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagDetail);
if (domElement.isElement())
{
SaveCoordinates(domElement, m_oldX, m_oldY);
VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId));
if (tool)
{
tool->Move(m_oldX, m_oldY);
}
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(), tool);
}
else
{
qCDebug(vUndo, "Can't find detail with id = %u.", nodeId);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MovePiece::redo() void MovePiece::redo()
{ {
qCDebug(vUndo, "Redo."); qCDebug(vUndo, "Redo.");
Do(m_newX, m_newY);
QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagDetail);
if (domElement.isElement())
{
SaveCoordinates(domElement, m_newX, m_newY);
VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId));
if (redoFlag && tool)
{
tool->Move(m_newX, m_newY);
}
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(), tool);
redoFlag = true;
}
else
{
qCDebug(vUndo, "Can't find detail with id = %u.", nodeId);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -135,6 +103,29 @@ int MovePiece::id() const
return static_cast<int>(UndoCommand::MovePiece); return static_cast<int>(UndoCommand::MovePiece);
} }
//---------------------------------------------------------------------------------------------------------------------
void MovePiece::Do(qreal x, qreal y)
{
qCDebug(vUndo, "Do.");
QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagDetail);
if (domElement.isElement())
{
SaveCoordinates(domElement, x, y);
VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId));
if (tool)
{
tool->Move(x, y);
}
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(), tool);
}
else
{
qCDebug(vUndo, "Can't find detail with id = %u.", nodeId);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MovePiece::SaveCoordinates(QDomElement &domElement, double x, double y) void MovePiece::SaveCoordinates(QDomElement &domElement, double x, double y)
{ {

View File

@ -52,6 +52,9 @@ public:
// cppcheck-suppress unusedFunction // cppcheck-suppress unusedFunction
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;
void Do(qreal x, qreal y);
quint32 getDetId() const; quint32 getDetId() const;
double getNewX() const; double getNewX() const;
double getNewY() const; double getNewY() const;