@@ -32,8 +32,13 @@ namespace Cmd {
3232
3333GUI::MainScene * Undo::s_scene = nullptr ;
3434
35- Undo::Undo ( QUndoCommand *parent, State *st)
36- : QUndoCommand(parent), current_state_(st)
35+ Undo::Undo ( QUndoCommand *parent,
36+ std::unique_ptr<State> &p,
37+ std::unique_ptr<State> &n, State *st)
38+ : QUndoCommand(parent),
39+ next_state_ (std::move(n)),
40+ prev_state_(std::move(p)),
41+ current_state_(st)
3742{
3843 // qDebug() << Q_FUNC_INFO;
3944}
@@ -70,42 +75,37 @@ void Undo::redo()
7075AddStroke::AddStroke ( State *curr,
7176 std::unique_ptr<State> &p,
7277 std::unique_ptr<State> &n,
73- QUndoCommand *parent) : Undo(parent, curr)
78+ QUndoCommand *parent) : Undo(parent, p, n, curr)
7479{
7580 // qDebug() << Q_FUNC_INFO;
76- setText ( QStringLiteral (" add stroke" ) );
77-
78- prev_state_ = std::move (p);
79- next_state_ = std::move (n);
81+ setText ( " add stroke" );
8082}
8183
8284
8385DeleteSelection::DeleteSelection ( State *st,
8486 std::unique_ptr<State> & p,
8587 std::unique_ptr<State> & n,
86- QUndoCommand *parent) : Undo(parent, st)
88+ QUndoCommand *parent) : Undo(parent, p,n, st)
8789{
8890 // qDebug() << Q_FUNC_INFO ;
8991 auto *scn = scene ();
9092 if (scn==nullptr ) {
9193 return ;
9294 }
9395
94- const QString suffix = scn->selectedItems ().size ()==1 ? QStringLiteral (" " ) : QStringLiteral (" s" );
95- setText ( QStringLiteral (" delete selected item%1" ).arg (suffix) );
96-
97- prev_state_ = std::move (p);
98- next_state_ = std::move (n);
96+ setText ( QString ( scn->selectedItems ().size ()==1 ?
97+ " delete selected item" : " delete selected items" ) );
9998}
10099
101100
102- TabulaRasa::TabulaRasa ( State *st, QUndoCommand *parent ) : Undo(parent, st)
101+ TabulaRasa::TabulaRasa ( State *st,
102+ std::unique_ptr<State> &p,
103+ std::unique_ptr<State> &n,
104+ QUndoCommand *parent )
105+ : Undo(parent, p,n, st)
103106{
104107 // qDebug() << Q_FUNC_INFO ;
105- setText ( QStringLiteral (" clear all" ) );
106-
107- prev_state_ = std::make_unique<State>(*st); // copy
108- next_state_ = std::make_unique<State>();
108+ setText ( " clear all" );
109109}
110110
111111
@@ -114,13 +114,10 @@ ReplaceStateWithFileContent::ReplaceStateWithFileContent( const QString & fileNa
114114 std::unique_ptr<State> & p,
115115 std::unique_ptr<State> & n,
116116 QUndoCommand *parent)
117- : Undo(parent, curr)
117+ : Undo(parent, p,n, curr)
118118{
119119 // qDebug() << Q_FUNC_INFO;
120120 setText ( fileName );
121-
122- prev_state_ = std::move (p); // copy
123- next_state_ = std::move (n);
124121}
125122
126123} // namespace Cmd
0 commit comments