@@ -32,7 +32,8 @@ namespace Cmd {
3232
3333GUI::MainScene * Cmd::Undo::s_scene = nullptr ;
3434
35- Undo::Undo ( QUndoCommand *parent) : QUndoCommand(parent)
35+ Undo::Undo ( QUndoCommand *parent, State *st)
36+ : QUndoCommand(parent), current_state_(st)
3637{
3738 // qDebug() << Q_FUNC_INFO;
3839}
@@ -61,12 +62,11 @@ void Undo::redo()
6162AddStroke::AddStroke ( State *curr,
6263 std::unique_ptr<State> &p,
6364 std::unique_ptr<State> &n,
64- QUndoCommand *parent) : Undo(parent)
65+ QUndoCommand *parent) : Undo(parent, curr )
6566{
6667 // qDebug() << Q_FUNC_INFO;
6768 setText ( QStringLiteral (" add stroke" ) );
6869
69- current_state_ = curr; // set pointer
7070 prev_state_ = std::move (p);
7171 next_state_ = std::move (n);
7272}
@@ -75,23 +75,22 @@ AddStroke::AddStroke( State *curr,
7575DeleteSelection::DeleteSelection ( State *st,
7676 std::unique_ptr<State> & p,
7777 std::unique_ptr<State> & n,
78- QUndoCommand *parent) : Undo(parent)
78+ QUndoCommand *parent) : Undo(parent, st )
7979{
8080 // qDebug() << Q_FUNC_INFO ;
8181 setText ( QStringLiteral (" delete selected item%1" )
8282 .arg ( scene ()->selectedItems ().size ()==1 ? " " : " s" ) );
8383
84- current_state_ = st; // pointer
8584 prev_state_ = std::move (p);
8685 next_state_ = std::move (n);
8786}
8887
8988
90- TabulaRasa::TabulaRasa ( State *st, QUndoCommand *parent ) : Undo(parent)
89+ TabulaRasa::TabulaRasa ( State *st, QUndoCommand *parent ) : Undo(parent, st )
9190{
9291 // qDebug() << Q_FUNC_INFO ;
9392 setText ( QStringLiteral (" clear all" ) );
94- current_state_ = st; // pointer
93+
9594 prev_state_ = std::make_unique<State>(*st); // copy
9695 next_state_ = std::make_unique<State>();
9796}
@@ -102,12 +101,11 @@ ReplaceStateWithFileContent::ReplaceStateWithFileContent( const QString & fileNa
102101 std::unique_ptr<State> & p,
103102 std::unique_ptr<State> & n,
104103 QUndoCommand *parent)
105- : Undo(parent)
104+ : Undo(parent, curr )
106105{
107106 // qDebug() << Q_FUNC_INFO;
108107 setText ( fileName );
109108
110- current_state_ = curr; // pointer
111109 prev_state_ = std::move (p); // copy
112110 next_state_ = std::move (n);
113111}
0 commit comments