-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommandchain.h
100 lines (76 loc) · 1.85 KB
/
commandchain.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef COMMANDCHAIN_H
#define COMMANDCHAIN_H
#include <vector>
#include <QImage>
class SpriteBuilder;
class SpriteTable;
class ImageView;
struct CommandInterface
{
virtual ~CommandInterface() {}
virtual void rollBack(SpriteTable*) {}
virtual void rollForward(SpriteTable*) {}
virtual void intialize(SpriteTable* it) { rollForward(it); }
};
class InsertionCommand : public CommandInterface
{
const int row;
public:
InsertionCommand(SpriteTable*, int row);
void rollBack(SpriteTable*);
void rollForward(SpriteTable*);
};
class DeletionCommand : public CommandInterface
{
const int row;
public:
DeletionCommand(SpriteTable*, int row);
void rollBack(SpriteTable*);
void rollForward(SpriteTable*);
};
class SetCommand : public CommandInterface
{
const int row, column;
ImageView * object;
public:
SetCommand(SpriteTable*, int row, int column);
SetCommand(SpriteTable*, int row, int column, const QImage & image);
~SetCommand();
void rollBack(SpriteTable*);
void rollForward(SpriteTable*);
};
class RearrangeCommand : public CommandInterface
{
public:
void rollBack(SpriteTable*);
void rollForward(SpriteTable*table) { RearrangeCommand::rollBack(table); }
};
class GroupCommand : public CommandInterface, public std::vector<CommandInterface *>
{
public:
~GroupCommand();
void rollBack(SpriteTable*);
void rollForward(SpriteTable*);
void intialize(SpriteTable*);
};
class CommandList
{
typedef std::list<CommandInterface *> List;
private:
List list;
List::iterator itr;
List::iterator save;
public:
SpriteBuilder * builder;
CommandList();
~CommandList();
bool dirtyPage() const;
void onSave();
bool canRollBack() const;
bool canRollForward() const;
void rollBack(SpriteTable *table);
void rollForward(SpriteTable *table);
void clear();
void push(SpriteTable *table, CommandInterface *);
};
#endif // COMMANDCHAIN_H