annotate base/CommandHistory.h @ 54:709d63d90028

fixed some bugs in tonal change detection function, removed ChromaMatrix (no longer used), added TCSgram
author Martin Gasser
date Tue, 21 Mar 2006 18:05:28 +0000
parents d397ea0a79f5
children 90ade4fa63be
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@16 2
Chris@16 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@16 7
Chris@52 8 This program is free software; you can redistribute it and/or
Chris@52 9 modify it under the terms of the GNU General Public License as
Chris@52 10 published by the Free Software Foundation; either version 2 of the
Chris@52 11 License, or (at your option) any later version. See the file
Chris@52 12 COPYING included with this distribution for more information.
Chris@16 13 */
Chris@16 14
Chris@16 15 /*
Chris@16 16 This is a modified version of a source file from the Rosegarden
Chris@16 17 MIDI and audio sequencer and notation editor, copyright 2000-2006
Chris@16 18 Chris Cannam, distributed under the GNU General Public License.
Chris@16 19
Chris@16 20 This file contains traces of the KCommandHistory class from the KDE
Chris@16 21 project, copyright 2000 Werner Trobin and David Faure and
Chris@16 22 distributed under the GNU Lesser General Public License.
Chris@16 23 */
Chris@16 24
Chris@16 25 #ifndef _MULTI_VIEW_COMMAND_HISTORY_H_
Chris@16 26 #define _MULTI_VIEW_COMMAND_HISTORY_H_
Chris@16 27
Chris@16 28 #include <QObject>
Chris@16 29 #include <QString>
Chris@16 30
Chris@16 31 #include <stack>
Chris@16 32 #include <set>
Chris@16 33 #include <map>
Chris@16 34
Chris@16 35 class Command;
Chris@44 36 class MacroCommand;
Chris@16 37 class QAction;
Chris@16 38 class QMenu;
Chris@16 39 class QToolBar;
Chris@47 40 class QTimer;
Chris@16 41
Chris@16 42 /**
Chris@17 43 * The CommandHistory class stores a list of executed commands and
Chris@17 44 * maintains Undo and Redo actions synchronised with those commands.
Chris@16 45 *
Chris@17 46 * CommandHistory allows you to associate more than one Undo and Redo
Chris@17 47 * menu or toolbar with the same command history, and it keeps them
Chris@17 48 * all up-to-date at once. This makes it effective in systems where
Chris@17 49 * multiple views may be editing the same data.
Chris@16 50 */
Chris@16 51
Chris@17 52 class CommandHistory : public QObject
Chris@16 53 {
Chris@16 54 Q_OBJECT
Chris@16 55
Chris@16 56 public:
Chris@17 57 virtual ~CommandHistory();
Chris@17 58
Chris@17 59 static CommandHistory *getInstance();
Chris@16 60
Chris@16 61 void clear();
Chris@16 62
Chris@16 63 void registerMenu(QMenu *menu);
Chris@16 64 void registerToolbar(QToolBar *toolbar);
Chris@16 65
Chris@47 66 /**
Chris@47 67 * Add a command to the command history.
Chris@47 68 *
Chris@47 69 * If execute is true, the command will be executed before being
Chris@47 70 * added. Otherwise it will be assumed to have been already
Chris@47 71 * executed -- a command should not be added to the history unless
Chris@47 72 * its work has actually been done somehow!
Chris@47 73 *
Chris@47 74 * If a compound operation is in use (see startCompoundOperation
Chris@47 75 * below), the execute status of the compound operation will
Chris@47 76 * override any value of execute passed to this method.
Chris@47 77 *
Chris@47 78 * If bundle is true, the command will be a candidate for bundling
Chris@47 79 * with any adjacent bundeable commands that have the same name,
Chris@47 80 * into a single compound command. This is useful for small
Chris@47 81 * commands that may be executed repeatedly altering the same data
Chris@47 82 * (e.g. type text, set a parameter) whose number and extent is
Chris@47 83 * not known in advance. The bundle parameter will be ignored if
Chris@47 84 * a compound operation is already in use.
Chris@47 85 */
Chris@47 86 void addCommand(Command *command, bool execute = true, bool bundle = false);
Chris@16 87
Chris@16 88 /// Return the maximum number of items in the undo history.
Chris@46 89 int getUndoLimit() const { return m_undoLimit; }
Chris@16 90
Chris@16 91 /// Set the maximum number of items in the undo history.
Chris@16 92 void setUndoLimit(int limit);
Chris@16 93
Chris@16 94 /// Return the maximum number of items in the redo history.
Chris@46 95 int getRedoLimit() const { return m_redoLimit; }
Chris@16 96
Chris@16 97 /// Set the maximum number of items in the redo history.
Chris@16 98 void setRedoLimit(int limit);
Chris@16 99
Chris@46 100 /// Return the maximum number of items visible in undo and redo menus.
Chris@46 101 int getMenuLimit() const { return m_menuLimit; }
Chris@46 102
Chris@46 103 /// Set the maximum number of items in the menus.
Chris@46 104 void setMenuLimit(int limit);
Chris@46 105
Chris@47 106 /// Return the time after which a bundle will be closed if nothing is added.
Chris@47 107 int getBundleTimeout() const { return m_bundleTimeout; }
Chris@47 108
Chris@47 109 /// Set the time after which a bundle will be closed if nothing is added.
Chris@47 110 void setBundleTimeout(int msec);
Chris@47 111
Chris@44 112 /// Start recording commands to batch up into a single compound command.
Chris@44 113 void startCompoundOperation(QString name, bool execute);
Chris@44 114
Chris@44 115 /// Finish recording commands and store the compound command.
Chris@44 116 void endCompoundOperation();
Chris@44 117
Chris@16 118 public slots:
Chris@16 119 /**
Chris@16 120 * Checkpoint function that should be called when the document is
Chris@16 121 * saved. If the undo/redo stack later returns to the point at
Chris@16 122 * which the document was saved, the documentRestored signal will
Chris@16 123 * be emitted.
Chris@16 124 */
Chris@16 125 virtual void documentSaved();
Chris@16 126
Chris@17 127 /**
Chris@17 128 * Add a command to the history that has already been executed,
Chris@17 129 * without executing it again. Equivalent to addCommand(command, false).
Chris@17 130 */
Chris@17 131 void addExecutedCommand(Command *);
Chris@17 132
Chris@17 133 /**
Chris@17 134 * Add a command to the history and also execute it. Equivalent
Chris@17 135 * to addCommand(command, true).
Chris@17 136 */
Chris@17 137 void addCommandAndExecute(Command *);
Chris@17 138
Chris@16 139 protected slots:
Chris@16 140 void undo();
Chris@16 141 void redo();
Chris@16 142 void undoActivated(QAction *);
Chris@16 143 void redoActivated(QAction *);
Chris@47 144 void bundleTimerTimeout();
Chris@47 145
Chris@16 146 signals:
Chris@16 147 /**
Chris@17 148 * Emitted whenever a command has just been executed or
Chris@17 149 * unexecuted, whether by addCommand, undo, or redo.
Chris@17 150 */
Chris@17 151 void commandExecuted();
Chris@17 152
Chris@17 153 /**
Chris@16 154 * Emitted whenever a command has just been executed, whether by
Chris@17 155 * addCommand or redo.
Chris@16 156 */
Chris@16 157 void commandExecuted(Command *);
Chris@16 158
Chris@16 159 /**
Chris@17 160 * Emitted whenever a command has just been unexecuted, whether by
Chris@17 161 * addCommand or undo.
Chris@16 162 */
Chris@17 163 void commandUnexecuted(Command *);
Chris@16 164
Chris@16 165 /**
Chris@16 166 * Emitted when the undo/redo stack has reached the same state at
Chris@16 167 * which the documentSaved slot was last called.
Chris@16 168 */
Chris@16 169 void documentRestored();
Chris@16 170
Chris@17 171 protected:
Chris@17 172 CommandHistory();
Chris@17 173 static CommandHistory *m_instance;
Chris@17 174
Chris@16 175 QAction *m_undoAction;
Chris@16 176 QAction *m_redoAction;
Chris@17 177 QAction *m_undoMenuAction;
Chris@17 178 QAction *m_redoMenuAction;
Chris@16 179 QMenu *m_undoMenu;
Chris@16 180 QMenu *m_redoMenu;
Chris@16 181
Chris@16 182 std::map<QAction *, int> m_actionCounts;
Chris@16 183
Chris@16 184 typedef std::stack<Command *> CommandStack;
Chris@16 185 CommandStack m_undoStack;
Chris@16 186 CommandStack m_redoStack;
Chris@16 187
Chris@16 188 int m_undoLimit;
Chris@16 189 int m_redoLimit;
Chris@46 190 int m_menuLimit;
Chris@16 191 int m_savedAt;
Chris@16 192
Chris@47 193 MacroCommand *m_currentCompound;
Chris@47 194 bool m_executeCompound;
Chris@47 195 void addToCompound(Command *command);
Chris@47 196
Chris@47 197 MacroCommand *m_currentBundle;
Chris@47 198 QString m_currentBundleName;
Chris@47 199 QTimer *m_bundleTimer;
Chris@47 200 int m_bundleTimeout;
Chris@47 201 void addToBundle(Command *command, bool execute);
Chris@47 202 void closeBundle();
Chris@44 203
Chris@16 204 void updateActions();
Chris@16 205
Chris@16 206 void clipCommands();
Chris@16 207
Chris@16 208 void clipStack(CommandStack &stack, int limit);
Chris@16 209 void clearStack(CommandStack &stack);
Chris@16 210 };
Chris@16 211
Chris@16 212
Chris@16 213 #endif