From 94bae7df21d3f7329bda1f0f8c8f98c7f8b61527 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Tue, 10 Oct 2023 14:02:26 +0200
Subject: [PATCH] rm AddLayer from SampleEditorCommands

---
 .../SampleDesigner/SampleEditorCommands.cpp   | 22 +------------------
 .../SampleDesigner/SampleEditorCommands.h     | 13 -----------
 .../SampleDesigner/SampleEditorController.cpp |  6 ++---
 3 files changed, 4 insertions(+), 37 deletions(-)

diff --git a/GUI/View/SampleDesigner/SampleEditorCommands.cpp b/GUI/View/SampleDesigner/SampleEditorCommands.cpp
index f152d2a6ded..2304d3c2c28 100644
--- a/GUI/View/SampleDesigner/SampleEditorCommands.cpp
+++ b/GUI/View/SampleDesigner/SampleEditorCommands.cpp
@@ -19,6 +19,7 @@
 #include "GUI/View/SampleDesigner/SampleEditorController.h"
 #include "GUI/View/SampleDesigner/SampleForm.h"
 #include <utility>
+#include <iostream>
 
 namespace {
 
@@ -52,27 +53,6 @@ void CommandRemoveLayer::undo()
 
 // --------------------------------------------------------------------------------------------- //
 
-CommandAddLayer::CommandAddLayer(SampleEditorController* ec, int atIndex, QUndoCommand* /*parent*/)
-    : m_ec(ec)
-    , m_atIndex(atIndex)
-{
-    setText("Add layer");
-}
-
-void CommandAddLayer::redo()
-{
-    m_ec->addLayerItemFromUndo(m_atIndex);
-}
-
-void CommandAddLayer::undo()
-{
-    // no backup of the layer has to be stored, since redo always creates the layer
-    // from scratch - no contents required for this
-    m_ec->removeLayerItemFromUndo(m_atIndex);
-}
-
-// --------------------------------------------------------------------------------------------- //
-
 CommandChangeValue::CommandChangeValue(const QString& label, SampleEditorController* ec,
                                        double oldValue, double newValue, const QString& path,
                                        QUndoCommand* parent /*= nullptr*/)
diff --git a/GUI/View/SampleDesigner/SampleEditorCommands.h b/GUI/View/SampleDesigner/SampleEditorCommands.h
index 0a58d850da7..a53900e9d38 100644
--- a/GUI/View/SampleDesigner/SampleEditorCommands.h
+++ b/GUI/View/SampleDesigner/SampleEditorCommands.h
@@ -40,19 +40,6 @@ private:
     bool m_isFirst = true;
 };
 
-//! Command to add a layer to a sample
-class CommandAddLayer : public QUndoCommand {
-public:
-    CommandAddLayer(SampleEditorController* ec, int atIndex, QUndoCommand* parent = nullptr);
-
-    void redo() override;
-    void undo() override;
-
-private:
-    SampleEditorController* m_ec;
-    int m_atIndex;
-};
-
 //! Command to remove a layer from a sample
 class CommandRemoveLayer : public QUndoCommand {
 public:
diff --git a/GUI/View/SampleDesigner/SampleEditorController.cpp b/GUI/View/SampleDesigner/SampleEditorController.cpp
index cd5a1568139..e8a1f29e922 100644
--- a/GUI/View/SampleDesigner/SampleEditorController.cpp
+++ b/GUI/View/SampleDesigner/SampleEditorController.cpp
@@ -63,9 +63,9 @@ SampleItem* SampleEditorController::sampleItem() const
 
 void SampleEditorController::addLayerItem(LayerItem* before)
 {
-    const int newIndex = (before != nullptr) ? m_sampleItem->layerItems().indexOf(before)
-                                             : m_sampleItem->layerItems().size();
-    m_undoStack.push(new CommandAddLayer(this, newIndex));
+    const int i = (before != nullptr) ? m_sampleItem->layerItems().indexOf(before)
+	: m_sampleItem->layerItems().size();
+    addLayerItemFromUndo(i);
 }
 
 QColor SampleEditorController::findColor(int atIndex)
-- 
GitLab