Improve Move piece undocommand.

Performance improvement.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-10-18 11:24:15 +03:00
parent b693244847
commit ef41c700f8
5 changed files with 31 additions and 18 deletions

View File

@ -71,8 +71,8 @@ public:
VContainerData(const VTranslateVars *trVars, const Unit *patternUnit) VContainerData(const VTranslateVars *trVars, const Unit *patternUnit)
: gObjects(QHash<quint32, QSharedPointer<VGObject> >()), : gObjects(QHash<quint32, QSharedPointer<VGObject> >()),
variables(QHash<QString, QSharedPointer<VInternalVariable> > ()), variables(QHash<QString, QSharedPointer<VInternalVariable> > ()),
pieces(QSharedPointer<QHash<quint32, VPiece>>(new QHash<quint32, VPiece>())), pieces(QSharedPointer<QHash<quint32, VPiece>>::create()),
piecePaths(QSharedPointer<QHash<quint32, VPiecePath>>(new QHash<quint32, VPiecePath>())), piecePaths(QSharedPointer<QHash<quint32, VPiecePath>>::create()),
trVars(trVars), trVars(trVars),
patternUnit(patternUnit) patternUnit(patternUnit)
{} {}

View File

@ -445,6 +445,20 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle
domElement.appendChild(domData); domElement.appendChild(domData);
} }
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::Move(qreal x, qreal y)
{
setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
// Don't forget to update geometry, because first change never call full parse
VPiece detail = VAbstractTool::data.GetPiece(m_id);
detail.SetMx(x);
detail.SetMy(y);
VAbstractTool::data.UpdatePiece(m_id, detail);
setPos(x, y);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VToolSeamAllowance::getTagName() const QString VToolSeamAllowance::getTagName() const
{ {
@ -907,9 +921,7 @@ QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change
// value - this is new position. // value - this is new position.
const QPointF newPos = value.toPointF(); const QPointF newPos = value.toPointF();
MovePiece *moveDet = new MovePiece(doc, newPos.x(), newPos.y(), m_id, scene()); qApp->getUndoStack()->push(new MovePiece(doc, newPos.x(), newPos.y(), m_id, scene()));
connect(moveDet, &MovePiece::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(moveDet);
const QList<QGraphicsView *> viewList = scene()->views(); const QList<QGraphicsView *> viewList = scene()->views();
if (not viewList.isEmpty()) if (not viewList.isEmpty())
@ -945,7 +957,6 @@ QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change
detail.SetMy(newPos.y()); detail.SetMy(newPos.y());
VAbstractTool::data.UpdatePiece(m_id, detail); VAbstractTool::data.UpdatePiece(m_id, detail);
RefreshGeometry();
changeFinished = true; changeFinished = true;
} }
} }

View File

@ -100,6 +100,8 @@ public:
static void AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece); static void AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
static void AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece); static void AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
void Move(qreal x, qreal y);
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::Piece)}; enum { Type = UserType + static_cast<int>(Tool::Piece)};

View File

@ -37,6 +37,7 @@
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vwidgets/vmaingraphicsview.h" #include "../vwidgets/vmaingraphicsview.h"
#include "vundocommand.h" #include "vundocommand.h"
#include "../tools/vtoolseamallowance.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
MovePiece::MovePiece(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, MovePiece::MovePiece(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id,
@ -64,10 +65,6 @@ MovePiece::MovePiece(VAbstractPattern *doc, const double &x, const double &y, co
} }
} }
//---------------------------------------------------------------------------------------------------------------------
MovePiece::~MovePiece()
{}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MovePiece::undo() void MovePiece::undo()
{ {
@ -77,8 +74,11 @@ void MovePiece::undo()
if (domElement.isElement()) if (domElement.isElement())
{ {
SaveCoordinates(domElement, m_oldX, m_oldY); SaveCoordinates(domElement, m_oldX, m_oldY);
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId)))
emit NeedLiteParsing(Document::LiteParse); {
tool->Move(m_oldX, m_oldY);
}
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
} }
else else
{ {
@ -98,12 +98,12 @@ void MovePiece::redo()
if (redoFlag) if (redoFlag)
{ {
emit NeedLiteParsing(Document::LiteParse); if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId)))
}
else
{ {
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); tool->Move(m_newX, m_newY);
} }
}
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
redoFlag = true; redoFlag = true;
} }
else else

View File

@ -45,7 +45,7 @@ class MovePiece : public VUndoCommand
public: public:
MovePiece(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, MovePiece(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene,
QUndoCommand *parent = nullptr); QUndoCommand *parent = nullptr);
virtual ~MovePiece(); virtual ~MovePiece()=default;
virtual void undo() Q_DECL_OVERRIDE; virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE;