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)
: gObjects(QHash<quint32, QSharedPointer<VGObject> >()),
variables(QHash<QString, QSharedPointer<VInternalVariable> > ()),
pieces(QSharedPointer<QHash<quint32, VPiece>>(new QHash<quint32, VPiece>())),
piecePaths(QSharedPointer<QHash<quint32, VPiecePath>>(new QHash<quint32, VPiecePath>())),
pieces(QSharedPointer<QHash<quint32, VPiece>>::create()),
piecePaths(QSharedPointer<QHash<quint32, VPiecePath>>::create()),
trVars(trVars),
patternUnit(patternUnit)
{}

View File

@ -445,6 +445,20 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle
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
{
@ -907,9 +921,7 @@ QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change
// value - this is new position.
const QPointF newPos = value.toPointF();
MovePiece *moveDet = new MovePiece(doc, newPos.x(), newPos.y(), m_id, scene());
connect(moveDet, &MovePiece::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(moveDet);
qApp->getUndoStack()->push(new MovePiece(doc, newPos.x(), newPos.y(), m_id, scene()));
const QList<QGraphicsView *> viewList = scene()->views();
if (not viewList.isEmpty())
@ -945,7 +957,6 @@ QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change
detail.SetMy(newPos.y());
VAbstractTool::data.UpdatePiece(m_id, detail);
RefreshGeometry();
changeFinished = true;
}
}

View File

@ -100,6 +100,8 @@ public:
static void AddPatternInfo(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;}
enum { Type = UserType + static_cast<int>(Tool::Piece)};

View File

@ -37,6 +37,7 @@
#include "../vmisc/def.h"
#include "../vwidgets/vmaingraphicsview.h"
#include "vundocommand.h"
#include "../tools/vtoolseamallowance.h"
//---------------------------------------------------------------------------------------------------------------------
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()
{
@ -77,8 +74,11 @@ void MovePiece::undo()
if (domElement.isElement())
{
SaveCoordinates(domElement, m_oldX, m_oldY);
emit NeedLiteParsing(Document::LiteParse);
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId)))
{
tool->Move(m_oldX, m_oldY);
}
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
}
else
{
@ -98,12 +98,12 @@ void MovePiece::redo()
if (redoFlag)
{
emit NeedLiteParsing(Document::LiteParse);
}
else
{
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId)))
{
tool->Move(m_newX, m_newY);
}
}
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
redoFlag = true;
}
else

View File

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