diff --git a/src/nostalgia/core/studio/tilesheeteditor.cpp b/src/nostalgia/core/studio/tilesheeteditor.cpp index c5ad7162..d373acf9 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor.cpp @@ -227,10 +227,13 @@ class InsertTileCommand: public QUndoCommand { }; +SheetData::SheetData(QUndoStack *undoStack): m_cmdStack(undoStack) { +} + void SheetData::updatePixel(QVariant pixelItem) { auto p = qobject_cast(pixelItem.value()); if (p && p != m_prevPixelUpdated) { - m_cmdStack.push(new UpdatePixelsCommand(m_pixels, m_palette, p, m_selectedColor, m_cmdIdx)); + m_cmdStack->push(new UpdatePixelsCommand(m_pixels, m_palette, p, m_selectedColor, m_cmdIdx)); m_prevPixelUpdated = p; emit changeOccurred(); } @@ -245,11 +248,11 @@ void SheetData::endCmd() { } void SheetData::insertTileCmd(int tileIdx) { - m_cmdStack.push(new InsertTileCommand(this, tileIdx)); + m_cmdStack->push(new InsertTileCommand(this, tileIdx)); } void SheetData::deleteTileCmd(int tileIdx) { - m_cmdStack.push(new InsertTileCommand(this, tileIdx, true)); + m_cmdStack->push(new InsertTileCommand(this, tileIdx, true)); } int SheetData::columns() const { @@ -343,10 +346,6 @@ void SheetData::setSelectedColor(int index) { m_selectedColor = index; } -QUndoStack *SheetData::undoStack() { - return &m_cmdStack; -} - void SheetData::setColumns(int columns) { m_columns = columns; emit columnsChanged(columns); @@ -360,11 +359,11 @@ void SheetData::setRows(int rows) { } void SheetData::updateColumns(int columns) { - m_cmdStack.push(new UpdateDimensionsCommand(this, UpdateDimensionsCommand::Dimension::Columns, m_columns, columns)); + m_cmdStack->push(new UpdateDimensionsCommand(this, UpdateDimensionsCommand::Dimension::Columns, m_columns, columns)); } void SheetData::updateRows(int rows) { - m_cmdStack.push(new UpdateDimensionsCommand(this, UpdateDimensionsCommand::Dimension::Rows, m_rows, rows)); + m_cmdStack->push(new UpdateDimensionsCommand(this, UpdateDimensionsCommand::Dimension::Rows, m_rows, rows)); } void SheetData::updatePixels(const NostalgiaGraphic *ng) { @@ -411,7 +410,7 @@ std::unique_ptr SheetData::toNostalgiaGraphic() const { return ng; } -TileSheetEditor::TileSheetEditor(QString path, const studio::Context *ctx, QWidget *parent): studio::Editor(parent) { +TileSheetEditor::TileSheetEditor(QString path, const studio::Context *ctx, QWidget *parent): studio::Editor(parent), m_sheetData(undoStack()) { m_ctx = ctx; m_itemPath = path; m_itemName = path.mid(path.lastIndexOf('/')); @@ -462,10 +461,6 @@ QString TileSheetEditor::itemName() { return m_itemName; } -QUndoStack *TileSheetEditor::undoStack() { - return m_sheetData.undoStack(); -} - void TileSheetEditor::saveItem() { m_sheetData.save(m_ctx, m_itemPath); } diff --git a/src/nostalgia/core/studio/tilesheeteditor.hpp b/src/nostalgia/core/studio/tilesheeteditor.hpp index d3a19853..88e29e48 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor.hpp @@ -29,7 +29,7 @@ class SheetData: public QObject { QString m_tilesheetPath; QString m_currentPalettePath; uint64_t m_cmdIdx = 0; - QUndoStack m_cmdStack; + QUndoStack *m_cmdStack; QStringList m_palette; QVector m_pixels; int m_columns = 1; @@ -37,6 +37,8 @@ class SheetData: public QObject { int m_selectedColor = 0; public: + SheetData(QUndoStack*); + Q_INVOKABLE void updatePixel(QVariant pixel); Q_INVOKABLE void beginCmd(); @@ -131,8 +133,6 @@ class TileSheetEditor: public studio::Editor { QString itemName() override; - QUndoStack *undoStack() override; - protected: void saveItem() override; diff --git a/src/nostalgia/studio/lib/editor.cpp b/src/nostalgia/studio/lib/editor.cpp index 658a69e8..c38a6207 100644 --- a/src/nostalgia/studio/lib/editor.cpp +++ b/src/nostalgia/studio/lib/editor.cpp @@ -13,10 +13,6 @@ namespace nostalgia::studio { Editor::Editor(QWidget *parent): QWidget(parent) { } -QUndoStack *Editor::undoStack() { - return nullptr; -} - void Editor::save() { saveItem(); setUnsavedChanges(false); @@ -27,6 +23,10 @@ void Editor::setUnsavedChanges(bool uc) { emit unsavedChangesUpdate(uc); } +QUndoStack *Editor::undoStack() { + return &m_cmdStack; +} + void Editor::saveItem() { } diff --git a/src/nostalgia/studio/lib/editor.hpp b/src/nostalgia/studio/lib/editor.hpp index 6795351d..70c56514 100644 --- a/src/nostalgia/studio/lib/editor.hpp +++ b/src/nostalgia/studio/lib/editor.hpp @@ -19,6 +19,7 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget { Q_OBJECT private: + QUndoStack m_cmdStack; bool m_unsavedChanges = false; public: @@ -31,11 +32,6 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget { */ virtual QString itemName() = 0; - /** - * Returns the undo stack holding changes to the item being edited. - */ - virtual QUndoStack *undoStack(); - /** * Save changes to item being edited. */ @@ -47,6 +43,11 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget { */ void setUnsavedChanges(bool); + /** + * Returns the undo stack holding changes to the item being edited. + */ + QUndoStack *undoStack(); + protected: /** * Save changes to item being edited.