Improve Save piece options undocommand.
Performance improvement. --HG-- branch : develop
This commit is contained in:
parent
ef41c700f8
commit
6b6c7aff52
|
@ -251,10 +251,7 @@ void VToolPiecePath::AddToFile()
|
||||||
newDet.GetCustomSARecords().append(record);
|
newDet.GetCustomSARecords().append(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId);
|
qApp->getUndoStack()->push(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,10 +148,7 @@ void VToolPin::AddToFile()
|
||||||
|
|
||||||
newDet.GetPins().append(m_id);
|
newDet.GetPins().append(m_id);
|
||||||
|
|
||||||
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId);
|
qApp->getUndoStack()->push(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,10 +209,7 @@ void VToolSeamAllowance::InsertNode(VPieceNode node, quint32 pieceId, VMainGraph
|
||||||
|
|
||||||
InitNode(node, scene, data, doc, saTool);
|
InitNode(node, scene, data, doc, saTool);
|
||||||
|
|
||||||
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, pieceId);
|
qApp->getUndoStack()->push(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,7 +446,6 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle
|
||||||
void VToolSeamAllowance::Move(qreal x, qreal y)
|
void VToolSeamAllowance::Move(qreal x, qreal y)
|
||||||
{
|
{
|
||||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
||||||
// Don't forget to update geometry, because first change never call full parse
|
|
||||||
VPiece detail = VAbstractTool::data.GetPiece(m_id);
|
VPiece detail = VAbstractTool::data.GetPiece(m_id);
|
||||||
detail.SetMx(x);
|
detail.SetMx(x);
|
||||||
detail.SetMy(y);
|
detail.SetMy(y);
|
||||||
|
@ -459,6 +455,15 @@ void VToolSeamAllowance::Move(qreal x, qreal y)
|
||||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
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
|
QString VToolSeamAllowance::getTagName() const
|
||||||
{
|
{
|
||||||
|
@ -653,7 +658,6 @@ void VToolSeamAllowance::SaveMoveDetail(const QPointF& ptPos)
|
||||||
|
|
||||||
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
||||||
moveCommand->setText(tr("move pattern piece label"));
|
moveCommand->setText(tr("move pattern piece label"));
|
||||||
connect(moveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
||||||
qApp->getUndoStack()->push(moveCommand);
|
qApp->getUndoStack()->push(moveCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,7 +678,6 @@ void VToolSeamAllowance::SaveResizeDetail(qreal dLabelW, int iFontSize)
|
||||||
|
|
||||||
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
||||||
resizeCommand->setText(tr("resize pattern piece label"));
|
resizeCommand->setText(tr("resize pattern piece label"));
|
||||||
connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
||||||
qApp->getUndoStack()->push(resizeCommand);
|
qApp->getUndoStack()->push(resizeCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,7 +699,6 @@ void VToolSeamAllowance::SaveRotationDetail(qreal dRot)
|
||||||
|
|
||||||
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
||||||
rotateCommand->setText(tr("rotate pattern piece label"));
|
rotateCommand->setText(tr("rotate pattern piece label"));
|
||||||
connect(rotateCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
||||||
qApp->getUndoStack()->push(rotateCommand);
|
qApp->getUndoStack()->push(rotateCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,7 +715,6 @@ void VToolSeamAllowance::SaveMovePattern(const QPointF &ptPos)
|
||||||
|
|
||||||
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
||||||
moveCommand->setText(tr("move pattern info label"));
|
moveCommand->setText(tr("move pattern info label"));
|
||||||
connect(moveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
||||||
qApp->getUndoStack()->push(moveCommand);
|
qApp->getUndoStack()->push(moveCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -734,7 +735,6 @@ void VToolSeamAllowance::SaveResizePattern(qreal dLabelW, int iFontSize)
|
||||||
|
|
||||||
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
||||||
resizeCommand->setText(tr("resize pattern info label"));
|
resizeCommand->setText(tr("resize pattern info label"));
|
||||||
connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
||||||
qApp->getUndoStack()->push(resizeCommand);
|
qApp->getUndoStack()->push(resizeCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,7 +754,6 @@ void VToolSeamAllowance::SaveRotationPattern(qreal dRot)
|
||||||
|
|
||||||
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
||||||
rotateCommand->setText(tr("rotate pattern info label"));
|
rotateCommand->setText(tr("rotate pattern info label"));
|
||||||
connect(rotateCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
||||||
qApp->getUndoStack()->push(rotateCommand);
|
qApp->getUndoStack()->push(rotateCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,7 +768,6 @@ void VToolSeamAllowance::SaveMoveGrainline(const QPointF& ptPos)
|
||||||
|
|
||||||
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
||||||
moveCommand->setText(tr("move grainline"));
|
moveCommand->setText(tr("move grainline"));
|
||||||
connect(moveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
||||||
qApp->getUndoStack()->push(moveCommand);
|
qApp->getUndoStack()->push(moveCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -782,9 +780,9 @@ void VToolSeamAllowance::SaveResizeGrainline(qreal dLength)
|
||||||
dLength = FromPixel(dLength, *VDataTool::data.GetPatternUnit());
|
dLength = FromPixel(dLength, *VDataTool::data.GetPatternUnit());
|
||||||
newDet.GetGrainlineGeometry().SetPos(m_grainLine->pos());
|
newDet.GetGrainlineGeometry().SetPos(m_grainLine->pos());
|
||||||
newDet.GetGrainlineGeometry().SetLength(QString().setNum(dLength));
|
newDet.GetGrainlineGeometry().SetLength(QString().setNum(dLength));
|
||||||
|
|
||||||
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
||||||
resizeCommand->setText(tr("resize grainline"));
|
resizeCommand->setText(tr("resize grainline"));
|
||||||
connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
||||||
qApp->getUndoStack()->push(resizeCommand);
|
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().SetRotation(QString().setNum(qRadiansToDegrees(dRot)));
|
||||||
newDet.GetGrainlineGeometry().SetPos(ptPos);
|
newDet.GetGrainlineGeometry().SetPos(ptPos);
|
||||||
|
|
||||||
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
||||||
rotateCommand->setText(tr("rotate grainline"));
|
rotateCommand->setText(tr("rotate grainline"));
|
||||||
connect(rotateCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
||||||
qApp->getUndoStack()->push(rotateCommand);
|
qApp->getUndoStack()->push(rotateCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1247,6 +1245,10 @@ void VToolSeamAllowance::RefreshGeometry()
|
||||||
m_seamAllowance->setPath(QPainterPath());
|
m_seamAllowance->setPath(QPainterPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateDetailLabel();
|
||||||
|
UpdatePatternInfo();
|
||||||
|
UpdateGrainline();
|
||||||
|
|
||||||
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1259,9 +1261,7 @@ void VToolSeamAllowance::SaveDialogChange()
|
||||||
const VPiece newDet = dialogTool->GetPiece();
|
const VPiece newDet = dialogTool->GetPiece();
|
||||||
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
|
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
|
||||||
|
|
||||||
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
|
qApp->getUndoStack()->push(new SavePieceOptions(oldDet, newDet, doc, m_id));
|
||||||
connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
||||||
qApp->getUndoStack()->push(saveCommand);
|
|
||||||
UpdateDetailLabel();
|
UpdateDetailLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ public:
|
||||||
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);
|
void Move(qreal x, qreal y);
|
||||||
|
void Update(const VPiece &piece);
|
||||||
|
|
||||||
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)};
|
||||||
|
|
|
@ -55,10 +55,6 @@ SavePieceOptions::SavePieceOptions(const VPiece &oldDet, const VPiece &newDet, V
|
||||||
nodeId = id;
|
nodeId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
SavePieceOptions::~SavePieceOptions()
|
|
||||||
{}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void SavePieceOptions::undo()
|
void SavePieceOptions::undo()
|
||||||
{
|
{
|
||||||
|
@ -77,11 +73,22 @@ void SavePieceOptions::undo()
|
||||||
VToolSeamAllowance::AddInternalPaths(doc, domElement, m_oldDet.GetInternalPaths());
|
VToolSeamAllowance::AddInternalPaths(doc, domElement, m_oldDet.GetInternalPaths());
|
||||||
VToolSeamAllowance::AddPins(doc, domElement, m_oldDet.GetPins());
|
VToolSeamAllowance::AddPins(doc, domElement, m_oldDet.GetPins());
|
||||||
|
|
||||||
|
DecrementReferences(m_newDet.MissingNodes(m_oldDet));
|
||||||
IncrementReferences(m_oldDet.MissingNodes(m_newDet));
|
IncrementReferences(m_oldDet.MissingNodes(m_newDet));
|
||||||
|
|
||||||
|
DecrementReferences(m_newDet.MissingCSAPath(m_oldDet));
|
||||||
IncrementReferences(m_oldDet.MissingCSAPath(m_newDet));
|
IncrementReferences(m_oldDet.MissingCSAPath(m_newDet));
|
||||||
|
|
||||||
|
DecrementReferences(m_newDet.MissingInternalPaths(m_oldDet));
|
||||||
IncrementReferences(m_oldDet.MissingInternalPaths(m_newDet));
|
IncrementReferences(m_oldDet.MissingInternalPaths(m_newDet));
|
||||||
|
|
||||||
|
DecrementReferences(m_newDet.MissingPins(m_oldDet));
|
||||||
IncrementReferences(m_oldDet.MissingPins(m_newDet));
|
IncrementReferences(m_oldDet.MissingPins(m_newDet));
|
||||||
emit NeedLiteParsing(Document::LiteParse);
|
|
||||||
|
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId)))
|
||||||
|
{
|
||||||
|
tool->Update(m_oldDet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -108,36 +115,24 @@ void SavePieceOptions::redo()
|
||||||
VToolSeamAllowance::AddPins(doc, domElement, m_newDet.GetPins());
|
VToolSeamAllowance::AddPins(doc, domElement, m_newDet.GetPins());
|
||||||
|
|
||||||
DecrementReferences(m_oldDet.MissingNodes(m_newDet));
|
DecrementReferences(m_oldDet.MissingNodes(m_newDet));
|
||||||
DecrementReferences(m_oldDet.MissingCSAPath(m_newDet));
|
IncrementReferences(m_newDet.MissingNodes(m_oldDet));
|
||||||
DecrementReferences(m_oldDet.MissingInternalPaths(m_newDet));
|
|
||||||
DecrementReferences(m_oldDet.MissingPins(m_newDet));
|
|
||||||
|
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
qCDebug(vUndo, "Can't find detail with id = %u.", nodeId);
|
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);
|
|
||||||
}
|
|
||||||
|
|
|
@ -39,14 +39,10 @@ class SavePieceOptions : public VUndoCommand
|
||||||
public:
|
public:
|
||||||
SavePieceOptions(const VPiece &oldDet, const VPiece &newDet, VAbstractPattern *doc, quint32 id,
|
SavePieceOptions(const VPiece &oldDet, const VPiece &newDet, VAbstractPattern *doc, quint32 id,
|
||||||
QUndoCommand *parent = nullptr);
|
QUndoCommand *parent = nullptr);
|
||||||
virtual ~SavePieceOptions();
|
virtual ~SavePieceOptions() =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;
|
||||||
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
|
|
||||||
virtual int id() const Q_DECL_OVERRIDE;
|
|
||||||
quint32 DetId() const;
|
|
||||||
VPiece NewDet() const;
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(SavePieceOptions)
|
Q_DISABLE_COPY(SavePieceOptions)
|
||||||
|
|
||||||
|
@ -54,16 +50,4 @@ private:
|
||||||
VPiece m_newDet;
|
VPiece m_newDet;
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline quint32 SavePieceOptions::DetId() const
|
|
||||||
{
|
|
||||||
return nodeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline VPiece SavePieceOptions::NewDet() const
|
|
||||||
{
|
|
||||||
return m_newDet;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // SAVEPIECEOPTIONS_H
|
#endif // SAVEPIECEOPTIONS_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user