src/edithistory.h

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

mercurial