Skip to content

Commit 3f26372

Browse files
committed
parent as argument
1 parent 40dbfc4 commit 3f26372

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
build/
22

3-
# docs/
3+
docs/
44

55
bin/

src/commands.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "global.h"
2121
#include "mainscene.h"
2222
#include "mainwindow.h"
23-
#include "uncertain.h"
23+
// #include "uncertain.h"
2424

2525
#include <QDebug>
2626
#include <QGraphicsItem>
@@ -29,15 +29,16 @@ namespace Cmd {
2929

3030
GUI::MainScene * Cmd::Undo::s_scene = nullptr;
3131

32-
Undo::Undo()
32+
Undo::Undo( QUndoCommand *parent) : QUndoCommand(parent)
3333
{
3434
qDebug() << Q_FUNC_INFO;
3535
}
3636

3737

3838
AddStroke::AddStroke( State *curr,
3939
std::unique_ptr<State> &p,
40-
std::unique_ptr<State> &n)
40+
std::unique_ptr<State> &n,
41+
QUndoCommand *parent) : Undo(parent)
4142
{
4243
qDebug() << Q_FUNC_INFO;
4344
setText( "add stroke" );
@@ -65,7 +66,8 @@ void AddStroke::undo()
6566

6667
DeleteSelection::DeleteSelection( State *st,
6768
std::unique_ptr<State> & p,
68-
std::unique_ptr<State> & n)
69+
std::unique_ptr<State> & n,
70+
QUndoCommand *parent) : Undo(parent)
6971
{
7072
setText( QString("delete selected item%1")
7173
.arg( scene()->selectedItems().size()==1 ? "" : "s") );
@@ -90,7 +92,7 @@ void DeleteSelection::undo()
9092
}
9193

9294

93-
TabulaRasa::TabulaRasa( State *st )
95+
TabulaRasa::TabulaRasa( State *st, QUndoCommand *parent ) : Undo(parent)
9496
{
9597
qDebug() << Q_FUNC_INFO ;
9698
setText( "clear all" );
@@ -119,7 +121,9 @@ void TabulaRasa::undo()
119121
ReplaceStateWithFileContent::ReplaceStateWithFileContent( const QString & fileName,
120122
State *curr,
121123
std::unique_ptr<State> & p,
122-
std::unique_ptr<State> & n)
124+
std::unique_ptr<State> & n,
125+
QUndoCommand *parent)
126+
: Undo(parent)
123127
{
124128
qDebug() << Q_FUNC_INFO;
125129
setText( fileName );

src/commands.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Undo : public QUndoCommand
4242
Undo & operator= (Undo && other) = delete;
4343

4444
protected:
45-
Undo();
45+
Undo(QUndoCommand *parent=nullptr);
4646
~Undo() override = default;
4747

4848
State *current_state_{};
@@ -61,9 +61,10 @@ class Undo : public QUndoCommand
6161
class AddStroke : public Undo
6262
{
6363
public:
64-
AddStroke( State *curr,
64+
AddStroke(State *curr,
6565
std::unique_ptr<State> & p,
66-
std::unique_ptr<State> & n);
66+
std::unique_ptr<State> & n,
67+
QUndoCommand *parent=nullptr);
6768
AddStroke( const AddStroke &) = delete;
6869
AddStroke( AddStroke &&) = delete;
6970
AddStroke operator= (const AddStroke &) = delete;
@@ -78,9 +79,10 @@ class AddStroke : public Undo
7879
class DeleteSelection : public Undo
7980
{
8081
public:
81-
DeleteSelection( State *st,
82+
DeleteSelection(State *st,
8283
std::unique_ptr<State> &p,
83-
std::unique_ptr<State> &n);
84+
std::unique_ptr<State> &n,
85+
QUndoCommand *parent=nullptr);
8486

8587
private:
8688
void redo() override;
@@ -91,7 +93,8 @@ class DeleteSelection : public Undo
9193
class TabulaRasa : public Undo
9294
{
9395
public:
94-
TabulaRasa( State *st);
96+
TabulaRasa( State *st,
97+
QUndoCommand *parent=nullptr);
9598
private:
9699
void redo() override;
97100
void undo() override;
@@ -103,7 +106,8 @@ class ReplaceStateWithFileContent : public Undo
103106
ReplaceStateWithFileContent( const QString &fileName,
104107
State *curr,
105108
std::unique_ptr<State> &p,
106-
std::unique_ptr<State> &n);
109+
std::unique_ptr<State> &n,
110+
QUndoCommand *parent=nullptr);
107111
private:
108112
void redo() override;
109113
void undo() override;

0 commit comments

Comments
 (0)