Undo/Redo add sheet.
This commit is contained in:
parent
6da151c604
commit
3f73bd9d75
|
@ -57,6 +57,7 @@ VPCarrousel::VPCarrousel(const VPLayoutPtr &layout, QWidget *parent) :
|
||||||
&VPCarrousel::on_ActivePieceListChanged);
|
&VPCarrousel::on_ActivePieceListChanged);
|
||||||
|
|
||||||
connect(layout.get(), &VPLayout::ActiveSheetChanged, this, &VPCarrousel::on_ActiveSheetChanged);
|
connect(layout.get(), &VPLayout::ActiveSheetChanged, this, &VPCarrousel::on_ActiveSheetChanged);
|
||||||
|
connect(layout.get(), &VPLayout::SheetListChanged, this, &VPCarrousel::Refresh);
|
||||||
|
|
||||||
// ------ then we fill the carrousel with the layout content
|
// ------ then we fill the carrousel with the layout content
|
||||||
Refresh();
|
Refresh();
|
||||||
|
|
|
@ -43,12 +43,19 @@ VPLayout::VPLayout(QUndoStack *undoStack) :
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPLayoutPtr VPLayout::CreateLayout(QUndoStack *undoStack)
|
auto VPLayout::CreateLayout(QUndoStack *undoStack) -> VPLayoutPtr
|
||||||
{
|
{
|
||||||
SCASSERT(undoStack != nullptr)
|
SCASSERT(undoStack != nullptr)
|
||||||
undoStack->clear();
|
undoStack->clear();
|
||||||
VPLayoutPtr layout(new VPLayout(undoStack));
|
VPLayoutPtr layout(new VPLayout(undoStack));
|
||||||
layout->AddTrashSheet(VPSheetPtr(new VPSheet(layout)));
|
layout->AddTrashSheet(VPSheetPtr(new VPSheet(layout)));
|
||||||
|
|
||||||
|
// create a standard sheet
|
||||||
|
VPSheetPtr sheet(new VPSheet(layout));
|
||||||
|
sheet->SetName(tr("Sheet %1").arg(layout->GetSheets().size()+1));
|
||||||
|
layout->AddSheet(sheet);
|
||||||
|
layout->SetFocusedSheet(sheet);
|
||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@ signals:
|
||||||
void ActiveSheetChanged(const VPSheetPtr &focusedSheet);
|
void ActiveSheetChanged(const VPSheetPtr &focusedSheet);
|
||||||
void PieceTransformationChanged(const VPPiecePtr &piece);
|
void PieceTransformationChanged(const VPPiecePtr &piece);
|
||||||
void TransformationOriginChanged();
|
void TransformationOriginChanged();
|
||||||
|
void SheetListChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit VPLayout(QUndoStack *undoStack);
|
explicit VPLayout(QUndoStack *undoStack);
|
||||||
|
|
|
@ -7,6 +7,7 @@ SOURCES += \
|
||||||
$$PWD/dialogs/dialogpuzzlepreferences.cpp \
|
$$PWD/dialogs/dialogpuzzlepreferences.cpp \
|
||||||
$$PWD/dialogs/vpdialogabout.cpp \
|
$$PWD/dialogs/vpdialogabout.cpp \
|
||||||
$$PWD/main.cpp \
|
$$PWD/main.cpp \
|
||||||
|
$$PWD/undocommands/vpundoaddsheet.cpp \
|
||||||
$$PWD/undocommands/vpundocommand.cpp \
|
$$PWD/undocommands/vpundocommand.cpp \
|
||||||
$$PWD/undocommands/vpundomovepieceonsheet.cpp \
|
$$PWD/undocommands/vpundomovepieceonsheet.cpp \
|
||||||
$$PWD/undocommands/vpundooriginmove.cpp \
|
$$PWD/undocommands/vpundooriginmove.cpp \
|
||||||
|
@ -46,6 +47,7 @@ HEADERS += \
|
||||||
$$PWD/layout/layoutdef.h \
|
$$PWD/layout/layoutdef.h \
|
||||||
$$PWD/scene/scenedef.h \
|
$$PWD/scene/scenedef.h \
|
||||||
$$PWD/stable.h \
|
$$PWD/stable.h \
|
||||||
|
$$PWD/undocommands/vpundoaddsheet.h \
|
||||||
$$PWD/undocommands/vpundocommand.h \
|
$$PWD/undocommands/vpundocommand.h \
|
||||||
$$PWD/undocommands/vpundomovepieceonsheet.h \
|
$$PWD/undocommands/vpundomovepieceonsheet.h \
|
||||||
$$PWD/undocommands/vpundooriginmove.h \
|
$$PWD/undocommands/vpundooriginmove.h \
|
||||||
|
|
|
@ -93,6 +93,7 @@ VPMainGraphicsView::VPMainGraphicsView(const VPLayoutPtr &layout, VPTileFactory
|
||||||
|
|
||||||
// add the connections
|
// add the connections
|
||||||
connect(layout.get(), &VPLayout::PieceSheetChanged, this, &VPMainGraphicsView::on_PieceSheetChanged);
|
connect(layout.get(), &VPLayout::PieceSheetChanged, this, &VPMainGraphicsView::on_PieceSheetChanged);
|
||||||
|
connect(layout.get(), &VPLayout::ActiveSheetChanged, this, &VPMainGraphicsView::RefreshPieces);
|
||||||
|
|
||||||
auto *restoreOrigin = new QAction(this);
|
auto *restoreOrigin = new QAction(this);
|
||||||
restoreOrigin->setShortcut(restoreOriginShortcut);
|
restoreOrigin->setShortcut(restoreOriginShortcut);
|
||||||
|
|
89
src/app/puzzle/undocommands/vpundoaddsheet.cpp
Normal file
89
src/app/puzzle/undocommands/vpundoaddsheet.cpp
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vpundoaddsheet.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 "vpundoaddsheet.h"
|
||||||
|
#include "../vmisc/def.h"
|
||||||
|
#include "../layout/vpsheet.h"
|
||||||
|
#include "../layout/vplayout.h"
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPUndoAddSheet::VPUndoAddSheet(const VPSheetPtr &sheet, QUndoCommand *parent)
|
||||||
|
: VPUndoCommand(false, parent),
|
||||||
|
m_sheet(sheet)
|
||||||
|
{
|
||||||
|
SCASSERT(not sheet.isNull())
|
||||||
|
|
||||||
|
setText(tr("add sheet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPUndoAddSheet::undo()
|
||||||
|
{
|
||||||
|
VPSheetPtr sheet = m_sheet.toStrongRef();
|
||||||
|
if (sheet.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sheet->SetVisible(false);
|
||||||
|
|
||||||
|
VPLayoutPtr layout = sheet->GetLayout();
|
||||||
|
if (layout.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit layout->SheetListChanged();
|
||||||
|
layout->SetFocusedSheet(VPSheetPtr());
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPUndoAddSheet::redo()
|
||||||
|
{
|
||||||
|
VPSheetPtr sheet = m_sheet.toStrongRef();
|
||||||
|
if (sheet.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VPLayoutPtr layout = sheet->GetLayout();
|
||||||
|
if (layout.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sheet->SetVisible(true);
|
||||||
|
layout->AddSheet(sheet);
|
||||||
|
emit layout->SheetListChanged();
|
||||||
|
layout->SetFocusedSheet(sheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto VPUndoAddSheet::id() const -> int
|
||||||
|
{
|
||||||
|
return static_cast<int>(ML::UndoCommand::AddSheet);
|
||||||
|
}
|
51
src/app/puzzle/undocommands/vpundoaddsheet.h
Normal file
51
src/app/puzzle/undocommands/vpundoaddsheet.h
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vpundoaddsheet.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 VPUNDOADDSHEET_H
|
||||||
|
#define VPUNDOADDSHEET_H
|
||||||
|
|
||||||
|
#include "vpundocommand.h"
|
||||||
|
|
||||||
|
#include "../layout/layoutdef.h"
|
||||||
|
|
||||||
|
class VPUndoAddSheet : public VPUndoCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit VPUndoAddSheet(const VPSheetPtr &sheet, QUndoCommand *parent = nullptr);
|
||||||
|
virtual ~VPUndoAddSheet()=default;
|
||||||
|
|
||||||
|
virtual void undo() override;
|
||||||
|
virtual void redo() override;
|
||||||
|
virtual auto id() const -> int override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(VPUndoAddSheet)
|
||||||
|
|
||||||
|
VPSheetWeakPtr m_sheet;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VPUNDOADDSHEET_H
|
|
@ -42,6 +42,8 @@ enum class UndoCommand: qint8
|
||||||
RotatePieces = 3,
|
RotatePieces = 3,
|
||||||
MoveOrigin = 4,
|
MoveOrigin = 4,
|
||||||
MoveOnSheet = 5,
|
MoveOnSheet = 5,
|
||||||
|
AddSheet = 6,
|
||||||
|
RemoveSheet = 7,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#include "../vwidgets/vmaingraphicsscene.h"
|
#include "../vwidgets/vmaingraphicsscene.h"
|
||||||
#include "layout/vpsheet.h"
|
#include "layout/vpsheet.h"
|
||||||
#include "dialogs/dialogpuzzlepreferences.h"
|
#include "dialogs/dialogpuzzlepreferences.h"
|
||||||
|
#include "undocommands/vpundoaddsheet.h"
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
|
||||||
#include "../vmisc/backport/qscopeguard.h"
|
#include "../vmisc/backport/qscopeguard.h"
|
||||||
|
@ -77,20 +78,21 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
// create a standard sheet
|
|
||||||
AddSheet();
|
|
||||||
|
|
||||||
// ----- for test purposes, to be removed------------------
|
// ----- for test purposes, to be removed------------------
|
||||||
m_layout->LayoutSettings().SetUnit(Unit::Cm);
|
m_layout->LayoutSettings().SetUnit(Unit::Cm);
|
||||||
m_layout->LayoutSettings().SetWarningSuperpositionOfPieces(true);
|
m_layout->LayoutSettings().SetWarningSuperpositionOfPieces(true);
|
||||||
m_layout->LayoutSettings().SetTitle(QString("My Test Layout"));
|
m_layout->LayoutSettings().SetTitle(QString("My Test Layout"));
|
||||||
m_layout->LayoutSettings().SetDescription(QString("Description of my Layout"));
|
m_layout->LayoutSettings().SetDescription(QString("Description of my Layout"));
|
||||||
|
|
||||||
m_layout->LayoutSettings().SetTilesSizeConverted(21,29.7);
|
m_layout->LayoutSettings().SetTilesSizeConverted(21, 29.7);
|
||||||
m_layout->LayoutSettings().SetTilesOrientation(PageOrientation::Portrait);
|
m_layout->LayoutSettings().SetTilesOrientation(PageOrientation::Portrait);
|
||||||
m_layout->LayoutSettings().SetTilesMarginsConverted(1,1,1,1);
|
m_layout->LayoutSettings().SetTilesMarginsConverted(1, 1, 1, 1);
|
||||||
m_layout->LayoutSettings().SetShowTiles(true);
|
m_layout->LayoutSettings().SetShowTiles(true);
|
||||||
|
|
||||||
|
m_layout->LayoutSettings().SetSheetMarginsConverted(1, 1, 1, 1);
|
||||||
|
m_layout->LayoutSettings().SetSheetSizeConverted(84.1, 118.9);
|
||||||
|
m_layout->LayoutSettings().SetPiecesGapConverted(1);
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
|
|
||||||
// init the tile factory
|
// init the tile factory
|
||||||
|
@ -1119,20 +1121,6 @@ void VPMainWindow::CreateWindowMenu(QMenu *menu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
void VPMainWindow::AddSheet()
|
|
||||||
{
|
|
||||||
VPSheetPtr sheet(new VPSheet(m_layout));
|
|
||||||
sheet->SetName(QObject::tr("Sheet %1").arg(m_layout->GetSheets().size()+1));
|
|
||||||
m_layout->AddSheet(sheet);
|
|
||||||
m_layout->SetFocusedSheet(sheet);
|
|
||||||
|
|
||||||
// // ----- for test purposes, to be removed------------------
|
|
||||||
m_layout->LayoutSettings().SetSheetMarginsConverted(1, 1, 1, 1);
|
|
||||||
m_layout->LayoutSettings().SetSheetSizeConverted(84.1, 118.9);
|
|
||||||
m_layout->LayoutSettings().SetPiecesGapConverted(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto VPMainWindow::IsLayoutReadOnly() const -> bool
|
auto VPMainWindow::IsLayoutReadOnly() const -> bool
|
||||||
{
|
{
|
||||||
|
@ -1948,8 +1936,9 @@ void VPMainWindow::ToolBarStyles()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPMainWindow::on_actionAddSheet_triggered()
|
void VPMainWindow::on_actionAddSheet_triggered()
|
||||||
{
|
{
|
||||||
AddSheet();
|
VPSheetPtr sheet(new VPSheet(m_layout));
|
||||||
m_carrousel->Refresh();
|
sheet->SetName(QObject::tr("Sheet %1").arg(m_layout->GetSheets().size()+1));
|
||||||
|
m_layout->UndoStack()->push(new VPUndoAddSheet(sheet));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -562,8 +562,6 @@ private:
|
||||||
|
|
||||||
void CreateWindowMenu(QMenu *menu);
|
void CreateWindowMenu(QMenu *menu);
|
||||||
|
|
||||||
void AddSheet();
|
|
||||||
|
|
||||||
auto IsLayoutReadOnly() const -> bool;
|
auto IsLayoutReadOnly() const -> bool;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,10 @@ void VPLayoutFileWriter::WriteSheets(const VPLayoutPtr &layout)
|
||||||
QList<VPSheetPtr> sheets = layout->GetSheets();
|
QList<VPSheetPtr> sheets = layout->GetSheets();
|
||||||
for (const auto &sheet : sheets)
|
for (const auto &sheet : sheets)
|
||||||
{
|
{
|
||||||
WriteSheet(sheet);
|
if (not sheet.isNull() && sheet->IsVisible())
|
||||||
|
{
|
||||||
|
WriteSheet(sheet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeEndElement(); // sheets
|
writeEndElement(); // sheets
|
||||||
|
|
Loading…
Reference in New Issue
Block a user