Undo/Redo remove sheet.

This commit is contained in:
Roman Telezhynskyi 2021-08-19 16:24:43 +03:00
parent 3f73bd9d75
commit 087d0855dd
6 changed files with 176 additions and 20 deletions

View File

@ -13,6 +13,7 @@ SOURCES += \
$$PWD/undocommands/vpundooriginmove.cpp \
$$PWD/undocommands/vpundopiecemove.cpp \
$$PWD/undocommands/vpundopiecerotate.cpp \
$$PWD/undocommands/vpundoremovesheet.cpp \
$$PWD/vpapplication.cpp \
$$PWD/carousel/vpcarrousel.cpp \
$$PWD/carousel/vpcarrouselpiece.cpp \
@ -53,6 +54,7 @@ HEADERS += \
$$PWD/undocommands/vpundooriginmove.h \
$$PWD/undocommands/vpundopiecemove.h \
$$PWD/undocommands/vpundopiecerotate.h \
$$PWD/undocommands/vpundoremovesheet.h \
$$PWD/vpapplication.h \
$$PWD/carousel/vpcarrousel.h \
$$PWD/carousel/vpcarrouselpiece.h \

View File

@ -49,6 +49,7 @@
#include "../undocommands/vpundopiecerotate.h"
#include "../undocommands/vpundooriginmove.h"
#include "../undocommands/vpundomovepieceonsheet.h"
#include "../undocommands/vpundoremovesheet.h"
#include <QLoggingCategory>
@ -401,22 +402,7 @@ void VPMainGraphicsView::contextMenuEvent(QContextMenuEvent *event)
QAction *selectedAction = menu.exec(event->globalPos());
if (selectedAction == removeSheetAction)
{
if (sheet != nullptr)
{
sheet->SetVisible(false);
QList<VPPiecePtr> pieces = sheet->GetPieces();
for (const auto &piece : pieces)
{
if (not piece.isNull())
{
piece->SetSheet(nullptr);
}
}
}
layout->SetFocusedSheet(VPSheetPtr());
emit on_SheetRemoved();
layout->UndoStack()->push(new VPUndoRemoveSheet(sheet));
}
else if (selectedAction == restoreOriginAction)
{

View File

@ -70,9 +70,6 @@ public:
*/
void CleanAfterExport();
signals:
void on_SheetRemoved();
public slots:
/**
* @brief on_PieceSheetChanged The slot is called when the given piece was moved from the given piece list to

View File

@ -0,0 +1,120 @@
/************************************************************************
**
** @file vpundoremovesheet.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 19 8, 2021
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2021 Valentina project
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vpundoremovesheet.h"
#include "../vmisc/def.h"
#include "../layout/vpsheet.h"
#include "../layout/vppiece.h"
#include "../layout/vplayout.h"
//---------------------------------------------------------------------------------------------------------------------
VPUndoRemoveSheet::VPUndoRemoveSheet(const VPSheetPtr &sheet, QUndoCommand *parent)
: VPUndoCommand(false, parent),
m_sheet(sheet)
{
SCASSERT(not sheet.isNull())
QList<VPPiecePtr> pieces = sheet->GetPieces();
for (auto piece : pieces)
{
m_pieces.append(piece);
}
setText(tr("add sheet"));
}
//---------------------------------------------------------------------------------------------------------------------
void VPUndoRemoveSheet::undo()
{
VPSheetPtr sheet = m_sheet.toStrongRef();
if (sheet.isNull())
{
return;
}
if (not sheet.isNull())
{
sheet->SetVisible(true);
for (const auto &piece : m_pieces)
{
VPPiecePtr p = piece.toStrongRef();
if (not p.isNull())
{
p->SetSheet(sheet);
}
}
VPLayoutPtr layout = sheet->GetLayout();
if (layout.isNull())
{
return;
}
emit layout->SheetListChanged();
layout->SetFocusedSheet(sheet);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPUndoRemoveSheet::redo()
{
VPSheetPtr sheet = m_sheet.toStrongRef();
if (sheet.isNull())
{
return;
}
if (not sheet.isNull())
{
sheet->SetVisible(false);
for (const auto &piece : m_pieces)
{
VPPiecePtr p = piece.toStrongRef();
if (not p.isNull())
{
p->SetSheet(VPSheetPtr());
}
}
}
VPLayoutPtr layout = sheet->GetLayout();
if (layout.isNull())
{
return;
}
emit layout->SheetListChanged();
layout->SetFocusedSheet(VPSheetPtr());
}
//---------------------------------------------------------------------------------------------------------------------
int VPUndoRemoveSheet::id() const
{
return static_cast<int>(ML::UndoCommand::RemoveSheet);
}

View File

@ -0,0 +1,52 @@
/************************************************************************
**
** @file vpundoremovesheet.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 19 8, 2021
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2021 Valentina project
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VPUNDOREMOVESHEET_H
#define VPUNDOREMOVESHEET_H
#include "vpundocommand.h"
#include "../layout/layoutdef.h"
class VPUndoRemoveSheet : public VPUndoCommand
{
public:
explicit VPUndoRemoveSheet(const VPSheetPtr &sheet, QUndoCommand *parent = nullptr);
virtual ~VPUndoRemoveSheet()=default;
virtual void undo() override;
virtual void redo() override;
virtual auto id() const -> int override;
private:
Q_DISABLE_COPY(VPUndoRemoveSheet)
QList<VPPieceWeakPtr> m_pieces{};
VPSheetWeakPtr m_sheet;
};
#endif // VPUNDOREMOVESHEET_H

View File

@ -784,7 +784,6 @@ void VPMainWindow::InitMainGraphics()
connect(m_graphicsView, &VPMainGraphicsView::ScaleChanged, this, &VPMainWindow::on_ScaleChanged);
connect(m_graphicsView->GetScene(), &VMainGraphicsScene::mouseMove, this, &VPMainWindow::on_MouseMoved);
connect(m_graphicsView, &VPMainGraphicsView::on_SheetRemoved, m_carrousel, &VPCarrousel::Refresh);
connect(m_layout.get(), &VPLayout::PieceSheetChanged, m_carrousel, &VPCarrousel::Refresh);
}