src/edithistory.h

Wed, 22 Sep 2021 00:25:31 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 22 Sep 2021 00:25:31 +0300
changeset 135
d384df40c8e7
parent 133
e39326ee48dc
child 136
e8444e0d7f1a
permissions
-rw-r--r--

Merge commit

133
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #pragma once
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include "main.h"
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 #include "model.h"
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 #include "modeleditcontext.h"
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 class AbstractHistoryEntry
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 {
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 public:
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 virtual void undo(Model::EditContext& editContext) = 0;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 virtual void redo(Model::EditContext& editContext) = 0;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 };
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 class InsertHistoryEntry : public AbstractHistoryEntry
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 {
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 public:
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 InsertHistoryEntry(int position, const QString& code) :
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 position{position},
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 code{code} {}
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 void undo(Model::EditContext& editContext) override;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 void redo(Model::EditContext& editContext) override;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 protected:
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 int position;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 QString code;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 };
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 class DeleteHistoryEntry : public InsertHistoryEntry
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 {
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 public:
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 void undo(Model::EditContext& editContext) override;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 void redo(Model::EditContext& editContext) override;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 };
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 class EditHistoryEntry : public AbstractHistoryEntry
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 {
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 public:
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 EditHistoryEntry(int position, const QString& codeBefore, const QString& codeAfter) :
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 position{position},
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 codeBefore{codeBefore},
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 codeAfter{codeAfter} {}
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 void undo(Model::EditContext& editContext) override;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 void redo(Model::EditContext& editContext) override;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 private:
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 int position;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 QString codeBefore;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 QString codeAfter;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 };
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 class EditHistory
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 {
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 public:
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 using Changeset = QVector<std::unique_ptr<AbstractHistoryEntry>>;
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 EditHistory();
e39326ee48dc Begin work on edit history
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 };

mercurial