Undo moving label.
--HG-- branch : develop
This commit is contained in:
parent
c978a8c090
commit
44b3064290
|
@ -30,6 +30,7 @@
|
|||
#include <QKeyEvent>
|
||||
#include "../../geometry/vpointf.h"
|
||||
#include "../../visualization/vgraphicssimpletextitem.h"
|
||||
#include "../../undocommands/movelabel.h"
|
||||
|
||||
const QString VToolPoint::TagName = QStringLiteral("point");
|
||||
|
||||
|
@ -121,13 +122,9 @@ void VToolPoint::NameChangePosition(const QPointF &pos)
|
|||
*/
|
||||
void VToolPoint::UpdateNamePosition(qreal mx, qreal my)
|
||||
{
|
||||
QDomElement domElement = doc->elementById(QString().setNum(id));
|
||||
if (domElement.isElement())
|
||||
{
|
||||
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(mx));
|
||||
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(my));
|
||||
emit toolhaveChange();
|
||||
}
|
||||
MoveLabel *moveLabel = new MoveLabel(doc, mx, my, id, this->scene());
|
||||
connect(moveLabel, &MoveLabel::NeedLiteParsing, doc, &VPattern::LiteParseTree);
|
||||
qApp->getUndoStack()->push(moveLabel);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
133
src/app/undocommands/movelabel.cpp
Normal file
133
src/app/undocommands/movelabel.cpp
Normal file
|
@ -0,0 +1,133 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file movelabel.cpp
|
||||
** @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) 2014 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 "movelabel.h"
|
||||
#include <QGraphicsScene>
|
||||
#include <QDomElement>
|
||||
#include "../xml/vpattern.h"
|
||||
#include "../tools/vabstracttool.h"
|
||||
#include "../core/vapplication.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
MoveLabel::MoveLabel(VPattern *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), scene(scene)
|
||||
{
|
||||
setText(tr("Move point label"));
|
||||
nodeId = id;
|
||||
qCDebug(vUndo)<<"Point id"<<nodeId;
|
||||
|
||||
qCDebug(vUndo)<<"Label new Mx"<<newMx;
|
||||
qCDebug(vUndo)<<"Label new My"<<newMy;
|
||||
|
||||
SCASSERT(scene != nullptr);
|
||||
QDomElement domElement = doc->elementById(QString().setNum(id));
|
||||
if (domElement.isElement())
|
||||
{
|
||||
oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMx, "0.0"));
|
||||
oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMy, "0.0"));
|
||||
|
||||
qCDebug(vUndo)<<"Label old Mx"<<oldMx;
|
||||
qCDebug(vUndo)<<"Label old My"<<oldMy;
|
||||
}
|
||||
else
|
||||
{
|
||||
qCDebug(vUndo)<<"Can't find point with id ="<<nodeId<<".";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
MoveLabel::~MoveLabel()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MoveLabel::undo()
|
||||
{
|
||||
qCDebug(vUndo)<<"Undo.";
|
||||
|
||||
Do(oldMx, oldMy);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MoveLabel::redo()
|
||||
{
|
||||
qCDebug(vUndo)<<"Redo.";
|
||||
|
||||
Do(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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
qCDebug(vUndo)<<"Mergin undo.";
|
||||
newMx = moveCommand->getNewMx();
|
||||
newMy = moveCommand->getNewMy();
|
||||
qCDebug(vUndo)<<"Label new Mx"<<newMx;
|
||||
qCDebug(vUndo)<<"Label new My"<<newMy;
|
||||
return true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int MoveLabel::id() const
|
||||
{
|
||||
return static_cast<int>(UndoCommand::MoveLabel);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MoveLabel::Do(double mx, double my)
|
||||
{
|
||||
qCDebug(vUndo)<<"New mx"<<mx;
|
||||
qCDebug(vUndo)<<"New my"<<my;
|
||||
|
||||
QDomElement domElement = doc->elementById(QString().setNum(nodeId));
|
||||
if (domElement.isElement())
|
||||
{
|
||||
doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(mx)));
|
||||
doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(my)));
|
||||
|
||||
emit NeedLiteParsing(Document::LitePPParse);
|
||||
|
||||
QList<QGraphicsView*> list = scene->views();
|
||||
VAbstractTool::NewSceneRect(scene, list[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
qCDebug(vUndo)<<"Can't find point with id ="<<nodeId<<".";
|
||||
return;
|
||||
}
|
||||
}
|
78
src/app/undocommands/movelabel.h
Normal file
78
src/app/undocommands/movelabel.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @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) 2014 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 "vundocommand.h"
|
||||
|
||||
class QGraphicsScene;
|
||||
|
||||
class MoveLabel : public VUndoCommand
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MoveLabel(VPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene,
|
||||
QUndoCommand *parent = 0);
|
||||
virtual ~MoveLabel();
|
||||
virtual void undo();
|
||||
virtual void redo();
|
||||
virtual bool mergeWith(const QUndoCommand *command);
|
||||
virtual int id() const;
|
||||
quint32 getPointId() const;
|
||||
double getNewMx() const;
|
||||
double getNewMy() const;
|
||||
void Do(double mx, double my);
|
||||
private:
|
||||
Q_DISABLE_COPY(MoveLabel)
|
||||
double oldMx;
|
||||
double oldMy;
|
||||
double newMx;
|
||||
double newMy;
|
||||
QGraphicsScene *scene;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
inline quint32 MoveLabel::getPointId() const
|
||||
{
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
inline double MoveLabel::getNewMx() const
|
||||
{
|
||||
return newMx;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
inline double MoveLabel::getNewMy() const
|
||||
{
|
||||
return newMy;
|
||||
}
|
||||
|
||||
#endif // MOVELABEL_H
|
|
@ -17,7 +17,8 @@ HEADERS += \
|
|||
$$PWD/adduniondetails.h \
|
||||
$$PWD/deletedetail.h \
|
||||
$$PWD/vundocommand.h \
|
||||
$$PWD/renamepp.h
|
||||
$$PWD/renamepp.h \
|
||||
$$PWD/movelabel.h
|
||||
|
||||
|
||||
SOURCES += \
|
||||
|
@ -36,5 +37,6 @@ SOURCES += \
|
|||
$$PWD/adduniondetails.cpp \
|
||||
$$PWD/deletedetail.cpp \
|
||||
$$PWD/vundocommand.cpp \
|
||||
$$PWD/renamepp.cpp
|
||||
$$PWD/renamepp.cpp \
|
||||
$$PWD/movelabel.cpp
|
||||
|
||||
|
|
|
@ -46,7 +46,8 @@ enum class UndoCommand: char { AddPatternPiece,
|
|||
MoveDetail,
|
||||
DeleteTool,
|
||||
DeletePatternPiece,
|
||||
RenamePP
|
||||
RenamePP,
|
||||
MoveLabel
|
||||
};
|
||||
|
||||
class VPattern;
|
||||
|
|
Loading…
Reference in New Issue
Block a user