Improve Save piece options undocommand.

Performance improvement.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-10-18 11:56:29 +03:00
parent ef41c700f8
commit 6b6c7aff52
6 changed files with 47 additions and 73 deletions

View File

@ -251,10 +251,7 @@ void VToolPiecePath::AddToFile()
newDet.GetCustomSARecords().append(record);
}
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId);
qApp->getUndoStack()->push(saveCommand);// First push then make a connect
VAbstractTool::data.UpdatePiece(m_pieceId, newDet);// Update piece because first save will not call lite update
connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(new SavePieceOptions(oldDet, newDet, doc, m_pieceId));
}
}

View File

@ -148,10 +148,7 @@ void VToolPin::AddToFile()
newDet.GetPins().append(m_id);
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId);
qApp->getUndoStack()->push(saveCommand);// First push then make a connect
VAbstractTool::data.UpdatePiece(m_pieceId, newDet);// Update piece because first save will not call lite update
connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(new SavePieceOptions(oldDet, newDet, doc, m_pieceId));
}
}

View File

@ -209,10 +209,7 @@ void VToolSeamAllowance::InsertNode(VPieceNode node, quint32 pieceId, VMainGraph
InitNode(node, scene, data, doc, saTool);
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, pieceId);
qApp->getUndoStack()->push(saveCommand);// First push then make a connect
data->UpdatePiece(pieceId, newDet);// Update piece because first save will not call lite update
connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(new SavePieceOptions(oldDet, newDet, doc, pieceId));
}
}
@ -449,7 +446,6 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle
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);
@ -459,6 +455,15 @@ void VToolSeamAllowance::Move(qreal x, qreal y)
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::Update(const VPiece &piece)
{
setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
VAbstractTool::data.UpdatePiece(m_id, piece);
RefreshGeometry();
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
//---------------------------------------------------------------------------------------------------------------------
QString VToolSeamAllowance::getTagName() const
{
@ -653,7 +658,6 @@ void VToolSeamAllowance::SaveMoveDetail(const QPointF& ptPos)
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
moveCommand->setText(tr("move pattern piece label"));
connect(moveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(moveCommand);
}
@ -674,7 +678,6 @@ void VToolSeamAllowance::SaveResizeDetail(qreal dLabelW, int iFontSize)
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
resizeCommand->setText(tr("resize pattern piece label"));
connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(resizeCommand);
}
@ -696,7 +699,6 @@ void VToolSeamAllowance::SaveRotationDetail(qreal dRot)
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
rotateCommand->setText(tr("rotate pattern piece label"));
connect(rotateCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(rotateCommand);
}
@ -713,7 +715,6 @@ void VToolSeamAllowance::SaveMovePattern(const QPointF &ptPos)
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
moveCommand->setText(tr("move pattern info label"));
connect(moveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(moveCommand);
}
@ -734,7 +735,6 @@ void VToolSeamAllowance::SaveResizePattern(qreal dLabelW, int iFontSize)
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
resizeCommand->setText(tr("resize pattern info label"));
connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(resizeCommand);
}
@ -754,7 +754,6 @@ void VToolSeamAllowance::SaveRotationPattern(qreal dRot)
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
rotateCommand->setText(tr("rotate pattern info label"));
connect(rotateCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(rotateCommand);
}
@ -769,7 +768,6 @@ void VToolSeamAllowance::SaveMoveGrainline(const QPointF& ptPos)
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
moveCommand->setText(tr("move grainline"));
connect(moveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(moveCommand);
}
@ -782,9 +780,9 @@ void VToolSeamAllowance::SaveResizeGrainline(qreal dLength)
dLength = FromPixel(dLength, *VDataTool::data.GetPatternUnit());
newDet.GetGrainlineGeometry().SetPos(m_grainLine->pos());
newDet.GetGrainlineGeometry().SetLength(QString().setNum(dLength));
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
resizeCommand->setText(tr("resize grainline"));
connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(resizeCommand);
}
@ -796,9 +794,9 @@ void VToolSeamAllowance::SaveRotateGrainline(qreal dRot, const QPointF& ptPos)
newDet.GetGrainlineGeometry().SetRotation(QString().setNum(qRadiansToDegrees(dRot)));
newDet.GetGrainlineGeometry().SetPos(ptPos);
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
rotateCommand->setText(tr("rotate grainline"));
connect(rotateCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(rotateCommand);
}
@ -1247,6 +1245,10 @@ void VToolSeamAllowance::RefreshGeometry()
m_seamAllowance->setPath(QPainterPath());
}
UpdateDetailLabel();
UpdatePatternInfo();
UpdateGrainline();
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
@ -1259,9 +1261,7 @@ void VToolSeamAllowance::SaveDialogChange()
const VPiece newDet = dialogTool->GetPiece();
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(saveCommand);
qApp->getUndoStack()->push(new SavePieceOptions(oldDet, newDet, doc, m_id));
UpdateDetailLabel();
}

