Skip to content

Commit 8ccb57c

Browse files
committed
pointer to current state now private
1 parent a4816ed commit 8ccb57c

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/commands.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ namespace Cmd {
3232

3333
GUI::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()
6162
AddStroke::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,
7575
DeleteSelection::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
}

src/commands.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ class Undo : public QUndoCommand
4949
static GUI::MainScene * scene() { return s_scene; }
5050

5151
protected:
52-
explicit Undo( QUndoCommand *parent); //!< Standard constructor
52+
explicit Undo(QUndoCommand *parent, State *st); //!< Standard constructor
5353
~Undo() override = default;
5454

55-
State *current_state_{}; //!< Pointer to current state
5655
std::unique_ptr<State> next_state_; //!< Pointer to next state (redo)
5756
std::unique_ptr<State> prev_state_; //!< Pointer to previous state (undo)
5857

5958
private:
59+
State *current_state_{}; //!< Pointer to current state
60+
6061
static GUI::MainScene *s_scene;
6162

6263
void redo() override;
@@ -86,10 +87,10 @@ class DeleteSelection : public Undo
8687
{
8788
public:
8889
//! Value constructor
89-
DeleteSelection( State *st,
90-
std::unique_ptr<State> &p,
91-
std::unique_ptr<State> &n,
92-
QUndoCommand *parent);
90+
DeleteSelection(State *st,
91+
std::unique_ptr<State> &p,
92+
std::unique_ptr<State> &n,
93+
QUndoCommand *parent);
9394
};
9495

9596

0 commit comments

Comments
 (0)