Skip to content

Commit

Permalink
Use Qt's undo system instead of 3rdparty/qt-undo
Browse files Browse the repository at this point in the history
Avoids a dependency, at least while QtWidgets is used anyway.
  • Loading branch information
bjorn authored and mitchcurtis committed Apr 5, 2018
1 parent b9cdf97 commit cde31ef
Show file tree
Hide file tree
Showing 71 changed files with 198 additions and 251 deletions.
3 changes: 1 addition & 2 deletions 3rdparty/3rdparty.pro
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
TEMPLATE = subdirs
SUBDIRS += \
pickawinner \
qt-undo
pickawinner
1 change: 0 additions & 1 deletion 3rdparty/qt-undo
Submodule qt-undo deleted from 2e07c4
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ See the [releases](https://github.com/mitchcurtis/slate/releases) page for the a
### Dependencies ###

* Qt >= 5.11
* https://github.com/mitchcurtis/qt-undo
* https://github.com/mitchcurtis/pickawinner

### Cloning ###
Expand All @@ -41,7 +40,7 @@ See the [releases](https://github.com/mitchcurtis/slate/releases) page for the a

### Building ###

qt-undo and pickawinner can be cloned and built separately, but they are also available as submodules of Slate's repo, and can therefore be built automatically when
pickawinner can be cloned and built separately, but it is also available as a submodule of Slate's repo, and can therefore be built automatically when
Slate is built, by first running the following commands:

cd /path/to/slate-source-dir
Expand Down
4 changes: 2 additions & 2 deletions app/addguidecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

Q_LOGGING_CATEGORY(lcAddGuideCommand, "app.undo.addGuideCommand")

AddGuideCommand::AddGuideCommand(Project *project, const Guide &guide, UndoCommand *parent) :
UndoCommand(parent),
AddGuideCommand::AddGuideCommand(Project *project, const Guide &guide, QUndoCommand *parent) :
QUndoCommand(parent),
mProject(project),
mGuide(guide)
{
Expand Down
8 changes: 3 additions & 5 deletions app/addguidecommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@
#define ADDGUIDECOMMAND_H

#include <QDebug>
#include <QtUndo/undocommand.h>
#include <QUndoCommand>

#include "guide.h"

class Project;

class AddGuideCommand : public UndoCommand
class AddGuideCommand : public QUndoCommand
{
Q_OBJECT

public:
AddGuideCommand(Project *project, const Guide &guide, UndoCommand *parent = nullptr);
AddGuideCommand(Project *project, const Guide &guide, QUndoCommand *parent = nullptr);

void undo() override;
void redo() override;
Expand Down
13 changes: 8 additions & 5 deletions app/addlayercommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@

Q_LOGGING_CATEGORY(lcAddLayerCommand, "app.undo.addLayerCommand")

AddLayerCommand::AddLayerCommand(LayeredImageProject *project, ImageLayer *layer, int index, UndoCommand *parent) :
UndoCommand(parent),
AddLayerCommand::AddLayerCommand(LayeredImageProject *project, ImageLayer *layer, int index, QUndoCommand *parent) :
QUndoCommand(parent),
mProject(project),
mIndex(index),
mLayer(layer)
mLayer(layer),
mLayerGuard(layer)
{
qCDebug(lcAddLayerCommand) << "constructed" << this;
}
Expand All @@ -39,14 +40,16 @@ void AddLayerCommand::undo()
{
qCDebug(lcAddLayerCommand) << "undoing" << this;
mProject->takeLayer(mIndex);

// Prevent leaks.
mLayer->setParent(this);
Q_ASSERT(mLayerGuard.isNull());
mLayerGuard.reset(mLayer);
}

void AddLayerCommand::redo()
{
qCDebug(lcAddLayerCommand) << "redoing" << this;
mProject->addLayer(mLayer, mIndex);
mProject->addLayer(mLayerGuard.take(), mIndex);
}

int AddLayerCommand::id() const
Expand Down
10 changes: 5 additions & 5 deletions app/addlayercommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@
#define ADDLAYERCOMMAND_H

#include <QDebug>
#include <QtUndo/undocommand.h>
#include <QScopedPointer>
#include <QUndoCommand>

class ImageLayer;
class LayeredImageProject;

class AddLayerCommand : public UndoCommand
class AddLayerCommand : public QUndoCommand
{
Q_OBJECT

public:
AddLayerCommand(LayeredImageProject *project, ImageLayer *layer, int index, UndoCommand *parent = nullptr);
AddLayerCommand(LayeredImageProject *project, ImageLayer *layer, int index, QUndoCommand *parent = nullptr);

void undo() override;
void redo() override;
Expand All @@ -44,6 +43,7 @@ class AddLayerCommand : public UndoCommand
LayeredImageProject *mProject;
int mIndex;
ImageLayer *mLayer;
QScopedPointer<ImageLayer> mLayerGuard;
};


Expand Down
2 changes: 1 addition & 1 deletion app/app.pri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QT += widgets qml quick undo
QT += widgets qml quick
CONFIG += c++11

INCLUDEPATH += $$PWD
Expand Down
7 changes: 6 additions & 1 deletion app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QApplication>
#include <QFontDatabase>
#include <QLoggingCategory>
#include <QUndoStack>

#include "canvaspane.h"
#include "filevalidator.h"
Expand Down Expand Up @@ -101,9 +102,13 @@ Application::Application(int &argc, char **argv, const QString &applicationName)
qRegisterMetaType<ApplicationSettings*>();
qRegisterMetaType<ImageLayer*>();
qRegisterMetaType<Project::Type>();

// For some reason, only when debugging, I get
// QMetaProperty::read: Unable to handle unregistered datatype 'QUndoStack*' for property 'Project_QML_108::undoStack'
// if I don't do this.
qRegisterMetaType<QUndoStack*>();
qRegisterMetaType<Tile*>();
qRegisterMetaType<Tileset*>();
qRegisterMetaType<UndoStack*>();

if (QFontDatabase::addApplicationFont(":/fonts/FontAwesome.otf") == -1) {
qWarning() << "Failed to load FontAwesome font";
Expand Down
4 changes: 2 additions & 2 deletions app/applygreedypixelfillcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
Q_LOGGING_CATEGORY(lcApplyGreedyPixelFillCommand, "app.undo.applyGreedyPixelFillCommand")

ApplyGreedyPixelFillCommand::ApplyGreedyPixelFillCommand(ImageCanvas *canvas, int layerIndex, const QImage &previousImage,
const QImage &newImage, UndoCommand *parent) :
UndoCommand(parent),
const QImage &newImage, QUndoCommand *parent) :
QUndoCommand(parent),
mCanvas(canvas),
mLayerIndex(layerIndex),
mPreviousImage(previousImage),
Expand Down
8 changes: 3 additions & 5 deletions app/applygreedypixelfillcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@

#include <QDebug>
#include <QImage>
#include <QtUndo/undocommand.h>
#include <QUndoCommand>

class ImageCanvas;

class ApplyGreedyPixelFillCommand : public UndoCommand
class ApplyGreedyPixelFillCommand : public QUndoCommand
{
Q_OBJECT

public:
ApplyGreedyPixelFillCommand(ImageCanvas *canvas, int layerIndex,const QImage &previousImage,
const QImage &newImage, UndoCommand *parent = nullptr);
const QImage &newImage, QUndoCommand *parent = nullptr);

void undo() override;
void redo() override;
Expand Down
2 changes: 0 additions & 2 deletions app/applylayeredimagepixelfillcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class LayeredImageProject;

class ApplyLayeredImagePixelFillCommand : public UndoCommand
{
Q_OBJECT

public:
ApplyLayeredImagePixelFillCommand(LayeredImageProject *project, const QImage &previousImage,
const QImage &newImage, UndoCommand *parent = nullptr);
Expand Down
8 changes: 4 additions & 4 deletions app/applypixelerasercommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
Q_LOGGING_CATEGORY(lcApplyPixelEraserCommand, "app.undo.applyPixelEraserCommand")

ApplyPixelEraserCommand::ApplyPixelEraserCommand(ImageCanvas *canvas, int layerIndex, const QVector<QPoint> &scenePositions,
const QVector<QColor> &previousColours, UndoCommand *parent) :
UndoCommand(parent),
const QVector<QColor> &previousColours, QUndoCommand *parent) :
QUndoCommand(parent),
mCanvas(canvas),
mLayerIndex(layerIndex)
{
Expand Down Expand Up @@ -58,9 +58,9 @@ int ApplyPixelEraserCommand::id() const
return ApplyPixelEraserCommandId;
}

bool ApplyPixelEraserCommand::mergeWith(const UndoCommand *other)
bool ApplyPixelEraserCommand::mergeWith(const QUndoCommand *other)
{
const ApplyPixelEraserCommand *otherCommand = qobject_cast<const ApplyPixelEraserCommand*>(other);
const ApplyPixelEraserCommand *otherCommand = dynamic_cast<const ApplyPixelEraserCommand*>(other);
if (!otherCommand) {
return false;
}
Expand Down
10 changes: 4 additions & 6 deletions app/applypixelerasercommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@
#include <QDebug>
#include <QPoint>
#include <QVector>
#include <QtUndo/undocommand.h>
#include <QUndoCommand>

#include "imagecanvas.h"

class ApplyPixelEraserCommand : public UndoCommand
class ApplyPixelEraserCommand : public QUndoCommand
{
Q_OBJECT

public:
ApplyPixelEraserCommand(ImageCanvas *canvas, int layerIndex, const QVector<QPoint> &scenePositions, const QVector<QColor> &previousColours,
UndoCommand *parent = nullptr);
QUndoCommand *parent = nullptr);

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

int id() const override;
bool mergeWith(const UndoCommand *other) override;
bool mergeWith(const QUndoCommand *other) override;

private:
friend QDebug operator<<(QDebug debug, const ApplyPixelEraserCommand *command);
Expand Down
4 changes: 2 additions & 2 deletions app/applypixelfillcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
Q_LOGGING_CATEGORY(lcApplyPixelFillCommand, "app.undo.applyPixelFillCommand")

ApplyPixelFillCommand::ApplyPixelFillCommand(ImageCanvas *canvas, int layerIndex,
const QImage &previousImage, const QImage &newImage, UndoCommand *parent) :
UndoCommand(parent),
const QImage &previousImage, const QImage &newImage, QUndoCommand *parent) :
QUndoCommand(parent),
mCanvas(canvas),
mLayerIndex(layerIndex),
mPreviousImage(previousImage),
Expand Down
8 changes: 3 additions & 5 deletions app/applypixelfillcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@

#include <QDebug>
#include <QImage>
#include <QtUndo/undocommand.h>
#include <QUndoCommand>

class ImageCanvas;

class ApplyPixelFillCommand : public UndoCommand
class ApplyPixelFillCommand : public QUndoCommand
{
Q_OBJECT

public:
ApplyPixelFillCommand(ImageCanvas *canvas, int layerIndex, const QImage &previousImage,
const QImage &newImage, UndoCommand *parent = nullptr);
const QImage &newImage, QUndoCommand *parent = nullptr);

void undo() override;
void redo() override;
Expand Down
6 changes: 3 additions & 3 deletions app/applypixellinecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Q_LOGGING_CATEGORY(lcApplyPixelLineCommand, "app.undo.applyPixelLineCommand")

ApplyPixelLineCommand::ApplyPixelLineCommand(ImageCanvas *canvas, int layerIndex, const QImage &imageWithLine,
const QImage &imageWithoutLine, const QRect &lineRect,
const QPoint &newLastPixelPenReleaseScenePos, const QPoint &oldLastPixelPenReleaseScenePos, UndoCommand *parent) :
UndoCommand(parent),
const QPoint &newLastPixelPenReleaseScenePos, const QPoint &oldLastPixelPenReleaseScenePos, QUndoCommand *parent) :
QUndoCommand(parent),
mCanvas(canvas),
mLayerIndex(layerIndex),
mImageWithLine(imageWithLine),
Expand Down Expand Up @@ -62,7 +62,7 @@ int ApplyPixelLineCommand::id() const
return ApplyPixelLineCommandId;
}

bool ApplyPixelLineCommand::mergeWith(const UndoCommand *)
bool ApplyPixelLineCommand::mergeWith(const QUndoCommand *)
{
return false;
}
Expand Down
10 changes: 4 additions & 6 deletions app/applypixellinecommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,23 @@

#include <QDebug>
#include <QPointF>
#include <QtUndo/undocommand.h>
#include <QUndoCommand>

#include "imagecanvas.h"

class ApplyPixelLineCommand : public UndoCommand
class ApplyPixelLineCommand : public QUndoCommand
{
Q_OBJECT

public:
ApplyPixelLineCommand(ImageCanvas *canvas, int layerIndex, const QImage &imageWithLine,
const QImage &imageWithoutLine, const QRect &lineRect, const QPoint &newLastPixelPenReleaseScenePos,
const QPoint &oldLastPixelPenReleaseScenePos, UndoCommand *parent = nullptr);
const QPoint &oldLastPixelPenReleaseScenePos, QUndoCommand *parent = nullptr);
~ApplyPixelLineCommand();

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

int id() const override;
bool mergeWith(const UndoCommand *other) override;
bool mergeWith(const QUndoCommand *other) override;

private:
friend QDebug operator<<(QDebug debug, const ApplyPixelLineCommand *command);
Expand Down
8 changes: 4 additions & 4 deletions app/applypixelpencommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
Q_LOGGING_CATEGORY(lcApplyPixelPenCommand, "app.undo.applyPixelPenCommand")

ApplyPixelPenCommand::ApplyPixelPenCommand(ImageCanvas *canvas, int layerIndex, const QVector<QPoint> &scenePositions,
const QVector<QColor> &previousColours, const QColor &colour, UndoCommand *parent) :
UndoCommand(parent),
const QVector<QColor> &previousColours, const QColor &colour, QUndoCommand *parent) :
QUndoCommand(parent),
mCanvas(canvas),
mLayerIndex(layerIndex),
mColour(colour)
Expand Down Expand Up @@ -59,9 +59,9 @@ int ApplyPixelPenCommand::id() const
return ApplyPixelPenCommandId;
}

