src/history.h

changeset 539
72ad83a67165
parent 538
2f85d4d286e5
child 540
0334789cb4d7
equal deleted inserted replaced
538:2f85d4d286e5 539:72ad83a67165
21 21
22 #include "common.h" 22 #include "common.h"
23 #include "ldtypes.h" 23 #include "ldtypes.h"
24 24
25 #define IMPLEMENT_HISTORY_TYPE(N) \ 25 #define IMPLEMENT_HISTORY_TYPE(N) \
26 virtual ~N##History(); \ 26 virtual ~N##History(){} \
27 virtual void undo() const override; \ 27 virtual void undo() const override; \
28 virtual void redo() const override; \ 28 virtual void redo() const override; \
29 virtual History::Type getType() const override { return History::N; } 29 virtual History::Type getType() const override { return History::N; }
30 30
31 class AbstractHistoryEntry; 31 class AbstractHistoryEntry;
32 32
33 // ============================================================================= 33 // =============================================================================
34 class History 34 class History
35 { PROPERTY (long, pos, setPos) 35 { PROPERTY (private, long, Position, NUM_OPS, NO_CB)
36 PROPERTY (LDFile*, file, setFile) 36 PROPERTY (public, LDFile*, File, NO_OPS, NO_CB)
37 READ_PROPERTY (bool, opened, setOpened) 37 PROPERTY (public, bool, Ignoring, BOOL_OPS, NO_CB)
38 38
39 public: 39 public:
40 typedef QList<AbstractHistoryEntry*> Changeset; 40 typedef QList<AbstractHistoryEntry*> Changeset;
41 41
42 enum Type 42 enum Type
51 void undo(); 51 void undo();
52 void redo(); 52 void redo();
53 void clear(); 53 void clear();
54 void updateActions() const; 54 void updateActions() const;
55 55
56 void open(); 56 void addStep();
57 void close();
58 void add (AbstractHistoryEntry* entry); 57 void add (AbstractHistoryEntry* entry);
59 58
60 inline long getSize() const 59 inline long getSize() const
61 { return m_changesets.size(); 60 { return m_changesets.size();
62 } 61 }
69 inline const Changeset& getChangeset (long pos) const 68 inline const Changeset& getChangeset (long pos) const
70 { return m_changesets[pos]; 69 { return m_changesets[pos];
71 } 70 }
72 71
73 private: 72 private:
74 Changeset m_currentArchive; 73 Changeset m_currentChangeset;
75 QList<Changeset> m_changesets; 74 QList<Changeset> m_changesets;
76 }; 75 };
77 76
78 // ============================================================================= 77 // =============================================================================
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 78 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
80 // ============================================================================= 79 // =============================================================================
81 class AbstractHistoryEntry 80 class AbstractHistoryEntry
82 { PROPERTY (History*, parent, setParent) 81 { PROPERTY (public, History*, Parent, NO_OPS, NO_CB)
83 82
84 public: 83 public:
84 virtual ~AbstractHistoryEntry() {}
85 virtual void undo() const {} 85 virtual void undo() const {}
86 virtual void redo() const {} 86 virtual void redo() const {}
87 virtual ~AbstractHistoryEntry() {}
88 virtual History::Type getType() const 87 virtual History::Type getType() const
89 { return (History::Type) 0; 88 { return (History::Type) 0;
90 } 89 }
91 }; 90 };
92 91
93 // ============================================================================= 92 // =============================================================================
94 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
95 // ============================================================================= 94 // =============================================================================
96 class DelHistory : public AbstractHistoryEntry 95 class DelHistory : public AbstractHistoryEntry
97 { public: 96 { PROPERTY (private, int, Index, NO_OPS, NO_CB)
98 enum Type 97 PROPERTY (private, str, Code, NO_OPS, NO_CB)
99 { Cut, // was deleted with a cut operation
100 Other, // was deleted witout specific reason
101 };
102
103 PROPERTY (int, index, setIndex)
104 PROPERTY (str, code, setCode)
105 PROPERTY (DelHistory::Type, type, setType)
106 98
107 public: 99 public:
108 IMPLEMENT_HISTORY_TYPE (Del) 100 IMPLEMENT_HISTORY_TYPE (Del)
109 101
110 DelHistory (int idx, LDObject* obj, Type type = Other) : 102 DelHistory (int idx, LDObject* obj) :
111 m_index (idx), 103 m_Index (idx),
112 m_code (obj->raw()), 104 m_Code (obj->raw()) {}
113 m_type (type) {}
114 }; 105 };
115 106
116 // ============================================================================= 107 // =============================================================================
117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
118 // ============================================================================= 109 // =============================================================================
119 class EditHistory : public AbstractHistoryEntry 110 class EditHistory : public AbstractHistoryEntry
120 { PROPERTY (int, index, setIndex) 111 { PROPERTY (private, int, Index, NO_OPS, NO_CB)
121 PROPERTY (str, oldCode, setOldCode) 112 PROPERTY (private, str, OldCode, NO_OPS, NO_CB)
122 PROPERTY (str, newCode, setNewCode) 113 PROPERTY (private, str, NewCode, NO_OPS, NO_CB)
123 114
124 public: 115 public:
125 IMPLEMENT_HISTORY_TYPE (Edit) 116 IMPLEMENT_HISTORY_TYPE (Edit)
126 117
127 EditHistory (int idx, str oldCode, str newCode) : 118 EditHistory (int idx, str oldCode, str newCode) :
128 m_index (idx), 119 m_Index (idx),
129 m_oldCode (oldCode), 120 m_OldCode (oldCode),
130 m_newCode (newCode) {} 121 m_NewCode (newCode) {}
131 }; 122 };
132 123
133 // ============================================================================= 124 // =============================================================================
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
135 // ============================================================================= 126 // =============================================================================
136 class AddHistory : public AbstractHistoryEntry 127 class AddHistory : public AbstractHistoryEntry
137 { public: 128 { PROPERTY (private, int, Index, NO_OPS, NO_CB)
138 enum Type 129 PROPERTY (private, str, Code, NO_OPS, NO_CB)
139 { Other, // was "just added"
140 Paste, // was added through a paste operation
141 };
142
143 PROPERTY (int, index, setIndex)
144 PROPERTY (str, code, setCode)
145 PROPERTY (AddHistory::Type, type, setType)
146 130
147 public: 131 public:
148 IMPLEMENT_HISTORY_TYPE (Add) 132 IMPLEMENT_HISTORY_TYPE (Add)
149 133
150 AddHistory (int idx, LDObject* obj, Type type = Other) : 134 AddHistory (int idx, LDObject* obj) :
151 m_index (idx), 135 m_Index (idx),
152 m_code (obj->raw()), 136 m_Code (obj->raw()) {}
153 m_type (type) {}
154 }; 137 };
155 138
156 // ============================================================================= 139 // =============================================================================
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
158 // ============================================================================= 141 // =============================================================================
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
173 // ============================================================================= 156 // =============================================================================
174 class SwapHistory : public AbstractHistoryEntry 157 class SwapHistory : public AbstractHistoryEntry
175 { public: 158 { public:
176 IMPLEMENT_HISTORY_TYPE (Swap) 159 IMPLEMENT_HISTORY_TYPE (Swap)
177 int a, b;
178 160
179 SwapHistory (int a, int b) : 161 SwapHistory (int a, int b) :
180 a (a), 162 a (a),
181 b (b) {} 163 b (b) {}
164
165 private:
166 int a, b;
182 }; 167 };
183 168
184 #endif // LDFORGE_HISTORY_H 169 #endif // LDFORGE_HISTORY_H

mercurial