فهرست منبع

PixelPaint: Make ImageEditor::m_undo_stack a regular value member

Andreas Kling 3 سال پیش
والد
کامیت
1a54ac262a
2فایلهای تغییر یافته به همراه10 افزوده شده و 12 حذف شده
  1. 8 10
      Userland/Applications/PixelPaint/ImageEditor.cpp
  2. 2 2
      Userland/Applications/PixelPaint/ImageEditor.h

+ 8 - 10
Userland/Applications/PixelPaint/ImageEditor.cpp

@@ -23,12 +23,10 @@ namespace PixelPaint {
 
 ImageEditor::ImageEditor(NonnullRefPtr<Image> image)
     : m_image(move(image))
-    , m_undo_stack(make<GUI::UndoStack>())
     , m_selection(*this)
 {
     set_focus_policy(GUI::FocusPolicy::StrongFocus);
-    m_undo_stack = make<GUI::UndoStack>();
-    m_undo_stack->push(make<ImageUndoCommand>(*m_image));
+    m_undo_stack.push(make<ImageUndoCommand>(*m_image));
     m_image->add_client(*this);
 
     m_pixel_grid_threshold = (float)Config::read_i32("PixelPaint", "PixelGrid", "Threshold", 15);
@@ -45,12 +43,12 @@ ImageEditor::~ImageEditor()
 
 void ImageEditor::did_complete_action()
 {
-    m_undo_stack->push(make<ImageUndoCommand>(*m_image));
+    m_undo_stack.push(make<ImageUndoCommand>(*m_image));
 }
 
 bool ImageEditor::undo()
 {
-    if (!m_undo_stack->can_undo())
+    if (!m_undo_stack.can_undo())
         return false;
 
     /* Without this you need to undo twice to actually start undoing stuff.
@@ -63,19 +61,19 @@ bool ImageEditor::undo()
      * This works because UndoStack::undo first decrements the stack pointer and then restores the snapshot,
      * while UndoStack::redo first restores the snapshot and then increments the stack pointer.
      */
-    m_undo_stack->undo();
-    m_undo_stack->undo();
-    m_undo_stack->redo();
+    m_undo_stack.undo();
+    m_undo_stack.undo();
+    m_undo_stack.redo();
     layers_did_change();
     return true;
 }
 
 bool ImageEditor::redo()
 {
-    if (!m_undo_stack->can_redo())
+    if (!m_undo_stack.can_redo())
         return false;
 
-    m_undo_stack->redo();
+    m_undo_stack.redo();
     layers_did_change();
     return true;
 }

+ 2 - 2
Userland/Applications/PixelPaint/ImageEditor.h

@@ -43,7 +43,7 @@ public:
     bool undo();
     bool redo();
 
-    auto& undo_stack() { return *m_undo_stack; }
+    auto& undo_stack() { return m_undo_stack; }
 
     void add_guide(NonnullRefPtr<Guide> guide) { m_guides.append(guide); }
     void remove_guide(Guide const& guide)
@@ -153,7 +153,7 @@ private:
 
     NonnullRefPtr<Image> m_image;
     RefPtr<Layer> m_active_layer;
-    OwnPtr<GUI::UndoStack> m_undo_stack;
+    GUI::UndoStack m_undo_stack;
 
     NonnullRefPtrVector<Guide> m_guides;
     bool m_show_guides { true };