Skip to content

Commit

Permalink
Merge pull request #22 from J5lx/MrStevns/undo-redo-manager-v2
Browse files Browse the repository at this point in the history
Fix some issues and housekeeping etc.
  • Loading branch information
MrStevns authored Apr 17, 2024
2 parents bcbee06 + 67d9596 commit 822de83
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 181 deletions.
2 changes: 1 addition & 1 deletion app/src/generalpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void GeneralPage::newUndoRedoCheckBoxStateChanged(bool b)
QMessageBox messageBox(this);
messageBox.setIcon(QMessageBox::Warning);
messageBox.setText(tr("Experimental feature!"));
messageBox.setInformativeText(tr("This feature is work in progress and may not currently allow for the same features as the current backup system. Once enabled, you'll need to restart the application to start using it. \n\nDo you still want to try?"));
messageBox.setInformativeText(tr("This feature is work in progress and may not currently allow for the same features as the current undo/redo system. Once enabled, you'll need to restart the application to start using it. \n\nDo you still want to try?"));
messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);

if (messageBox.exec() == QMessageBox::Yes) {
Expand Down
5 changes: 2 additions & 3 deletions app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,7 @@ void MainWindow2::newObject()

setWindowTitle(PENCIL_WINDOW_TITLE);

mEditor->backups()->updateUndoAction(ui->actionUndo);
mEditor->backups()->updateRedoAction(ui->actionRedo);
updateBackupActionState();
}

bool MainWindow2::newObjectFromPresets(int presetIndex)
Expand Down Expand Up @@ -1643,7 +1642,7 @@ void MainWindow2::createToolbars()
mOverlayToolbar->setIconSize(QSize(22,22));
mViewToolbar->setIconSize(QSize(22,22));
mMainToolbar->setIconSize(QSize(22,22));

QToolButton* perspectiveLinesAngleButton = new QToolButton(this);
perspectiveLinesAngleButton->setDefaultAction(ui->menuPerspectiveLinesAngle->menuAction());
perspectiveLinesAngleButton->setPopupMode(QToolButton::InstantPopup);
Expand Down
2 changes: 1 addition & 1 deletion app/ui/generalpage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@
<item>
<widget class="QCheckBox" name="newUndoRedoCheckBox">
<property name="text">
<string>Enable new Backup System (experimental)</string>
<string>Enable New Undo/Redo System (Experimental)</string>
</property>
</widget>
</item>
Expand Down
15 changes: 5 additions & 10 deletions core_lib/src/interface/backupelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,18 @@ GNU General Public License for more details.
*/

#include <QCoreApplication>
#include "QProgressDialog"
#include <QDebug>

#include "layermanager.h"
#include "backupmanager.h"
#include "viewmanager.h"
#include "selectionmanager.h"

#include "layersound.h"
#include "layerbitmap.h"
#include "layervector.h"
#include "layercamera.h"

#include "editor.h"
#include "backupelement.h"

#include "soundclip.h"
#include "camera.h"

