annotate base/CommandHistory.h @ 46:5364a9d338a2

* Add Insert Instant function in main window * Ensure selections and window geometry are saved in session file * Add wait cursor on session file save * Various improvements to display of texts in pane (clearer readability) * Use commands for setting properties on layers and panes (still need to batch up multiple sets on the same property) * Fix failure of spectrogram to refresh when initial part became visible * Some fixes & paint optimisations in View &c * Make curve mode for time value layers work properly when resolution == 1 * Some vague improvements for time value layer vertical scale
author Chris Cannam
date Thu, 16 Mar 2006 18:46:00 +0000
parents 701404725897
children bac8b14ab355
rev   line source
Chris@16 1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
Chris@16 2
Chris@16 3 /*
Chris@16 4 A waveform viewer and audio annotation editor.
Chris@16 5 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@16 6
Chris@16 7 This is experimental software. Not for distribution.
Chris@16 8 */
Chris@16 9
Chris@16 10 /*
Chris@16 11 This is a modified version of a source file from the Rosegarden
Chris@16 12 MIDI and audio sequencer and notation editor, copyright 2000-2006
Chris@16 13 Chris Cannam, distributed under the GNU General Public License.
Chris@16 14
Chris@16 15 This file contains traces of the KCommandHistory class from the KDE
Chris@16 16 project, copyright 2000 Werner Trobin and David Faure and
Chris@16 17 distributed under the GNU Lesser General Public License.
Chris@16 18 */
Chris@16 19
Chris@16 20 #ifndef _MULTI_VIEW_COMMAND_HISTORY_H_
Chris@16 21 #define _MULTI_VIEW_COMMAND_HISTORY_H_
Chris@16 22
Chris@16 23 #include <QObject>
Chris@16 24 #include <QString>
Chris@16 25
Chris@16 26 #include <stack>
Chris@16 27 #include <set>
Chris@16 28 #include <map>
Chris@16 29
Chris@16 30 class Command;
Chris@44 31 class MacroCommand;
Chris@16 32 class QAction;
Chris@16 33 class QMenu;
Chris@16 34 class QToolBar;
Chris@16 35
Chris@16 36 /**
Chris@17 37 * The CommandHistory class stores a list of executed commands and
Chris@17 38 * maintains Undo and Redo actions synchronised with those commands.
Chris@16 39 *
Chris@17 40 * CommandHistory allows you to associate more than one Undo and Redo
Chris@17 41 * menu or toolbar with the same command history, and it keeps them
Chris@17 42 * all up-to-date at once. This makes it effective in systems where
Chris@17 43 * multiple views may be editing the same data.
Chris@16 44 */
Chris@16 45
Chris@17 46 class CommandHistory : public QObject
Chris@16 47 {
Chris@16 48 Q_OBJECT
Chris@16 49
Chris@16 50 public:
Chris@17 51 virtual ~CommandHistory();
Chris@17 52
Chris@17 53 static CommandHistory *getInstance();
Chris@16 54
Chris@16 55 void clear();
Chris@16 56
Chris@16 57 void registerMenu(QMenu *menu);
Chris@16 58 void registerToolbar(QToolBar *toolbar);
Chris@16 59
Chris@16 60 void addCommand(Command *command, bool execute = true);
Chris@16 61
Chris@16 62 /// Return the maximum number of items in the undo history.
Chris@46 63 int getUndoLimit() const { return m_undoLimit; }
Chris@16 64
Chris@16 65 /// Set the maximum number of items in the undo history.
Chris@16 66 void setUndoLimit(int limit);
Chris@16 67
Chris@16 68 /// Return the maximum number of items in the redo history.
Chris@46 69 int getRedoLimit() const { return m_redoLimit; }
Chris@16 70
Chris@16 71 /// Set the maximum number of items in the redo history.
Chris@16 72 void setRedoLimit(int limit);
Chris@16 73
Chris@46 74 /// Return the maximum number of items visible in undo and redo menus.
Chris@46 75 int getMenuLimit() const { return m_menuLimit; }
Chris@46 76
Chris@46 77 /// Set the maximum number of items in the menus.
Chris@46 78 void setMenuLimit(int limit);
Chris@46 79
Chris@44 80 /// Start recording commands to batch up into a single compound command.
Chris@44 81 void startCompoundOperation(QString name, bool execute);
Chris@44 82
Chris@44 83 /// Finish recording commands and store the compound command.
Chris@44 84 void endCompoundOperation();
Chris@44 85
Chris@16 86 public slots:
Chris@16 87 /**
Chris@16 88 * Checkpoint function that should be called when the document is
Chris@16 89 * saved. If the undo/redo stack later returns to the point at
Chris@16 90 * which the document was saved, the documentRestored signal will
Chris@16 91 * be emitted.
Chris@16 92 */
Chris@16 93 virtual void documentSaved();
Chris@16 94
Chris@17 95 /**
Chris@17 96 * Add a command to the history that has already been executed,
Chris@17 97 * without executing it again. Equivalent to addCommand(command, false).
Chris@17 98 */
Chris@17 99 void addExecutedCommand(Command *);
Chris@17 100
Chris@17 101 /**
Chris@17 102 * Add a command to the history and also execute it. Equivalent
Chris@17 103 * to addCommand(command, true).
Chris@17 104 */
Chris@17 105 void addCommandAndExecute(Command *);
Chris@17 106
Chris@16 107 protected slots:
Chris@16 108 void undo();
Chris@16 109 void redo();
Chris@16 110 void undoActivated(QAction *);
Chris@16 111 void redoActivated(QAction *);
Chris@16 112
Chris@16 113 signals:
Chris@16 114 /**
Chris@17 115 * Emitted whenever a command has just been executed or
Chris@17 116 * unexecuted, whether by addCommand, undo, or redo.
Chris@17 117 */
Chris@17 118 void commandExecuted();
Chris@17 119
Chris@17 120 /**
Chris@16 121 * Emitted whenever a command has just been executed, whether by
Chris@17 122 * addCommand or redo.
Chris@16 123 */
Chris@16 124 void commandExecuted(Command *);
Chris@16 125
Chris@16 126 /**
Chris@17 127 * Emitted whenever a command has just been unexecuted, whether by
Chris@17 128 * addCommand or undo.
Chris@16 129 */
Chris@17 130 void commandUnexecuted(Command *);
Chris@16 131
Chris@16 132 /**
Chris@16 133 * Emitted when the undo/redo stack has reached the same state at
Chris@16 134 * which the documentSaved slot was last called.
Chris@16 135 */
Chris@16 136 void documentRestored();
Chris@16 137
Chris@17 138 protected:
Chris@17 139 CommandHistory();
Chris@17 140 static CommandHistory *m_instance;
Chris@17 141
Chris@16 142 QAction *m_undoAction;
Chris@16 143 QAction *m_redoAction;
Chris@17 144 QAction *m_undoMenuAction;
Chris@17 145 QAction *m_redoMenuAction;
Chris@16 146 QMenu *m_undoMenu;
Chris@16 147 QMenu *m_redoMenu;
Chris@16 148
Chris@16 149 std::map<QAction *, int> m_actionCounts;
Chris@16 150
Chris@16 151 typedef std::stack<Command *> CommandStack;
Chris@16 152 CommandStack m_undoStack;
Chris@16 153 CommandStack m_redoStack;
Chris@16 154
Chris@16 155 int m_undoLimit;
Chris@16 156 int m_redoLimit;
Chris@46 157 int m_menuLimit;
Chris@16 158 int m_savedAt;
Chris@16 159
Chris@44 160 MacroCommand *m_currentMacro;
Chris@44 161 bool m_executeMacro;
Chris@44 162 void addToMacro(Command *command);
Chris@44 163
Chris@16 164 void updateActions();
Chris@16 165
Chris@16 166 void clipCommands();
Chris@16 167
Chris@16 168 void clipStack(CommandStack &stack, int limit);
Chris@16 169 void clearStack(CommandStack &stack);
Chris@16 170 };
Chris@16 171
Chris@16 172
Chris@16 173 #endif