From 26f07add795f0db90d052cf5b93196976b9256ca Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 17 Feb 2023 22:27:02 -0500 Subject: [PATCH] Reset Tileset Editor history when tileset changes --- include/core/history.h | 6 ++++++ src/ui/tileseteditor.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/core/history.h b/include/core/history.h index 0c26780c..c999a4e1 100644 --- a/include/core/history.h +++ b/include/core/history.h @@ -10,9 +10,15 @@ public: History() { } ~History() { + clear(); + } + + void clear() { while (!history.isEmpty()) { delete history.takeLast(); } + head = -1; + saved = -1; } T back() { diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index e06e33ad..c16aeaf4 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -22,7 +22,6 @@ TilesetEditor::TilesetEditor(Project *project, Map *map, QWidget *parent) : { this->setTilesets(this->map->layout->tileset_primary_label, this->map->layout->tileset_secondary_label); this->initUi(); - this->initMetatileHistory(); } TilesetEditor::~TilesetEditor() @@ -64,7 +63,6 @@ void TilesetEditor::updateTilesets(QString primaryTilesetLabel, QString secondar if (result == QMessageBox::Yes) this->on_actionSave_Tileset_triggered(); } - this->hasUnsavedChanges = false; this->setTilesets(primaryTilesetLabel, secondaryTilesetLabel); this->refresh(); } @@ -89,6 +87,7 @@ void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTi this->primaryTileset = new Tileset(*primaryTileset); this->secondaryTileset = new Tileset(*secondaryTileset); if (paletteEditor) paletteEditor->setTilesets(this->primaryTileset, this->secondaryTileset); + this->initMetatileHistory(); } void TilesetEditor::initUi() { @@ -276,12 +275,13 @@ void TilesetEditor::restoreWindowState() { } void TilesetEditor::initMetatileHistory() { - MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, new Metatile(*metatile), QString(), QString()); + metatileHistory.clear(); + MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, new Metatile(), QString(), QString()); metatileHistory.push(commit); + this->hasUnsavedChanges = false; } void TilesetEditor::reset() { - this->hasUnsavedChanges = false; this->setTilesets(this->primaryTileset->name, this->secondaryTileset->name); if (this->paletteEditor) this->paletteEditor->setTilesets(this->primaryTileset, this->secondaryTileset);