OpenCPN Partial API docs
undo.h
1 /******************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose: Framework for Undo features
5  * Author: Jesper Weissglas
6  *
7  ***************************************************************************
8  * Copyright (C) 2012 by David S. Register *
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  * This program is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18  * GNU General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU General Public License *
21  * along with this program; if not, write to the *
22  * Free Software Foundation, Inc., *
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24  ***************************************************************************
25  *
26  *
27  */
28 
29 #ifndef UNDO_H
30 #define UNDO_H
31 
32 #include <vector>
33 #include <deque>
34 
35 class ChartCanvas;
36 
37 enum UndoType {
38  Undo_CreateWaypoint,
39  Undo_DeleteWaypoint,
40  Undo_AppendWaypoint,
41  Undo_MoveWaypoint
42 };
43 
44 enum UndoBeforePointerType { Undo_IsOrphanded, Undo_NeedsCopy, Undo_HasParent };
45 
46 typedef void* UndoItemPointer;
47 
48 class UndoAction {
49 public:
50  ~UndoAction();
51  wxString Description();
52 
53  UndoType type;
54  std::vector<UndoItemPointer> before;
55  std::vector<UndoBeforePointerType> beforeType;
56  std::vector<UndoItemPointer> after;
57  std::vector<UndoItemPointer> selectable;
58 };
59 
60 class Undo {
61 public:
62  Undo(ChartCanvas* parent);
63  ~Undo();
64  bool AnythingToUndo();
65  bool AnythingToRedo();
66  void InvalidateRedo();
67  void InvalidateUndo();
68  void Invalidate();
69  bool InUndoableAction() { return isInsideUndoableAction; }
70  UndoAction* GetNextUndoableAction();
71  UndoAction* GetNextRedoableAction();
72  bool UndoLastAction();
73  bool RedoNextAction();
74  bool BeforeUndoableAction(UndoType type, UndoItemPointer before,
75  UndoBeforePointerType beforeType,
76  UndoItemPointer selectable);
77  bool AfterUndoableAction(UndoItemPointer after);
78  bool CancelUndoableAction(bool noDataDelete = false);
79  ChartCanvas* GetParent() { return m_parent; }
80 
81 private:
82  ChartCanvas* m_parent;
83  bool isInsideUndoableAction;
84  UndoAction* candidate;
85  unsigned int stackpointer;
86  unsigned int depthSetting;
87  std::deque<UndoAction*> undoStack;
88 };
89 
90 #endif
Definition: undo.h:60