From 9e9f317c13388e14295507ee235c73a48a274772 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 22 May 2024 02:11:58 -0500 Subject: [PATCH] [studio] Make UndoCommand::mergeWith take a reference --- .../modules/core/src/studio/paletteeditor/paletteeditor.cpp | 6 +++--- .../modules/core/src/studio/paletteeditor/paletteeditor.hpp | 2 +- src/olympic/studio/modlib/include/studio/undocommand.hpp | 2 +- src/olympic/studio/modlib/src/undocommand.cpp | 2 +- src/olympic/studio/modlib/src/undostack.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp index e81b55c9..f3c57a20 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp @@ -124,11 +124,11 @@ UpdateColorCommand::UpdateColorCommand( //setObsolete(m_oldColor == m_newColor); } -bool UpdateColorCommand::mergeWith(const UndoCommand *cmd) noexcept { - if (cmd->commandId() != static_cast(PaletteEditorCommandId::UpdateColor)) { +bool UpdateColorCommand::mergeWith(UndoCommand const&cmd) noexcept { + if (cmd.commandId() != static_cast(PaletteEditorCommandId::UpdateColor)) { return false; } - auto ucCmd = static_cast(cmd); + auto ucCmd = static_cast(&cmd); if (m_idx != ucCmd->m_idx) { return false; } diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp index 92b68b94..d56cf825 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp @@ -140,7 +140,7 @@ class UpdateColorCommand: public studio::UndoCommand { ~UpdateColorCommand() noexcept override = default; [[nodiscard]] - bool mergeWith(const UndoCommand *cmd) noexcept final; + bool mergeWith(const UndoCommand &cmd) noexcept final; [[nodiscard]] int commandId() const noexcept final; diff --git a/src/olympic/studio/modlib/include/studio/undocommand.hpp b/src/olympic/studio/modlib/include/studio/undocommand.hpp index 93e04f13..c42af98f 100644 --- a/src/olympic/studio/modlib/include/studio/undocommand.hpp +++ b/src/olympic/studio/modlib/include/studio/undocommand.hpp @@ -20,7 +20,7 @@ class UndoCommand { virtual void undo() noexcept = 0; [[nodiscard]] virtual int commandId() const noexcept = 0; - virtual bool mergeWith(UndoCommand const*cmd) noexcept; + virtual bool mergeWith(UndoCommand const&cmd) noexcept; }; } diff --git a/src/olympic/studio/modlib/src/undocommand.cpp b/src/olympic/studio/modlib/src/undocommand.cpp index 72fee36c..6a929cab 100644 --- a/src/olympic/studio/modlib/src/undocommand.cpp +++ b/src/olympic/studio/modlib/src/undocommand.cpp @@ -3,7 +3,7 @@ namespace studio { -bool UndoCommand::mergeWith(UndoCommand const*) noexcept { +bool UndoCommand::mergeWith(UndoCommand const&) noexcept { return false; } diff --git a/src/olympic/studio/modlib/src/undostack.cpp b/src/olympic/studio/modlib/src/undostack.cpp index 3d34858a..26d25d68 100644 --- a/src/olympic/studio/modlib/src/undostack.cpp +++ b/src/olympic/studio/modlib/src/undostack.cpp @@ -13,7 +13,7 @@ void UndoStack::push(ox::UPtr &&cmd) noexcept { cmd->redo(); redoTriggered.emit(cmd.get()); changeTriggered.emit(cmd.get()); - if (m_stack.empty() || !(*m_stack.back().value)->mergeWith(cmd.get())) { + if (m_stack.empty() || !(*m_stack.back().value)->mergeWith(*cmd)) { m_stack.emplace_back(std::move(cmd)); ++m_stackIdx; }