bool ApplyPixelPenCommand::mergeWith(const UndoCommand *other)
bool ApplyPixelPenCommand::mergeWith(const QUndoCommand *other)
{
const ApplyPixelPenCommand *otherCommand = qobject_cast<const ApplyPixelPenCommand*>(other);
const ApplyPixelPenCommand *otherCommand = dynamic_cast<const ApplyPixelPenCommand*>(other);
if (!otherCommand) {
return false;
}
Expand Down
10 changes: 4 additions & 6 deletions app/applypixelpencommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@
#include <QDebug>
#include <QPoint>
#include <QVector>
#include <QtUndo/undocommand.h>
#include <QUndoCommand>

#include "imagecanvas.h"

class ApplyPixelPenCommand : public UndoCommand
class ApplyPixelPenCommand : public QUndoCommand
{
Q_OBJECT

public:
ApplyPixelPenCommand(ImageCanvas *canvas, int layerIndex, const QVector<QPoint> &scenePositions, const QVector<QColor> &previousColours,
const QColor &colour, UndoCommand *parent = nullptr);
const QColor &colour, QUndoCommand *parent = nullptr);

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

int id() const override;
bool mergeWith(const UndoCommand *other) override;
bool mergeWith(const QUndoCommand *other) override;

private:
friend QDebug operator<<(QDebug debug, const ApplyPixelPenCommand *command);
Expand Down
4 changes: 2 additions & 2 deletions app/applytilecanvaspixelfillcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
Q_LOGGING_CATEGORY(lcApplyTileCanvasPixelFillCommand, "app.undo.applyTileCanvasPixelFillCommand")

ApplyTileCanvasPixelFillCommand::ApplyTileCanvasPixelFillCommand(TileCanvas *canvas, const QVector<QPoint> &scenePositions,
const QColor &previousColour, const QColor &colour, UndoCommand *parent) :
UndoCommand(parent),
const QColor &previousColour, const QColor &colour, QUndoCommand *parent) :
QUndoCommand(parent),
mCanvas(canvas),
mColour(colour)
{
Expand Down
Loading

0 comments on commit cde31ef

Please sign in to comment.