src/editHistory.cpp

Sat, 24 Mar 2018 12:54:28 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Mar 2018 12:54:28 +0200
changeset 1326
69a90bd2dba2
parent 1318
568fcfc6da71
child 1440
265b2e95a8e8
permissions
-rw-r--r--

Happy new year 2018

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
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1318
diff changeset
3 * Copyright (C) 2013 - 2018 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"
1145
02264bf0108d Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1144
diff changeset
20 #include "lddocument.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
22 EditHistory::EditHistory (LDDocument* document) :
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
23 m_document (document),
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
24 m_isIgnoring (false),
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
25 m_position (-1) {}
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
27 EditHistory::~EditHistory()
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
28 {
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
29 clear();
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
30 }
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
31
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
32 void EditHistory::undo()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 {
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 838
diff changeset
34 if (m_changesets.isEmpty() or position() == -1)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 // 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
38 setIgnoring (true);
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
39 const Changeset& set = changesetAt (position());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 // 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
42 for (int i = countof(set) - 1; i >= 0; --i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 AbstractHistoryEntry* change = set[i];
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 change->undo();
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 m_position--;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 setIgnoring (false);
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
50 emit undone();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
53 void EditHistory::redo()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 {
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
55 if (position() == countof(m_changesets))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 setIgnoring (true);
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
59 const Changeset& set = changesetAt (position() + 1);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
61 // Redo things in original order
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
62 for (AbstractHistoryEntry* change : set)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 change->redo();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
65 ++m_position;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 setIgnoring (false);
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
67 emit redone();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
70 void EditHistory::clear()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 for (Changeset set : m_changesets)
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
73 for (AbstractHistoryEntry* change : set)
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
74 delete change;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 m_changesets.clear();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
79 void EditHistory::addStep()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 if (m_currentChangeset.isEmpty())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
84 while (position() < size() - 1)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 Changeset last = m_changesets.last();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 for (AbstractHistoryEntry* entry : last)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 delete entry;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 m_changesets.removeLast();
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 m_changesets << m_currentChangeset;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 m_currentChangeset.clear();
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
96 ++m_position;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
97 emit stepAdded();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
100 int EditHistory::size() const
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
101 {
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
102 return countof(m_changesets);
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
103 }
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
104
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
105 const EditHistory::Changeset& EditHistory::changesetAt (int pos) const
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
106 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
107 return m_changesets[pos];
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
110 int EditHistory::position()
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
111 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
112 return m_position;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
113 }
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 bool EditHistory::isIgnoring() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 {
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
117 return m_isIgnoring;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
118 }
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
119
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
120 void EditHistory::setIgnoring (bool value)
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
121 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
122 m_isIgnoring = value;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
125 LDDocument* EditHistory::document() const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 {
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
127 return m_document;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
130 AbstractHistoryEntry::AbstractHistoryEntry(EditHistory* parent) :
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
131 m_parent {parent} {}
983
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 AbstractHistoryEntry::~AbstractHistoryEntry() {}
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
134
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
135 EditHistory* AbstractHistoryEntry::parent() const
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
136 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
137 return m_parent;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
138 }
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
139
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
140 AddHistoryEntry::AddHistoryEntry(const QModelIndex& index, EditHistory* parent) :
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
141 AbstractHistoryEntry {parent},
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
142 m_row {index.row()},
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
143 m_code {Serializer::store(parent->document()->lookup(index))} {}
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
144
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
145 void AddHistoryEntry::undo()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
147 LDObject* object = parent()->document()->getObject(m_row);
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
148 parent()->document()->remove(object);
983
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
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
151 void AddHistoryEntry::redo()
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
152 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
153 parent()->document()->insertFromArchive(m_row, m_code);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
156 void DelHistoryEntry::undo()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 {
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
158 AddHistoryEntry::redo();
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
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
161 void DelHistoryEntry::redo()
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
162 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
163 AddHistoryEntry::undo();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
166 EditHistoryEntry::EditHistoryEntry(
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
167 const QModelIndex& index,
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
168 const Serializer::Archive& oldState,
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
169 const Serializer::Archive& newState,
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
170 EditHistory* parent
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
171 ) :
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
172 AbstractHistoryEntry {parent},
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
173 row {index.row()},
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
174 oldState {oldState},
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
175 newState {newState} {}
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
176
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
177 void EditHistoryEntry::undo()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
179 parent()->document()->setObjectAt(row, oldState);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
182 void EditHistoryEntry::redo()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 {
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
184 parent()->document()->setObjectAt(row, newState);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186
1273
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
187 MoveHistoryEntry::MoveHistoryEntry(int top, int bottom, int destination, EditHistory* parent) :
1269
ec691d9472b3 Added LDObject serialization and refactored the internal resource managing to use it. No more tearing objects from one model into another, and this provides a stable way to keep an object's state in memory such as the edit history.
Santeri Piippo
parents: 1260
diff changeset
188 AbstractHistoryEntry {parent},
1273
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
189 top {top},
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
190 bottom {bottom},
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
191 destination {destination} {}
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
192
1273
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
193 void MoveHistoryEntry::undo()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 {
1273
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
195 bool downwards = (destination < top);
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
196 parent()->document()->moveRows(
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
197 {},
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
198 downwards ? (destination) : (destination - (bottom - top) - 1),
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
199 bottom - top + 1,
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
200 {},
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
201 downwards ? (bottom + 1) : top
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
202 );
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204
1273
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
205 void MoveHistoryEntry::redo()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 {
1273
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
207 parent()->document()->moveRows(
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
208 {},
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
209 top,
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
210 bottom - top + 1,
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
211 {},
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
212 destination
900f1dfae46b Implemented row moving in the model and replaced swapping with it
Santeri Piippo
parents: 1272
diff changeset
213 );
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
214 }

mercurial