Fix crash when remove pieces.

This commit is contained in:
Roman Telezhynskyi 2024-04-18 20:12:11 +03:00
parent 6eb702b778
commit ce1634e1ab
2 changed files with 43 additions and 8 deletions

View File

@ -639,6 +639,10 @@ void VPMainGraphicsView::RemovePiece() const
} }
const QList<VPGraphicsPiece *> &graphicsPieces = sheet->SceneData()->GraphicsPieces(); const QList<VPGraphicsPiece *> &graphicsPieces = sheet->SceneData()->GraphicsPieces();
QVector<VPUndoMovePieceOnSheet *> commands;
commands.reserve(graphicsPieces.size());
for (auto *graphicsPiece : graphicsPieces) for (auto *graphicsPiece : graphicsPieces)
{ {
VPPiecePtr const piece = graphicsPiece->GetPiece(); VPPiecePtr const piece = graphicsPiece->GetPiece();
@ -646,15 +650,26 @@ void VPMainGraphicsView::RemovePiece() const
if (not piece.isNull() && piece->IsSelected()) if (not piece.isNull() && piece->IsSelected())
{ {
piece->SetSelected(false); piece->SetSelected(false);
emit layout->PieceSelectionChanged(piece);
VPLayoutPtr const layout = m_layout.toStrongRef(); commands.append(new VPUndoMovePieceOnSheet(VPSheetPtr(), piece));
if (not layout.isNull())
{
emit layout->PieceSelectionChanged(piece);
layout->UndoStack()->push(new VPUndoMovePieceOnSheet(VPSheetPtr(), piece));
}
} }
} }
if (commands.size() > 1)
{
layout->UndoStack()->beginMacro(tr("Remove pieces"));
}
for (auto *command : commands)
{
layout->UndoStack()->push(command);
}
if (commands.size() > 1)
{
layout->UndoStack()->endMacro();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -76,9 +76,26 @@ void VPUndoMovePieceOnSheet::undo()
piece->SetSheet(sourceSheet); piece->SetSheet(sourceSheet);
piece->SetSelected(false); piece->SetSelected(false);
if ((m_followGrainline || piece->IsFollowGrainline()) && !sourceSheet.isNull())
{
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wnoexcept")
VPTransformationOrigon origin;
origin.custom = true;
QT_WARNING_POP
piece->RotateToGrainline(origin);
}
if (not layout.isNull()) if (not layout.isNull())
{ {
emit layout->PieceSheetChanged(piece); emit layout->PieceSheetChanged(piece);
if (!sourceSheet.isNull())
{
emit layout->PieceTransformationChanged(piece);
}
emit layout->PieceSelectionChanged(piece); emit layout->PieceSelectionChanged(piece);
} }
} }
@ -115,7 +132,7 @@ void VPUndoMovePieceOnSheet::redo()
piece->SetSelected(false); piece->SetSelected(false);
} }
if (m_followGrainline || piece->IsFollowGrainline()) if ((m_followGrainline || piece->IsFollowGrainline()) && !sourceSheet.isNull())
{ {
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wnoexcept") QT_WARNING_DISABLE_GCC("-Wnoexcept")
@ -131,7 +148,10 @@ void VPUndoMovePieceOnSheet::redo()
if (not layout.isNull()) if (not layout.isNull())
{ {
emit layout->PieceSheetChanged(piece); emit layout->PieceSheetChanged(piece);
emit layout->PieceTransformationChanged(piece); if (!sourceSheet.isNull())
{
emit layout->PieceTransformationChanged(piece);
}
emit layout->LayoutChanged(); emit layout->LayoutChanged();
} }
} }