BackupElement::BackupElement(Editor* editor, QUndoCommand* parent) : QUndoCommand(parent)
{
qDebug() << "backupElement created";
Expand All @@ -48,8 +40,8 @@ BackupElement::~BackupElement()

BitmapElement::BitmapElement(const BitmapImage* backupBitmap,
const int backupLayerId,
const QString& description,
Editor *editor,
QString description,
QUndoCommand *parent) : BackupElement(editor, parent)
{

Expand All @@ -76,6 +68,7 @@ void BitmapElement::undo()

void BitmapElement::redo()
{
// Ignore automatic redo when added to undo stack
if (isFirstRedo()) { setFirstRedo(false); return; }

QUndoCommand::redo();
Expand All @@ -88,7 +81,7 @@ void BitmapElement::redo()

VectorElement::VectorElement(const VectorImage* backupVector,
const int& backupLayerId,
QString description,
const QString& description,
Editor* editor,
QUndoCommand* parent) : BackupElement(editor, parent)
{
Expand Down Expand Up @@ -122,6 +115,7 @@ void VectorElement::redo()
{
qDebug() << "BackupVectorElement: redo";

// Ignore automatic redo when added to undo stack
if (isFirstRedo()) { setFirstRedo(false); return; }

QUndoCommand::redo();
Expand Down Expand Up @@ -206,6 +200,7 @@ void TransformElement::undo()

void TransformElement::redo()
{
// Ignore automatic redo when added to undo stack
if (isFirstRedo()) { setFirstRedo(false); return; }

apply(newBitmap,
Expand Down
68 changes: 30 additions & 38 deletions core_lib/src/interface/backupelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ GNU General Public License for more details.
#ifndef BACKUPELEMENT_H
#define BACKUPELEMENT_H

#include <QObject>
#include <QUndoCommand>
#include <QRectF>
#include <QTransform>

#include "movemode.h"
#include "pencildef.h"
#include "layer.h"
#include "vectorselection.h"
#include "preferencemanager.h"
#include "bitmapimage.h"
#include "vectorimage.h"

Expand All @@ -41,25 +34,21 @@ class Layer;
class KeyFrame;
class TransformElement;

enum types { UNDEFINED,
ADD_KEY_MODIF,
REMOVE_KEY_MODIF
};

class BackupElement : public QUndoCommand
{
public:
explicit BackupElement(Editor* editor, QUndoCommand* parent = nullptr);
virtual ~BackupElement();
~BackupElement() override;

void undo() override { Q_ASSUME(true); } // should never end here
void redo() override { Q_ASSUME(true); } // should never end here

protected:
Editor* editor() { return mEditor; }

bool isFirstRedo() const { return mIsFirstRedo; }
void setFirstRedo(bool state) { mIsFirstRedo = state; }
void setFirstRedo(const bool state) { mIsFirstRedo = state; }

virtual int type() const { return UNDEFINED; }
virtual void undo() { Q_ASSUME(true); } // should never end here
virtual void redo() { Q_ASSUME(true); } // should never end here
private:
Editor* mEditor = nullptr;
bool mIsFirstRedo = true;
Expand All @@ -70,14 +59,15 @@ class BitmapElement : public BackupElement

public:
BitmapElement(const BitmapImage* backupBitmap,
const int backupLayerId,
int backupLayerId,
const QString& description,
Editor* editor,
QString description,
QUndoCommand* parent = nullptr);

void undo() override;
void redo() override;

private:
int oldLayerId = 0;
int newLayerId = 0;

Expand All @@ -90,19 +80,19 @@ class VectorElement : public BackupElement
public:
VectorElement(const VectorImage* backupVector,
const int& backupLayerId,
QString description,
const QString& description,
Editor* editor,
QUndoCommand* parent = nullptr);

void undo() override;
void redo() override;

private:
int oldLayerId = 0;
int newLayerId = 0;

VectorImage oldVector;
VectorImage newVector;

void undo() override;
void redo() override;

};

class TransformElement : public BackupElement
Expand All @@ -112,30 +102,32 @@ class TransformElement : public BackupElement

enum { Id = 2 };
TransformElement(KeyFrame* backupKeyFrame,
const int backupLayerId,
int backupLayerId,
const QRectF& backupSelectionRect,
const QPointF backupTranslation,
const qreal backupRotationAngle,
const qreal backupScaleX,
const qreal backupScaleY,
const QPointF backupTransformAnchor,
QPointF backupTranslation,
qreal backupRotationAngle,
qreal backupScaleX,
qreal backupScaleY,
QPointF backupTransformAnchor,
const QString& description,
Editor* editor,
QUndoCommand* parent = nullptr);

void undo() override;
void redo() override;

int id() const override { return Id; }

private:
void apply(const BitmapImage& bitmapImage,
const VectorImage& vectorImage,
const QRectF& selectionRect,
const QPointF translation,
const qreal rotationAngle,
const qreal scaleX,
const qreal scaleY,
const QPointF selectionAnchor,
const int layerId);

int id() const override { return Id; }
QPointF translation,
qreal rotationAngle,
qreal scaleX,
qreal scaleY,
QPointF selectionAnchor,
int layerId);

QRectF oldSelectionRect;
QRectF newSelectionRect;
Expand Down
13 changes: 1 addition & 12 deletions core_lib/src/interface/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Editor : public QObject
* @return The newly created keyframe or `nullptr` if the layer is not visible
*/
KeyFrame* addNewKey();
/**
/**
* Attempts to create a new keyframe at the given position and layer. If a keyframe already exists at the position,
* the new one will instead be created on the first empty frame that follows. If the layer is not visible, a warning
* dialog will be shown to the user and no new keyframe is created.
Expand All @@ -205,17 +205,6 @@ class Editor : public QObject

void backup(const QString& undoText);
bool backup(int layerNumber, int frameNumber, const QString& undoText);
/**
* Restores integrity of the backup elements after a layer has been deleted.
* Removes backup elements affecting the deleted layer and adjusts the layer
* index on other backup elements as necessary.
*
* @param layerIndex The index of the layer that was deleted
*
* @warning This serves as a temporary hack to prevent crashes until #864 is done
* (see #1412).
*/
void sanitizeBackupElementsAfterLayerDeletion(int layerIndex);

void onCurrentLayerWillChange(int index);

Expand Down
Loading

0 comments on commit 822de83

Please sign in to comment.