View File

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

View File

@ -55,10 +55,6 @@ SavePieceOptions::SavePieceOptions(const VPiece &oldDet, const VPiece &newDet, V
nodeId = id;
}
//---------------------------------------------------------------------------------------------------------------------
SavePieceOptions::~SavePieceOptions()
{}
//---------------------------------------------------------------------------------------------------------------------
void SavePieceOptions::undo()
{
@ -77,11 +73,22 @@ void SavePieceOptions::undo()
VToolSeamAllowance::AddInternalPaths(doc, domElement, m_oldDet.GetInternalPaths());
VToolSeamAllowance::AddPins(doc, domElement, m_oldDet.GetPins());
DecrementReferences(m_newDet.MissingNodes(m_oldDet));
IncrementReferences(m_oldDet.MissingNodes(m_newDet));
DecrementReferences(m_newDet.MissingCSAPath(m_oldDet));
IncrementReferences(m_oldDet.MissingCSAPath(m_newDet));
DecrementReferences(m_newDet.MissingInternalPaths(m_oldDet));
IncrementReferences(m_oldDet.MissingInternalPaths(m_newDet));
DecrementReferences(m_newDet.MissingPins(m_oldDet));
IncrementReferences(m_oldDet.MissingPins(m_newDet));
emit NeedLiteParsing(Document::LiteParse);
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId)))
{
tool->Update(m_oldDet);
}
}
else
{
@ -108,36 +115,24 @@ void SavePieceOptions::redo()
VToolSeamAllowance::AddPins(doc, domElement, m_newDet.GetPins());
DecrementReferences(m_oldDet.MissingNodes(m_newDet));
DecrementReferences(m_oldDet.MissingCSAPath(m_newDet));
DecrementReferences(m_oldDet.MissingInternalPaths(m_newDet));
DecrementReferences(m_oldDet.MissingPins(m_newDet));
IncrementReferences(m_newDet.MissingNodes(m_oldDet));
emit NeedLiteParsing(Document::LiteParse);
DecrementReferences(m_oldDet.MissingCSAPath(m_newDet));
IncrementReferences(m_newDet.MissingCSAPath(m_oldDet));
DecrementReferences(m_oldDet.MissingInternalPaths(m_newDet));
IncrementReferences(m_newDet.MissingInternalPaths(m_oldDet));
DecrementReferences(m_oldDet.MissingPins(m_newDet));
IncrementReferences(m_newDet.MissingPins(m_oldDet));
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId)))
{
tool->Update(m_newDet);
}
}
else
{
qCDebug(vUndo, "Can't find detail with id = %u.", nodeId);
}
}
//---------------------------------------------------------------------------------------------------------------------
bool SavePieceOptions::mergeWith(const QUndoCommand *command)
{
const SavePieceOptions *saveCommand = static_cast<const SavePieceOptions *>(command);
SCASSERT(saveCommand != nullptr);
const quint32 id = saveCommand->DetId();
if (id != nodeId)
{
return false;
}
m_newDet = saveCommand->NewDet();
return true;
}
//---------------------------------------------------------------------------------------------------------------------
int SavePieceOptions::id() const
{
return static_cast<int>(UndoCommand::SavePieceOptions);
}

View File

@ -39,14 +39,10 @@ class SavePieceOptions : public VUndoCommand
public:
SavePieceOptions(const VPiece &oldDet, const VPiece &newDet, VAbstractPattern *doc, quint32 id,
QUndoCommand *parent = nullptr);
virtual ~SavePieceOptions();
virtual ~SavePieceOptions() =default;
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 DetId() const;
VPiece NewDet() const;
private:
Q_DISABLE_COPY(SavePieceOptions)
@ -54,16 +50,4 @@ private:
VPiece m_newDet;
};
//---------------------------------------------------------------------------------------------------------------------
inline quint32 SavePieceOptions::DetId() const
{
return nodeId;
}
//---------------------------------------------------------------------------------------------------------------------
inline VPiece SavePieceOptions::NewDet() const
{
return m_newDet;
}
#endif // SAVEPIECEOPTIONS_H