history.h

Wed, 10 Apr 2013 01:27:06 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 10 Apr 2013 01:27:06 +0300
changeset 86
d7e02a4315a7
parent 85
b1541b547c8c
child 89
5e6c08e98dbf
permissions
-rw-r--r--

Added icons for undo and redo

85
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 Santeri `arezey` Piippo
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #ifndef HISTORY_H
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #define HISTORY_H
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "common.h"
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #define IMPLEMENT_HISTORY_TYPE(N) \
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 virtual HistoryType_e getType () const { \
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 return HISTORY_##N; \
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 } \
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 enum HistoryType_e {
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 HISTORY_Delete,
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 };
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 class HistoryEntry {
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 public:
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 virtual void undo () {}
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 virtual void redo () {}
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 virtual ~HistoryEntry () {}
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 virtual HistoryType_e getType () const {
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 return (HistoryType_e)(0);
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 };
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 };
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 class DeleteHistory : public HistoryEntry {
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 public:
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 IMPLEMENT_HISTORY_TYPE (Delete)
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 vector<ulong> indices;
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 vector<LDObject*> cache;
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 DeleteHistory (vector<ulong> indices, vector<LDObject*> cache) :
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 indices (indices), cache (cache) {}
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 virtual ~DeleteHistory ();
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 virtual void undo ();
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 virtual void redo ();
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 };
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 namespace History {
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 extern std::vector<HistoryEntry*> entries;
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 void addEntry (HistoryEntry* entry);
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 void undo ();
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 void redo ();
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 };
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 #endif // HISTORY_H

mercurial