Fix SavePiecePathOptions undocommand.

Bug with increment/decrement reference counter.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-10-18 11:58:01 +03:00
parent 6b6c7aff52
commit 1fbb65d21d
2 changed files with 3 additions and 43 deletions

View File

@ -49,10 +49,6 @@ SavePiecePathOptions::SavePiecePathOptions(const VPiecePath &oldPath, const VPie
nodeId = id; nodeId = id;
} }
//---------------------------------------------------------------------------------------------------------------------
SavePiecePathOptions::~SavePiecePathOptions()
{}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void SavePiecePathOptions::undo() void SavePiecePathOptions::undo()
{ {
@ -65,6 +61,7 @@ void SavePiecePathOptions::undo()
doc->RemoveAllChildren(domElement);//Very important to clear before rewrite doc->RemoveAllChildren(domElement);//Very important to clear before rewrite
VToolPiecePath::AddNodes(doc, domElement, m_oldPath); VToolPiecePath::AddNodes(doc, domElement, m_oldPath);
DecrementReferences(m_newPath.MissingNodes(m_oldPath));
IncrementReferences(m_oldPath.MissingNodes(m_newPath)); IncrementReferences(m_oldPath.MissingNodes(m_newPath));
SCASSERT(m_data); SCASSERT(m_data);
@ -89,6 +86,7 @@ void SavePiecePathOptions::redo()
VToolPiecePath::AddNodes(doc, domElement, m_newPath); VToolPiecePath::AddNodes(doc, domElement, m_newPath);
DecrementReferences(m_oldPath.MissingNodes(m_newPath)); DecrementReferences(m_oldPath.MissingNodes(m_newPath));
IncrementReferences(m_newPath.MissingNodes(m_oldPath));
SCASSERT(m_data); SCASSERT(m_data);
m_data->UpdatePiecePath(nodeId, m_newPath); m_data->UpdatePiecePath(nodeId, m_newPath);
@ -98,37 +96,3 @@ void SavePiecePathOptions::redo()
qCDebug(vUndo, "Can't find path with id = %u.", nodeId); qCDebug(vUndo, "Can't find path with id = %u.", nodeId);
} }
} }
//---------------------------------------------------------------------------------------------------------------------
bool SavePiecePathOptions::mergeWith(const QUndoCommand *command)
{
const SavePiecePathOptions *saveCommand = static_cast<const SavePiecePathOptions *>(command);
SCASSERT(saveCommand != nullptr);
const quint32 id = saveCommand->PathId();
if (id != nodeId)
{
return false;
}
m_newPath = saveCommand->NewPath();
return true;
}
//---------------------------------------------------------------------------------------------------------------------
int SavePiecePathOptions::id() const
{
return static_cast<int>(UndoCommand::SavePiecePathOptions);
}
//---------------------------------------------------------------------------------------------------------------------
quint32 SavePiecePathOptions::PathId() const
{
return nodeId;
}
//---------------------------------------------------------------------------------------------------------------------
VPiecePath SavePiecePathOptions::NewPath() const
{
return m_newPath;
}

View File

@ -39,14 +39,10 @@ class SavePiecePathOptions : public VUndoCommand
public: public:
SavePiecePathOptions(const VPiecePath &oldPath, const VPiecePath &newPath, VAbstractPattern *doc, SavePiecePathOptions(const VPiecePath &oldPath, const VPiecePath &newPath, VAbstractPattern *doc,
VContainer *data, quint32 id, QUndoCommand *parent = nullptr); VContainer *data, quint32 id, QUndoCommand *parent = nullptr);
virtual ~SavePiecePathOptions(); virtual ~SavePiecePathOptions()=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 PathId() const;
VPiecePath NewPath() const;
private: private:
Q_DISABLE_COPY(SavePiecePathOptions) Q_DISABLE_COPY(SavePiecePathOptions)