Undo/Redo transformation origin move.
This commit is contained in:
parent
9a7e4e5ea6
commit
18d9417c96
|
@ -28,6 +28,7 @@
|
||||||
#ifndef LAYOUTDEF_H
|
#ifndef LAYOUTDEF_H
|
||||||
#define LAYOUTDEF_H
|
#define LAYOUTDEF_H
|
||||||
|
|
||||||
|
#include <QPointF>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
class VPLayout;
|
class VPLayout;
|
||||||
|
@ -42,4 +43,16 @@ class VPSheet;
|
||||||
using VPSheetPtr = QSharedPointer<VPSheet>;
|
using VPSheetPtr = QSharedPointer<VPSheet>;
|
||||||
using VPSheetWeakPtr = QWeakPointer<VPSheet>;
|
using VPSheetWeakPtr = QWeakPointer<VPSheet>;
|
||||||
|
|
||||||
|
enum class GrainlineType : qint8
|
||||||
|
{
|
||||||
|
Vertical,
|
||||||
|
Horizontal
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VPTransformationOrigon
|
||||||
|
{
|
||||||
|
QPointF origin{};
|
||||||
|
bool custom{false};
|
||||||
|
};
|
||||||
|
|
||||||
#endif // LAYOUTDEF_H
|
#endif // LAYOUTDEF_H
|
||||||
|
|
|
@ -88,6 +88,7 @@ signals:
|
||||||
void PieceSheetChanged(const VPPiecePtr &piece);
|
void PieceSheetChanged(const VPPiecePtr &piece);
|
||||||
void ActiveSheetChanged(const VPSheetPtr &focusedSheet);
|
void ActiveSheetChanged(const VPSheetPtr &focusedSheet);
|
||||||
void PieceTransformationChanged(const VPPiecePtr &piece);
|
void PieceTransformationChanged(const VPPiecePtr &piece);
|
||||||
|
void TransformationOriginChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit VPLayout(QUndoStack *undoStack);
|
explicit VPLayout(QUndoStack *undoStack);
|
||||||
|
|
|
@ -40,18 +40,6 @@
|
||||||
class VPLayout;
|
class VPLayout;
|
||||||
class VPPiece;
|
class VPPiece;
|
||||||
|
|
||||||
enum class GrainlineType : qint8
|
|
||||||
{
|
|
||||||
Vertical,
|
|
||||||
Horizontal
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VPTransformationOrigon
|
|
||||||
{
|
|
||||||
QPointF origin{};
|
|
||||||
bool custom{false};
|
|
||||||
};
|
|
||||||
|
|
||||||
class VPSheet
|
class VPSheet
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -8,6 +8,7 @@ SOURCES += \
|
||||||
$$PWD/dialogs/vpdialogabout.cpp \
|
$$PWD/dialogs/vpdialogabout.cpp \
|
||||||
$$PWD/main.cpp \
|
$$PWD/main.cpp \
|
||||||
$$PWD/undocommands/vpundocommand.cpp \
|
$$PWD/undocommands/vpundocommand.cpp \
|
||||||
|
$$PWD/undocommands/vpundooriginmove.cpp \
|
||||||
$$PWD/undocommands/vpundopiecemove.cpp \
|
$$PWD/undocommands/vpundopiecemove.cpp \
|
||||||
$$PWD/undocommands/vpundopiecerotate.cpp \
|
$$PWD/undocommands/vpundopiecerotate.cpp \
|
||||||
$$PWD/vpapplication.cpp \
|
$$PWD/vpapplication.cpp \
|
||||||
|
@ -45,6 +46,7 @@ HEADERS += \
|
||||||
$$PWD/scene/scenedef.h \
|
$$PWD/scene/scenedef.h \
|
||||||
$$PWD/stable.h \
|
$$PWD/stable.h \
|
||||||
$$PWD/undocommands/vpundocommand.h \
|
$$PWD/undocommands/vpundocommand.h \
|
||||||
|
$$PWD/undocommands/vpundooriginmove.h \
|
||||||
$$PWD/undocommands/vpundopiecemove.h \
|
$$PWD/undocommands/vpundopiecemove.h \
|
||||||
$$PWD/undocommands/vpundopiecerotate.h \
|
$$PWD/undocommands/vpundopiecerotate.h \
|
||||||
$$PWD/vpapplication.h \
|
$$PWD/vpapplication.h \
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "../vwidgets/global.h"
|
#include "../vwidgets/global.h"
|
||||||
#include "../layout/vplayout.h"
|
#include "../layout/vplayout.h"
|
||||||
#include "../undocommands/vpundopiecerotate.h"
|
#include "../undocommands/vpundopiecerotate.h"
|
||||||
|
#include "../undocommands/vpundooriginmove.h"
|
||||||
#include "vpgraphicspiece.h"
|
#include "vpgraphicspiece.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -93,12 +94,16 @@ VPGraphicsTransformationOrigin::VPGraphicsTransformationOrigin(const VPLayoutPtr
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
setZValue(1);
|
setZValue(1);
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
|
|
||||||
|
connect(layout.get(), &VPLayout::TransformationOriginChanged, this,
|
||||||
|
&VPGraphicsTransformationOrigin::SetTransformationOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPGraphicsTransformationOrigin::SetTransformationOrigin()
|
void VPGraphicsTransformationOrigin::SetTransformationOrigin()
|
||||||
{
|
{
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -181,11 +186,14 @@ void VPGraphicsTransformationOrigin::mouseMoveEvent(QGraphicsSceneMouseEvent *ev
|
||||||
VPTransformationOrigon origin = sheet->TransformationOrigin();
|
VPTransformationOrigon origin = sheet->TransformationOrigin();
|
||||||
origin.origin = event->scenePos();
|
origin.origin = event->scenePos();
|
||||||
origin.custom = true;
|
origin.custom = true;
|
||||||
sheet->SetTransformationOrigin(origin);
|
|
||||||
|
auto *command = new VPUndoOriginMove(sheet, origin, m_allowChangeMerge);
|
||||||
|
layout->UndoStack()->push(command);
|
||||||
}
|
}
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_allowChangeMerge = true;
|
||||||
QGraphicsObject::mouseMoveEvent(event);
|
QGraphicsObject::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +207,7 @@ void VPGraphicsTransformationOrigin::mouseReleaseEvent(QGraphicsSceneMouseEvent
|
||||||
if (event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
m_allowChangeMerge = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -779,7 +788,7 @@ auto VPGraphicsPieceControls::SelectedPieces() const -> QVector<VPGraphicsPiece
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto VPGraphicsPieceControls::PiecesBoundingRect(const QVector<VPGraphicsPiece *> &selectedPieces) const -> QRectF
|
auto VPGraphicsPieceControls::PiecesBoundingRect(const QVector<VPGraphicsPiece *> &selectedPieces) -> QRectF
|
||||||
{
|
{
|
||||||
QRectF rect;
|
QRectF rect;
|
||||||
for (auto *item : selectedPieces)
|
for (auto *item : selectedPieces)
|
||||||
|
|
|
@ -69,6 +69,7 @@ private:
|
||||||
bool m_originVisible{true};
|
bool m_originVisible{true};
|
||||||
VPLayoutWeakPtr m_layout{};
|
VPLayoutWeakPtr m_layout{};
|
||||||
QColor m_color;
|
QColor m_color;
|
||||||
|
bool m_allowChangeMerge{false};
|
||||||
|
|
||||||
auto RotationCenter(QPainter *painter = nullptr) const -> QPainterPath;
|
auto RotationCenter(QPainter *painter = nullptr) const -> QPainterPath;
|
||||||
auto Center1() const -> QPainterPath;
|
auto Center1() const -> QPainterPath;
|
||||||
|
@ -127,9 +128,10 @@ private:
|
||||||
|
|
||||||
auto ArrowPath() const -> QPainterPath;
|
auto ArrowPath() const -> QPainterPath;
|
||||||
|
|
||||||
auto SelectedPieces() const -> QVector<VPGraphicsPiece *>;
|
|
||||||
auto PiecesBoundingRect(const QVector<VPGraphicsPiece *> &selectedPieces) const -> QRectF;
|
|
||||||
auto HandleCorner(const QPointF &pos) const -> int;
|
auto HandleCorner(const QPointF &pos) const -> int;
|
||||||
|
|
||||||
|
auto SelectedPieces() const -> QVector<VPGraphicsPiece *>;
|
||||||
|
static auto PiecesBoundingRect(const QVector<VPGraphicsPiece *> &selectedPieces) -> QRectF;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VPGRAPHICSPIECECONTROLS_H
|
#endif // VPGRAPHICSPIECECONTROLS_H
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
#include "vpgraphicspiececontrols.h"
|
#include "vpgraphicspiececontrols.h"
|
||||||
#include "../undocommands/vpundopiecemove.h"
|
#include "../undocommands/vpundopiecemove.h"
|
||||||
#include "../undocommands/vpundopiecerotate.h"
|
#include "../undocommands/vpundopiecerotate.h"
|
||||||
|
#include "../undocommands/vpundooriginmove.h"
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
|
|
||||||
|
@ -440,9 +441,23 @@ void VPMainGraphicsView::RestoreOrigin() const
|
||||||
if (not sheet.isNull())
|
if (not sheet.isNull())
|
||||||
{
|
{
|
||||||
VPTransformationOrigon origin = sheet->TransformationOrigin();
|
VPTransformationOrigon origin = sheet->TransformationOrigin();
|
||||||
origin.custom = false;
|
if (origin.custom)
|
||||||
sheet->SetTransformationOrigin(origin);
|
{ // ignore if not custom. Prevent double call
|
||||||
m_rotationControls->on_UpdateControls();
|
origin.custom = false;
|
||||||
|
|
||||||
|
QRectF boundingRect;
|
||||||
|
for (auto *graphicsPiece : m_graphicsPieces)
|
||||||
|
{
|
||||||
|
if (graphicsPiece->isSelected())
|
||||||
|
{
|
||||||
|
boundingRect = boundingRect.united(graphicsPiece->sceneBoundingRect());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
origin.origin = boundingRect.center();
|
||||||
|
|
||||||
|
auto *command = new VPUndoOriginMove(sheet, origin);
|
||||||
|
layout->UndoStack()->push(command);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
Q_LOGGING_CATEGORY(vpUndo, "vp.undo")
|
Q_LOGGING_CATEGORY(vpUndo, "vp.undo")
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPUndoCommand::VPUndoCommand(QUndoCommand *parent)
|
VPUndoCommand::VPUndoCommand(bool allowMerge, QUndoCommand *parent)
|
||||||
: QUndoCommand(parent)
|
: QUndoCommand(parent),
|
||||||
|
m_allowMerge(allowMerge)
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -40,6 +40,7 @@ enum class UndoCommand: qint8
|
||||||
MovePieces = 1,
|
MovePieces = 1,
|
||||||
RotatePiece = 2,
|
RotatePiece = 2,
|
||||||
RotatePieces = 3,
|
RotatePieces = 3,
|
||||||
|
MoveOrigin = 4,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,11 +50,23 @@ class VPUndoCommand : public QObject, public QUndoCommand
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit VPUndoCommand(QUndoCommand *parent = nullptr);
|
explicit VPUndoCommand(bool allowMerge = false, QUndoCommand *parent = nullptr);
|
||||||
virtual ~VPUndoCommand() =default;
|
virtual ~VPUndoCommand() =default;
|
||||||
|
|
||||||
|
auto AllowMerge() const -> bool;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool m_allowMerge;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VPUndoCommand)
|
Q_DISABLE_COPY(VPUndoCommand)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPUndoCommand::AllowMerge() const -> bool
|
||||||
|
{
|
||||||
|
return m_allowMerge;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // VPUNDOCOMMAND_H
|
#endif // VPUNDOCOMMAND_H
|
||||||
|
|
121
src/app/puzzle/undocommands/vpundooriginmove.cpp
Normal file
121
src/app/puzzle/undocommands/vpundooriginmove.cpp
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vpundooriginmove.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 "vpundooriginmove.h"
|
||||||
|
#include "../vmisc/def.h"
|
||||||
|
#include "../layout/vpsheet.h"
|
||||||
|
#include "../layout/vplayout.h"
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPUndoOriginMove::VPUndoOriginMove(const VPSheetPtr &sheet, const VPTransformationOrigon &origin, bool allowMerge,
|
||||||
|
QUndoCommand *parent)
|
||||||
|
: VPUndoCommand(allowMerge, parent),
|
||||||
|
m_sheet(sheet),
|
||||||
|
m_origin(origin)
|
||||||
|
{
|
||||||
|
SCASSERT(not sheet.isNull())
|
||||||
|
|
||||||
|
m_oldOrigin = sheet->TransformationOrigin();
|
||||||
|
|
||||||
|
setText(QObject::tr("move transformation origin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPUndoOriginMove::undo()
|
||||||
|
{
|
||||||
|
VPSheetPtr sheet = m_sheet.toStrongRef();
|
||||||
|
if (sheet.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VPLayoutPtr layout = sheet->GetLayout();
|
||||||
|
if (layout.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
layout->SetFocusedSheet(sheet);
|
||||||
|
|
||||||
|
sheet->SetTransformationOrigin(m_oldOrigin);
|
||||||
|
layout->TransformationOriginChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPUndoOriginMove::redo()
|
||||||
|
{
|
||||||
|
VPSheetPtr sheet = m_sheet.toStrongRef();
|
||||||
|
if (sheet.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VPLayoutPtr layout = sheet->GetLayout();
|
||||||
|
if (layout.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
layout->SetFocusedSheet(sheet);
|
||||||
|
|
||||||
|
sheet->SetTransformationOrigin(m_origin);
|
||||||
|
layout->TransformationOriginChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto VPUndoOriginMove::mergeWith(const QUndoCommand *command) -> bool
|
||||||
|
{
|
||||||
|
if (command->id() != id()) // make sure other is also an VPUndoPieceMove command
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto *moveCommand = dynamic_cast<const VPUndoOriginMove *>(command);
|
||||||
|
SCASSERT(moveCommand != nullptr)
|
||||||
|
|
||||||
|
VPSheetPtr sheet = Sheet();
|
||||||
|
if (moveCommand->Sheet().isNull() || sheet.isNull() || not moveCommand->AllowMerge())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
VPTransformationOrigon origin = moveCommand->Origin();
|
||||||
|
|
||||||
|
if (origin.custom != m_origin.custom)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_origin.origin += origin.origin;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto VPUndoOriginMove::id() const -> int
|
||||||
|
{
|
||||||
|
return static_cast<int>(ML::UndoCommand::MoveOrigin);
|
||||||
|
}
|
73
src/app/puzzle/undocommands/vpundooriginmove.h
Normal file
73
src/app/puzzle/undocommands/vpundooriginmove.h
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vpundooriginmove.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 VPUNDOORIGINMOVE_H
|
||||||
|
#define VPUNDOORIGINMOVE_H
|
||||||
|
|
||||||
|
#include "vpundocommand.h"
|
||||||
|
|
||||||
|
#include "../layout/layoutdef.h"
|
||||||
|
|
||||||
|
class VPUndoOriginMove : public VPUndoCommand
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
VPUndoOriginMove(const VPSheetPtr &sheet, const VPTransformationOrigon &origin, bool allowMerge = false,
|
||||||
|
QUndoCommand *parent = nullptr);
|
||||||
|
virtual ~VPUndoOriginMove()=default;
|
||||||
|
|
||||||
|
virtual void undo() override;
|
||||||
|
virtual void redo() override;
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
virtual auto mergeWith(const QUndoCommand *command) -> bool override;
|
||||||
|
virtual auto id() const -> int override ;
|
||||||
|
|
||||||
|
auto Sheet() const -> VPSheetWeakPtr;
|
||||||
|
auto Origin() const -> const VPTransformationOrigon &;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(VPUndoOriginMove)
|
||||||
|
|
||||||
|
VPSheetWeakPtr m_sheet;
|
||||||
|
VPTransformationOrigon m_oldOrigin{};
|
||||||
|
VPTransformationOrigon m_origin{};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPUndoOriginMove::Sheet() const -> VPSheetWeakPtr
|
||||||
|
{
|
||||||
|
return m_sheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPUndoOriginMove::Origin() const ->const VPTransformationOrigon &
|
||||||
|
{
|
||||||
|
return m_origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // VPUNDOORIGINMOVE_H
|
|
@ -32,11 +32,10 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPUndoPieceMove::VPUndoPieceMove(const VPPiecePtr &piece, qreal dx, qreal dy, bool allowMerge, QUndoCommand *parent)
|
VPUndoPieceMove::VPUndoPieceMove(const VPPiecePtr &piece, qreal dx, qreal dy, bool allowMerge, QUndoCommand *parent)
|
||||||
: VPUndoCommand(parent),
|
: VPUndoCommand(allowMerge, parent),
|
||||||
m_piece(piece),
|
m_piece(piece),
|
||||||
m_dx(dx),
|
m_dx(dx),
|
||||||
m_dy(dy),
|
m_dy(dy)
|
||||||
m_allowMerge(allowMerge)
|
|
||||||
{
|
{
|
||||||
SCASSERT(not piece.isNull())
|
SCASSERT(not piece.isNull())
|
||||||
|
|
||||||
|
@ -99,17 +98,8 @@ auto VPUndoPieceMove::mergeWith(const QUndoCommand *command) -> bool
|
||||||
SCASSERT(moveCommand != nullptr)
|
SCASSERT(moveCommand != nullptr)
|
||||||
|
|
||||||
VPPiecePtr piece = Piece();
|
VPPiecePtr piece = Piece();
|
||||||
if (moveCommand->Piece().isNull() || piece.isNull())
|
if (moveCommand->Piece().isNull() || piece.isNull() || moveCommand->Piece() != piece ||
|
||||||
{
|
not moveCommand->AllowMerge())
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (moveCommand->Piece() != piece)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not moveCommand->AllowMerge())
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -129,10 +119,9 @@ auto VPUndoPieceMove::id() const -> int
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPUndoPiecesMove::VPUndoPiecesMove(const QVector<VPPiecePtr> &pieces, qreal dx, qreal dy, bool allowMerge,
|
VPUndoPiecesMove::VPUndoPiecesMove(const QVector<VPPiecePtr> &pieces, qreal dx, qreal dy, bool allowMerge,
|
||||||
QUndoCommand *parent)
|
QUndoCommand *parent)
|
||||||
: VPUndoCommand(parent),
|
: VPUndoCommand(allowMerge, parent),
|
||||||
m_dx(dx),
|
m_dx(dx),
|
||||||
m_dy(dy),
|
m_dy(dy)
|
||||||
m_allowMerge(allowMerge)
|
|
||||||
{
|
{
|
||||||
setText(QObject::tr("move pieces"));
|
setText(QObject::tr("move pieces"));
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,6 @@ public:
|
||||||
auto Piece() const -> VPPiecePtr;
|
auto Piece() const -> VPPiecePtr;
|
||||||
auto Dx() const -> qreal;
|
auto Dx() const -> qreal;
|
||||||
auto Dy() const -> qreal;
|
auto Dy() const -> qreal;
|
||||||
auto AllowMerge() const -> bool;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VPUndoPieceMove)
|
Q_DISABLE_COPY(VPUndoPieceMove)
|
||||||
|
@ -60,7 +59,6 @@ private:
|
||||||
QTransform m_oldTransform{};
|
QTransform m_oldTransform{};
|
||||||
qreal m_dx;
|
qreal m_dx;
|
||||||
qreal m_dy;
|
qreal m_dy;
|
||||||
bool m_allowMerge;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -81,12 +79,6 @@ inline auto VPUndoPieceMove::Dy() const -> qreal
|
||||||
return m_dy;
|
return m_dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline auto VPUndoPieceMove::AllowMerge() const -> bool
|
|
||||||
{
|
|
||||||
return m_allowMerge;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move pieces
|
// Move pieces
|
||||||
class VPUndoPiecesMove : public VPUndoCommand
|
class VPUndoPiecesMove : public VPUndoCommand
|
||||||
{
|
{
|
||||||
|
@ -105,7 +97,6 @@ public:
|
||||||
auto PieceIds() const -> QSet<QString>;
|
auto PieceIds() const -> QSet<QString>;
|
||||||
auto Dx() const -> qreal;
|
auto Dx() const -> qreal;
|
||||||
auto Dy() const -> qreal;
|
auto Dy() const -> qreal;
|
||||||
auto AllowMerge() const -> bool;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VPUndoPiecesMove)
|
Q_DISABLE_COPY(VPUndoPiecesMove)
|
||||||
|
@ -114,7 +105,6 @@ private:
|
||||||
QMap<QString, QTransform> m_oldTransforms{};
|
QMap<QString, QTransform> m_oldTransforms{};
|
||||||
qreal m_dx;
|
qreal m_dx;
|
||||||
qreal m_dy;
|
qreal m_dy;
|
||||||
bool m_allowMerge;
|
|
||||||
|
|
||||||
auto Layout() const -> VPLayoutPtr;
|
auto Layout() const -> VPLayoutPtr;
|
||||||
auto Sheet() const -> VPSheetPtr;
|
auto Sheet() const -> VPSheetPtr;
|
||||||
|
@ -132,10 +122,4 @@ inline auto VPUndoPiecesMove::Dy() const -> qreal
|
||||||
return m_dy;
|
return m_dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline auto VPUndoPiecesMove::AllowMerge() const -> bool
|
|
||||||
{
|
|
||||||
return m_allowMerge;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // VPUNDOPIECEMOVE_H
|
#endif // VPUNDOPIECEMOVE_H
|
||||||
|
|
|
@ -32,11 +32,10 @@
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPUndoPieceRotate::VPUndoPieceRotate(const VPPiecePtr &piece, const QPointF &origin, qreal angle, bool allowMerge,
|
VPUndoPieceRotate::VPUndoPieceRotate(const VPPiecePtr &piece, const QPointF &origin, qreal angle, bool allowMerge,
|
||||||
QUndoCommand *parent)
|
QUndoCommand *parent)
|
||||||
: VPUndoCommand(parent),
|
: VPUndoCommand(allowMerge, parent),
|
||||||
m_piece(piece),
|
m_piece(piece),
|
||||||
m_origin(origin),
|
m_origin(origin),
|
||||||
m_angle(angle),
|
m_angle(angle)
|
||||||
m_allowMerge(allowMerge)
|
|
||||||
{
|
{
|
||||||
SCASSERT(not piece.isNull())
|
SCASSERT(not piece.isNull())
|
||||||
|
|
||||||
|
@ -119,10 +118,9 @@ auto VPUndoPieceRotate::id() const -> int
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPUndoPiecesRotate::VPUndoPiecesRotate(const QVector<VPPiecePtr> &pieces, const QPointF &origin, qreal angle,
|
VPUndoPiecesRotate::VPUndoPiecesRotate(const QVector<VPPiecePtr> &pieces, const QPointF &origin, qreal angle,
|
||||||
bool allowMerge, QUndoCommand *parent)
|
bool allowMerge, QUndoCommand *parent)
|
||||||
: VPUndoCommand(parent),
|
: VPUndoCommand(allowMerge, parent),
|
||||||
m_origin(origin),
|
m_origin(origin),
|
||||||
m_angle(angle),
|
m_angle(angle)
|
||||||
m_allowMerge(allowMerge)
|
|
||||||
{
|
{
|
||||||
setText(QObject::tr("rotate pieces"));
|
setText(QObject::tr("rotate pieces"));
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,6 @@ public:
|
||||||
auto Piece() const -> VPPiecePtr;
|
auto Piece() const -> VPPiecePtr;
|
||||||
auto Origin() const -> QPointF;
|
auto Origin() const -> QPointF;
|
||||||
auto Angle() const -> qreal;
|
auto Angle() const -> qreal;
|
||||||
auto AllowMerge() const -> bool;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VPUndoPieceRotate)
|
Q_DISABLE_COPY(VPUndoPieceRotate)
|
||||||
|
@ -61,7 +60,6 @@ private:
|
||||||
QTransform m_oldTransform{};
|
QTransform m_oldTransform{};
|
||||||
QPointF m_origin;
|
QPointF m_origin;
|
||||||
qreal m_angle;
|
qreal m_angle;
|
||||||
bool m_allowMerge;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -82,12 +80,6 @@ inline auto VPUndoPieceRotate::Angle() const -> qreal
|
||||||
return m_angle;
|
return m_angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline auto VPUndoPieceRotate::AllowMerge() const -> bool
|
|
||||||
{
|
|
||||||
return m_allowMerge;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rotate pieces
|
// Rotate pieces
|
||||||
class VPUndoPiecesRotate : public VPUndoCommand
|
class VPUndoPiecesRotate : public VPUndoCommand
|
||||||
{
|
{
|
||||||
|
@ -106,7 +98,6 @@ public:
|
||||||
auto PieceIds() const -> QSet<QString>;
|
auto PieceIds() const -> QSet<QString>;
|
||||||
auto Origin() const -> QPointF;
|
auto Origin() const -> QPointF;
|
||||||
auto Angle() const -> qreal;
|
auto Angle() const -> qreal;
|
||||||
auto AllowMerge() const -> bool;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VPUndoPiecesRotate)
|
Q_DISABLE_COPY(VPUndoPiecesRotate)
|
||||||
|
@ -115,7 +106,6 @@ private:
|
||||||
QMap<QString, QTransform> m_oldTransforms{};
|
QMap<QString, QTransform> m_oldTransforms{};
|
||||||
QPointF m_origin;
|
QPointF m_origin;
|
||||||
qreal m_angle;
|
qreal m_angle;
|
||||||
bool m_allowMerge;
|
|
||||||
|
|
||||||
auto Layout() const -> VPLayoutPtr;
|
auto Layout() const -> VPLayoutPtr;
|
||||||
auto Sheet() const -> VPSheetPtr;
|
auto Sheet() const -> VPSheetPtr;
|
||||||
|
@ -133,10 +123,4 @@ inline auto VPUndoPiecesRotate::Angle() const -> qreal
|
||||||
return m_angle;
|
return m_angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline auto VPUndoPiecesRotate::AllowMerge() const -> bool
|
|
||||||
{
|
|
||||||
return m_allowMerge;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // VPUNDOPIECEROTATE_H
|
#endif // VPUNDOPIECEROTATE_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user