Mercurial > hg > svcore
comparison base/MultiViewCommandHistory.h @ 16:cc98d496d52b
* Add command history class, and basic undo/redo menus. No actual commands
to undo/redo yet. Selecting the placeholders sometimes seems to cause
a crash, so this looks a little uncertain so far.
* Add Rename Layer
* Remove models from playback when their layers are removed (and ref counts
hit zero)
* Don't hang around waiting so much when there's work to be done in the audio
buffer fill thread
* Put more sensible names on layers generated from transforms
* Add basic editing to time-value layer like existing editing in time-instants
layer, and make both of them snap to the appropriate resolution during drag
author | Chris Cannam |
---|---|
date | Mon, 30 Jan 2006 17:51:56 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:47500c27ac26 | 16:cc98d496d52b |
---|---|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 A waveform viewer and audio annotation editor. | |
5 Chris Cannam, Queen Mary University of London, 2005-2006 | |
6 | |
7 This is experimental software. Not for distribution. | |
8 */ | |
9 | |
10 /* | |
11 This is a modified version of a source file from the Rosegarden | |
12 MIDI and audio sequencer and notation editor, copyright 2000-2006 | |
13 Chris Cannam, distributed under the GNU General Public License. | |
14 | |
15 This file contains traces of the KCommandHistory class from the KDE | |
16 project, copyright 2000 Werner Trobin and David Faure and | |
17 distributed under the GNU Lesser General Public License. | |
18 */ | |
19 | |
20 #ifndef _MULTI_VIEW_COMMAND_HISTORY_H_ | |
21 #define _MULTI_VIEW_COMMAND_HISTORY_H_ | |
22 | |
23 #include <QObject> | |
24 #include <QString> | |
25 | |
26 #include <stack> | |
27 #include <set> | |
28 #include <map> | |
29 | |
30 class Command; | |
31 class QAction; | |
32 class QMenu; | |
33 class QToolBar; | |
34 | |
35 /** | |
36 * The MultiViewCommandHistory class stores a list of executed | |
37 * commands and maintains Undo and Redo actions synchronised with | |
38 * those commands. | |
39 * | |
40 * MultiViewCommandHistory also allows you to associate more than one | |
41 * Undo and Redo action with the same command history, and it keeps | |
42 * them all up-to-date at once. This makes it effective in systems | |
43 * where multiple views may be editing the same data at once. | |
44 */ | |
45 | |
46 class MultiViewCommandHistory : public QObject | |
47 { | |
48 Q_OBJECT | |
49 | |
50 public: | |
51 MultiViewCommandHistory(); | |
52 virtual ~MultiViewCommandHistory(); | |
53 | |
54 void clear(); | |
55 | |
56 void registerMenu(QMenu *menu); | |
57 void registerToolbar(QToolBar *toolbar); | |
58 | |
59 void addCommand(Command *command, bool execute = true); | |
60 | |
61 /// Return the maximum number of items in the undo history. | |
62 int undoLimit() { return m_undoLimit; } | |
63 | |
64 /// Set the maximum number of items in the undo history. | |
65 void setUndoLimit(int limit); | |
66 | |
67 /// Return the maximum number of items in the redo history. | |
68 int redoLimit() { return m_redoLimit; } | |
69 | |
70 /// Set the maximum number of items in the redo history. | |
71 void setRedoLimit(int limit); | |
72 | |
73 public slots: | |
74 /** | |
75 * Checkpoint function that should be called when the document is | |
76 * saved. If the undo/redo stack later returns to the point at | |
77 * which the document was saved, the documentRestored signal will | |
78 * be emitted. | |
79 */ | |
80 virtual void documentSaved(); | |
81 | |
82 protected slots: | |
83 void undo(); | |
84 void redo(); | |
85 void undoActivated(QAction *); | |
86 void redoActivated(QAction *); | |
87 | |
88 signals: | |
89 /** | |
90 * Emitted whenever a command has just been executed, whether by | |
91 * addCommand, undo, or redo. | |
92 */ | |
93 void commandExecuted(Command *); | |
94 | |
95 /** | |
96 * Emitted whenever a command has just been executed, whether by | |
97 * addCommand, undo, or redo. | |
98 */ | |
99 void commandExecuted(); | |
100 | |
101 /** | |
102 * Emitted when the undo/redo stack has reached the same state at | |
103 * which the documentSaved slot was last called. | |
104 */ | |
105 void documentRestored(); | |
106 | |
107 private: | |
108 QAction *m_undoAction; | |
109 QAction *m_redoAction; | |
110 QMenu *m_undoMenu; | |
111 QMenu *m_redoMenu; | |
112 | |
113 std::map<QAction *, int> m_actionCounts; | |
114 | |
115 typedef std::stack<Command *> CommandStack; | |
116 CommandStack m_undoStack; | |
117 CommandStack m_redoStack; | |
118 | |
119 int m_undoLimit; | |
120 int m_redoLimit; | |
121 int m_savedAt; | |
122 | |
123 void updateActions(); | |
124 // void updateMenus(); | |
125 | |
126 // void updateButtons(); | |
127 // void updateButton(bool undo, const QString &name, CommandStack &stack); | |
128 // void updateMenu(bool undo, const QString &name, CommandStack &stack); | |
129 void clipCommands(); | |
130 | |
131 void clipStack(CommandStack &stack, int limit); | |
132 void clearStack(CommandStack &stack); | |
133 }; | |
134 | |
135 | |
136 #endif |