src/editHistory.h

Sun, 06 Sep 2015 03:00:28 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 06 Sep 2015 03:00:28 +0300
changeset 983
05ba93066194
parent 968
4b93b7963456
child 1014
f0a8ecb6a357
child 1217
314e12e23c3a
permissions
-rw-r--r--

Refactor edit history

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
968
4b93b7963456 Happy new year 2015
Teemu Piippo <crimsondusk64@gmail.com>
parents: 948
diff changeset
3 * Copyright (C) 2013 - 2015 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 #pragma once
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "main.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "ldObject.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 class AbstractHistoryEntry;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
25 class EditHistory : public QObject
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 {
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
27 Q_OBJECT
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
29 public:
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
30 using Changeset = QList<AbstractHistoryEntry*>;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
31
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
32 EditHistory (LDDocument* document);
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
33
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
34 void add (AbstractHistoryEntry* entry);
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
35 void addStep();
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
36 const Changeset& changesetAt (int pos) const;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
37 void clear();
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
38 LDDocument* document() const;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
39 bool isIgnoring() const;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
40 int position();
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
41 void redo();
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
42 void setIgnoring (bool value);
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
43 int size() const;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
44 void undo();
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
45
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
46 signals:
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
47 void undone();
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
48 void redone();
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
49 void stepAdded();
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
50
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
51 private:
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
52 LDDocument* m_document;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
53 Changeset m_currentChangeset;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
54 QList<Changeset> m_changesets;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
55 bool m_isIgnoring;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
56 int m_position;
655
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
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
59 class AbstractHistoryEntry
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 {
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
61 public:
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
62 AbstractHistoryEntry();
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
63 virtual ~AbstractHistoryEntry();
655
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: 968
diff changeset
65 EditHistory* parent() const;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
66 virtual void redo() const = 0;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
67 void setParent (EditHistory* parent);
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
68 virtual void undo() const = 0;
655
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: 968
diff changeset
70 private:
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
71 EditHistory* m_parent;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
74 class AddHistoryEntry : public AbstractHistoryEntry
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 {
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
76 public:
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
77 AddHistoryEntry (int idx, LDObject* obj);
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
78 void undo() const override;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
79 void redo() const override;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
80
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
81 private:
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
82 int m_index;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
83 QString m_code;
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
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
86 class DelHistoryEntry : public AddHistoryEntry
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 {
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
88 public:
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
89 DelHistoryEntry (int idx, LDObject* obj);
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
90 void undo() const override;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
91 void redo() const override;
655
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
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
94 class EditHistoryEntry : public AbstractHistoryEntry
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 {
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
96 public:
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
97 EditHistoryEntry (int idx, QString oldCode, QString newCode);
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
98 void undo() const override;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
99 void redo() const override;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
100
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
101 private:
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
102 int m_index;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
103 QString m_oldCode;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
104 QString m_newCode;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
105 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
107 class SwapHistoryEntry : public AbstractHistoryEntry
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
108 {
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
109 public:
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
110 SwapHistoryEntry (int a, int b);
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
111 void undo() const override;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
112 void redo() const override;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
794
c254ddc6618b - source reformat
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
114 private:
983
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
115 int m_a;
05ba93066194 Refactor edit history
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
116 int m_b;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 };

mercurial