src/editHistory.cpp

Sat, 28 Jan 2017 14:14:28 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 28 Jan 2017 14:14:28 +0200
changeset 1065
c8ecddbd99e9
parent 1063
1f15c52c11f6
child 1072
9ce9496427f2
permissions
-rw-r--r--

Actually, let's call it countof(). Makes more sense.

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1014
f0a8ecb6a357 Happy new year 2016!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 983
diff changeset
3 * Copyright (C) 2013 - 2016 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include "editHistory.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "ldObject.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "ldDocument.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "miscallenous.h"
962
a4b463a7ee82 Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents: 952
diff changeset
23 #include "mainwindow.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "glRenderer.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
26 EditHistory::EditHistory (LDDocument* document) :
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
27 m_document (document),
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
28 m_isIgnoring (false),
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
29 m_position (-1) {}
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
31 void EditHistory::undo()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 {
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 838
diff changeset
33 if (m_changesets.isEmpty() or position() == -1)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 // Don't take the changes done here as actual edits to the document
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 setIgnoring (true);
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
38 const Changeset& set = changesetAt (position());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 // Iterate the list in reverse and undo all actions
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
41 for (int i = countof(set) - 1; i >= 0; --i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 AbstractHistoryEntry* change = set[i];
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 change->undo();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 m_position--;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 setIgnoring (false);
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
49 emit undone();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
52 void EditHistory::redo()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 {
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
54 if (position() == countof(m_changesets))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 setIgnoring (true);
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
58 const Changeset& set = changesetAt (position() + 1);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
60 // Redo things in original order
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 for (const AbstractHistoryEntry* change : set)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 change->redo();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
64 ++m_position;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 setIgnoring (false);
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
66 emit redone();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
69 void EditHistory::clear()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 for (Changeset set : m_changesets)
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
72 for (AbstractHistoryEntry* change : set)
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
73 delete change;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 m_changesets.clear();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
78 void EditHistory::addStep()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 if (m_currentChangeset.isEmpty())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
83 while (position() < size() - 1)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 Changeset last = m_changesets.last();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 for (AbstractHistoryEntry* entry : last)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 delete entry;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 m_changesets.removeLast();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 m_changesets << m_currentChangeset;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 m_currentChangeset.clear();
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
95 ++m_position;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
96 emit stepAdded();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
99 void EditHistory::add (AbstractHistoryEntry* entry)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 if (isIgnoring())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 delete entry;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 entry->setParent (this);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 m_currentChangeset << entry;
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
109 }
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
110
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
111 int EditHistory::size() const
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
112 {
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
113 return countof(m_changesets);
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
114 }
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
115
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
116 const EditHistory::Changeset& EditHistory::changesetAt (int pos) const
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
117 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
118 return m_changesets[pos];
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
121 int EditHistory::position()
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
122 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
123 return m_position;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
124 }
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
125
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
126 bool EditHistory::isIgnoring() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 {
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
128 return m_isIgnoring;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
129 }
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
130
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
131 void EditHistory::setIgnoring (bool value)
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
132 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
133 m_isIgnoring = value;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
136 LDDocument* EditHistory::document() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 {
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
138 return m_document;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
141 //
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
142 // ---------------------------------------------------------------------------------------------------------------------
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 //
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
144
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
145 AbstractHistoryEntry::AbstractHistoryEntry() {}
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
146 AbstractHistoryEntry::~AbstractHistoryEntry() {}
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
147
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
148 EditHistory* AbstractHistoryEntry::parent() const
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
149 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
150 return m_parent;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
151 }
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
152
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
153 void AbstractHistoryEntry::setParent (EditHistory* parent)
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
154 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
155 m_parent = parent;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
156 }
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
157
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
158 //
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
159 // ---------------------------------------------------------------------------------------------------------------------
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
160 //
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
161
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
162 AddHistoryEntry::AddHistoryEntry (int idx, LDObject* obj) :
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 m_index (idx),
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 m_code (obj->asText()) {}
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
166 void AddHistoryEntry::undo() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 {
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
168 parent()->document()->getObject (m_index)->destroy();
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
169 }
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
170
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
171 void AddHistoryEntry::redo() const
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
172 {
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
173 parent()->document()->insertObject (m_index, ParseLine (m_code));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
176 //
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
177 // ---------------------------------------------------------------------------------------------------------------------
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 //
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
179
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
180 DelHistoryEntry::DelHistoryEntry (int idx, LDObject* obj) :
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
181 AddHistoryEntry (idx, obj) {}
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
182
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
183 void DelHistoryEntry::undo() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 {
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
185 AddHistoryEntry::redo();
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
186 }
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
187
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
188 void DelHistoryEntry::redo() const
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
189 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
190 AddHistoryEntry::undo();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
193 //
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
194 // ---------------------------------------------------------------------------------------------------------------------
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 //
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
196
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
197 EditHistoryEntry::EditHistoryEntry (int idx, QString oldCode, QString newCode) :
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
198 m_index (idx),
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
199 m_oldCode (oldCode),
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
200 m_newCode (newCode) {}
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
201
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
202 void EditHistoryEntry::undo() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 {
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
204 LDObject* obj = parent()->document()->getObject (m_index);
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
205 LDObject* newobj = ParseLine (m_oldCode);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 obj->replace (newobj);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
209 void EditHistoryEntry::redo() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 {
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
211 LDObject* obj = parent()->document()->getObject (m_index);
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
212 LDObject* newobj = ParseLine (m_newCode);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 obj->replace (newobj);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
216 //
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
217 // ---------------------------------------------------------------------------------------------------------------------
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 //
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
219
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
220 SwapHistoryEntry::SwapHistoryEntry (int a, int b) :
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
221 m_a (a),
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
222 m_b (b) {}
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
223
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
224
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
225 void SwapHistoryEntry::undo() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226 {
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
227 LDObject::fromID (m_a)->swap (LDObject::fromID (m_b));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
230 void SwapHistoryEntry::redo() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 undo();
879
c5b3bc08e609 - if an external program fails to run properly, an stdout&stderr log is now printed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
233 }

mercurial