11/*
22 * This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3- * Copyright (c) 2022-2025 Jochen Meidow, Fraunhofer IOSB
3+ * Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
44 *
55 * This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
1717 */
1818
1919#include " commands.h"
20- #include " global.h"
2120#include " mainscene.h"
2221#include " state.h"
2322
@@ -39,32 +38,37 @@ Undo::Undo( QUndoCommand *parent) : QUndoCommand(parent)
3938}
4039
4140
42- AddStroke::AddStroke ( State *curr,
43- std::unique_ptr<State> &p,
44- std::unique_ptr<State> &n,
45- QUndoCommand *parent) : Undo(parent)
41+ void Undo::undo ()
4642{
47- // qDebug() << Q_FUNC_INFO;
48- setText ( QStringLiteral ( " add stroke " ) );
49- current_state_ = curr ; // set pointer
50- prev_state_ = std::move (p );
51- next_state_ = std::move (n );
43+ // qDebug() << Q_FUNC_INFO;
44+
45+ * current_state_ = *prev_state_ ; // set
46+ scene ()-> removeAllItems ( );
47+ scene ()-> addGraphicItems ( prev_state_. get () );
5248}
5349
54- void AddStroke::redo ()
50+
51+ void Undo::redo ()
5552{
56- // qDebug() << Q_FUNC_INFO;
53+ // qDebug() << Q_FUNC_INFO;
54+
5755 *current_state_ = *next_state_; // copy content
5856 scene ()->removeAllItems ();
5957 scene ()->addGraphicItems ( next_state_.get () );
6058}
6159
62- void AddStroke::undo ()
60+
61+ AddStroke::AddStroke ( State *curr,
62+ std::unique_ptr<State> &p,
63+ std::unique_ptr<State> &n,
64+ QUndoCommand *parent) : Undo(parent)
6365{
6466 // qDebug() << Q_FUNC_INFO;
65- *current_state_ = *prev_state_; // set
66- scene ()->removeAllItems ();
67- scene ()->addGraphicItems ( prev_state_.get () );
67+ setText ( QStringLiteral (" add stroke" ) );
68+
69+ current_state_ = curr; // set pointer
70+ prev_state_ = std::move (p);
71+ next_state_ = std::move (n);
6872}
6973
7074
@@ -73,6 +77,7 @@ DeleteSelection::DeleteSelection( State *st,
7377 std::unique_ptr<State> & n,
7478 QUndoCommand *parent) : Undo(parent)
7579{
80+ // qDebug() << Q_FUNC_INFO ;
7681 setText ( QStringLiteral (" delete selected item%1" )
7782 .arg ( scene ()->selectedItems ().size ()==1 ? " " : " s" ) );
7883
@@ -81,20 +86,6 @@ DeleteSelection::DeleteSelection( State *st,
8186 next_state_ = std::move (n);
8287}
8388
84- void DeleteSelection::redo ()
85- {
86- *current_state_ = *next_state_;
87- scene ()->removeAllItems ();
88- scene ()->addGraphicItems ( next_state_.get () );
89- }
90-
91- void DeleteSelection::undo ()
92- {
93- *current_state_ = *prev_state_;
94- scene ()->removeAllItems ();
95- scene ()->addGraphicItems ( prev_state_.get () );
96- }
97-
9889
9990TabulaRasa::TabulaRasa ( State *st, QUndoCommand *parent ) : Undo(parent)
10091{
@@ -103,25 +94,9 @@ TabulaRasa::TabulaRasa( State *st, QUndoCommand *parent ) : Undo(parent)
10394 current_state_ = st; // pointer
10495 prev_state_ = std::make_unique<State>(*st); // copy
10596 next_state_ = std::make_unique<State>();
106- // next_state_ = std::make_unique<State>(*st);
107- // next_state_->clearAll();
10897}
10998
11099
111- void TabulaRasa::redo ()
112- {
113- // qDebug() << Q_FUNC_INFO;
114- *current_state_ = *next_state_;
115- scene ()->removeAllItems ();
116- }
117-
118- void TabulaRasa::undo ()
119- {
120- // qDebug() << Q_FUNC_INFO;
121- *current_state_ = *prev_state_;
122- scene ()->addGraphicItems ( prev_state_.get () );
123- }
124-
125100ReplaceStateWithFileContent::ReplaceStateWithFileContent ( const QString & fileName,
126101 State *curr,
127102 std::unique_ptr<State> & p,
@@ -133,25 +108,8 @@ ReplaceStateWithFileContent::ReplaceStateWithFileContent( const QString & fileNa
133108 setText ( fileName );
134109
135110 current_state_ = curr; // pointer
136- // prev_state_ = std::make_unique<State>(*Old); // copy
137111 prev_state_ = std::move (p); // copy
138112 next_state_ = std::move (n);
139113}
140114
141- void ReplaceStateWithFileContent::redo ()
142- {
143- // qDebug() << Q_FUNC_INFO;
144- *current_state_ = *next_state_;
145- scene ()->removeAllItems ();
146- scene ()->addGraphicItems ( next_state_.get () );
147- }
148-
149- void ReplaceStateWithFileContent::undo ()
150- {
151- // qDebug() << Q_FUNC_INFO;
152- *current_state_ = *prev_state_;
153- scene ()->removeAllItems ();
154- scene ()->addGraphicItems ( prev_state_.get () );
155- }
156-
157115} // namespace Cmd
0 commit comments