#include <CommandHistory.h>
Collaboration diagram for CommandHistory:

CommandHistory allows you to associate more than one Undo and Redo menu or toolbar with the same command history, and it keeps them all up-to-date at once. This makes it effective in systems where multiple views may be editing the same data.
Definition at line 52 of file CommandHistory.h.
Public Slots | |
| virtual void | documentSaved () |
| Checkpoint function that should be called when the document is saved. | |
| void | addExecutedCommand (Command *) |
| Add a command to the history that has already been executed, without executing it again. | |
| void | addCommandAndExecute (Command *) |
| Add a command to the history and also execute it. | |
| void | undo () |
| void | redo () |
Signals | |
| void | commandExecuted () |
| Emitted whenever a command has just been executed or unexecuted, whether by addCommand, undo, or redo. | |
| void | commandExecuted (Command *) |
| Emitted whenever a command has just been executed, whether by addCommand or redo. | |
| void | commandUnexecuted (Command *) |
| Emitted whenever a command has just been unexecuted, whether by addCommand or undo. | |
| void | documentRestored () |
| Emitted when the undo/redo stack has reached the same state at which the documentSaved slot was last called. | |
Public Member Functions | |
| virtual | ~CommandHistory () |
| void | clear () |
| void | registerMenu (QMenu *menu) |
| void | registerToolbar (QToolBar *toolbar) |
| void | addCommand (Command *command) |
| Add a command to the command history. | |
| void | addCommand (Command *command, bool execute, bool bundle=false) |
| Add a command to the command history. | |
| int | getUndoLimit () const |
| Return the maximum number of items in the undo history. | |
| void | setUndoLimit (int limit) |
| Set the maximum number of items in the undo history. | |
| int | getRedoLimit () const |
| Return the maximum number of items in the redo history. | |
| void | setRedoLimit (int limit) |
| Set the maximum number of items in the redo history. | |
| int | getMenuLimit () const |
| Return the maximum number of items visible in undo and redo menus. | |
| void | setMenuLimit (int limit) |
| Set the maximum number of items in the menus. | |
| int | getBundleTimeout () const |
| Return the time after which a bundle will be closed if nothing is added. | |
| void | setBundleTimeout (int msec) |
| Set the time after which a bundle will be closed if nothing is added. | |
| void | startCompoundOperation (QString name, bool execute) |
| Start recording commands to batch up into a single compound command. | |
| void | endCompoundOperation () |
| Finish recording commands and store the compound command. | |
Static Public Member Functions | |
| static CommandHistory * | getInstance () |
Protected Types | |
| typedef std::stack< Command * > | CommandStack |
Protected Slots | |
| void | undoActivated (QAction *) |
| void | redoActivated (QAction *) |
| void | bundleTimerTimeout () |
Protected Member Functions | |
| CommandHistory () | |
| void | addToCompound (Command *command, bool execute) |
| void | addToBundle (Command *command, bool execute) |
| void | closeBundle () |
| void | updateActions () |
| void | clipCommands () |
| void | clipStack (CommandStack &stack, int limit) |
| void | clearStack (CommandStack &stack) |
Protected Attributes | |
| QAction * | m_undoAction |
| QAction * | m_redoAction |
| QAction * | m_undoMenuAction |
| QAction * | m_redoMenuAction |
| QMenu * | m_undoMenu |
| QMenu * | m_redoMenu |
| std::map< QAction *, int > | m_actionCounts |
| CommandStack | m_undoStack |
| CommandStack | m_redoStack |
| int | m_undoLimit |
| int | m_redoLimit |
| int | m_menuLimit |
| int | m_savedAt |
| MacroCommand * | m_currentCompound |
| bool | m_executeCompound |
| MacroCommand * | m_currentBundle |
| QString | m_currentBundleName |
| QTimer * | m_bundleTimer |
| int | m_bundleTimeout |
Static Protected Attributes | |
| static CommandHistory * | m_instance |
typedef std::stack<Command *> CommandHistory::CommandStack [protected] |
Definition at line 197 of file CommandHistory.h.
| CommandHistory::~CommandHistory | ( | ) | [virtual] |
Definition at line 77 of file CommandHistory.cpp.
References clearStack(), m_redoMenu, m_redoStack, m_savedAt, m_undoMenu, and m_undoStack.
| CommandHistory::CommandHistory | ( | ) | [protected] |
Definition at line 39 of file CommandHistory.cpp.
References m_redoAction, m_redoMenu, m_redoMenuAction, m_undoAction, m_undoMenu, m_undoMenuAction, redo(), redoActivated(), undo(), and undoActivated().
Referenced by getInstance().
| CommandHistory * CommandHistory::getInstance | ( | ) | [static] |
Definition at line 88 of file CommandHistory.cpp.
References CommandHistory(), and m_instance.
Referenced by Document::addLayerToView(), MainWindow::addPane(), MainWindowBase::addPaneToStack(), MainWindow::closeSession(), MainWindowBase::cut(), Layer::deleteCurrentMeasureRect(), MainWindowBase::deleteCurrentPane(), TextLayer::editOpen(), ImageLayer::editOpen(), Pane::editSelectionEnd(), SparseModel< PointType >::EditCommand::finish(), MainWindow::handleOSCMessage(), MainWindowBase::insertInstantAt(), MainWindowBase::MainWindowBase(), SpectrogramLayer::measureDoubleClick(), Layer::measureEnd(), MainWindow::newSession(), MainWindowBase::openAudio(), MainWindowBase::openSession(), MainWindowBase::paneDeleteButtonClicked(), MainWindowBase::paste(), Document::removeLayerFromView(), MainWindow::saveSession(), MainWindow::saveSessionAs(), PropertyContainer::setPropertyWithCommand(), ViewManager::setSelections(), MainWindow::setupEditMenu(), MainWindow::setupMenus(), MainWindow::setupToolbars(), and Document::~Document().
| void CommandHistory::clear | ( | ) |
Definition at line 95 of file CommandHistory.cpp.
References clearStack(), closeBundle(), m_redoStack, m_savedAt, m_undoStack, and updateActions().
Referenced by MainWindow::closeSession(), MainWindow::newSession(), MainWindowBase::openAudio(), MainWindowBase::openSession(), and Document::~Document().
| void CommandHistory::registerMenu | ( | QMenu * | menu | ) |
Definition at line 106 of file CommandHistory.cpp.
References m_redoAction, and m_undoAction.
Referenced by MainWindow::setupEditMenu(), and MainWindow::setupMenus().
| void CommandHistory::registerToolbar | ( | QToolBar * | toolbar | ) |
Definition at line 113 of file CommandHistory.cpp.
References m_redoMenuAction, and m_undoMenuAction.
Referenced by MainWindow::setupToolbars().
| void CommandHistory::addCommand | ( | Command * | command | ) |
Add a command to the command history.
The command will normally be executed before being added; but if a compound operation is in use (see startCompoundOperation below), the execute status of the compound operation will determine whether the command is executed or not.
Definition at line 120 of file CommandHistory.cpp.
References addToCompound(), m_currentCompound, and m_executeCompound.
Referenced by addCommandAndExecute(), addExecutedCommand(), Document::addLayerToView(), MainWindow::addPane(), MainWindowBase::addPaneToStack(), addToBundle(), Layer::deleteCurrentMeasureRect(), MainWindowBase::deleteCurrentPane(), TextLayer::editOpen(), ImageLayer::editOpen(), endCompoundOperation(), SparseModel< PointType >::EditCommand::finish(), SpectrogramLayer::measureDoubleClick(), Layer::measureEnd(), MainWindowBase::openAudio(), MainWindowBase::paneDeleteButtonClicked(), Document::removeLayerFromView(), PropertyContainer::setPropertyWithCommand(), and ViewManager::setSelections().
| void CommandHistory::addCommand | ( | Command * | command, | |
| bool | execute, | |||
| bool | bundle = false | |||
| ) |
Add a command to the command history.
If execute is true, the command will be executed before being added. Otherwise it will be assumed to have been already executed -- a command should not be added to the history unless its work has actually been done somehow!
If a compound operation is in use (see startCompoundOperation below), the execute value passed to this method will override the execute status of the compound operation. In this way it's possible to have a compound operation mixing both to-execute and pre-executed commands.
If bundle is true, the command will be a candidate for bundling with any adjacent bundleable commands that have the same name, into a single compound command. This is useful for small commands that may be executed repeatedly altering the same data (e.g. type text, set a parameter) whose number and extent is not known in advance. The bundle parameter will be ignored if a compound operation is already in use.
Definition at line 133 of file CommandHistory.cpp.
References addToBundle(), addToCompound(), clearStack(), clipCommands(), closeBundle(), commandExecuted(), Command::execute(), m_currentBundle, m_currentCompound, m_redoStack, m_savedAt, m_undoStack, and updateActions().
| int CommandHistory::getUndoLimit | ( | ) | const [inline] |
Return the maximum number of items in the undo history.
Definition at line 101 of file CommandHistory.h.
References m_undoLimit.
| void CommandHistory::setUndoLimit | ( | int | limit | ) |
Set the maximum number of items in the undo history.
Definition at line 318 of file CommandHistory.cpp.
References clipCommands(), and m_undoLimit.
| int CommandHistory::getRedoLimit | ( | ) | const [inline] |
Return the maximum number of items in the redo history.
Definition at line 107 of file CommandHistory.h.
References m_redoLimit.
| void CommandHistory::setRedoLimit | ( | int | limit | ) |
Set the maximum number of items in the redo history.
Definition at line 327 of file CommandHistory.cpp.
References clipCommands(), and m_redoLimit.
| int CommandHistory::getMenuLimit | ( | ) | const [inline] |
Return the maximum number of items visible in undo and redo menus.
Definition at line 113 of file CommandHistory.h.
References m_menuLimit.
| void CommandHistory::setMenuLimit | ( | int | limit | ) |
Set the maximum number of items in the menus.
Definition at line 336 of file CommandHistory.cpp.
References m_menuLimit, and updateActions().
| int CommandHistory::getBundleTimeout | ( | ) | const [inline] |
Return the time after which a bundle will be closed if nothing is added.
Definition at line 119 of file CommandHistory.h.
References m_bundleTimeout.
| void CommandHistory::setBundleTimeout | ( | int | msec | ) |
Set the time after which a bundle will be closed if nothing is added.
Definition at line 343 of file CommandHistory.cpp.
References m_bundleTimeout.
| void CommandHistory::startCompoundOperation | ( | QString | name, | |
| bool | execute | |||
| ) |
Start recording commands to batch up into a single compound command.
Definition at line 229 of file CommandHistory.cpp.
References closeBundle(), MacroCommand::getName(), m_currentCompound, and m_executeCompound.
Referenced by MainWindow::addPane(), MainWindowBase::cut(), MainWindowBase::deleteCurrentPane(), Pane::editSelectionEnd(), MainWindowBase::insertInstantAt(), MainWindowBase::openAudio(), MainWindowBase::paneDeleteButtonClicked(), and MainWindowBase::paste().
| void CommandHistory::endCompoundOperation | ( | ) |
Finish recording commands and store the compound command.
Definition at line 244 of file CommandHistory.cpp.
References addCommand(), MacroCommand::haveCommands(), and m_currentCompound.
Referenced by MainWindow::addPane(), MainWindowBase::cut(), MainWindowBase::deleteCurrentPane(), Pane::editSelectionEnd(), MainWindowBase::insertInstantAt(), MainWindowBase::openAudio(), MainWindowBase::paneDeleteButtonClicked(), and MainWindowBase::paste().
| void CommandHistory::documentSaved | ( | ) | [virtual, slot] |
Checkpoint function that should be called when the document is saved.
If the undo/redo stack later returns to the point at which the document was saved, the documentRestored signal will be emitted.
Definition at line 349 of file CommandHistory.cpp.
References closeBundle(), m_savedAt, and m_undoStack.
Referenced by MainWindow::closeSession(), MainWindow::newSession(), MainWindowBase::openAudio(), MainWindowBase::openSession(), MainWindow::saveSession(), and MainWindow::saveSessionAs().
| void CommandHistory::addExecutedCommand | ( | Command * | ) | [slot] |
Add a command to the history that has already been executed, without executing it again.
Equivalent to addCommand(command, false).
Definition at line 264 of file CommandHistory.cpp.
References addCommand().
| void CommandHistory::addCommandAndExecute | ( | Command * | ) | [slot] |
Add a command to the history and also execute it.
Equivalent to addCommand(command, true).
Definition at line 270 of file CommandHistory.cpp.
References addCommand().
| void CommandHistory::undo | ( | ) | [slot] |
Definition at line 276 of file CommandHistory.cpp.
References clipCommands(), closeBundle(), commandExecuted(), commandUnexecuted(), documentRestored(), m_redoStack, m_savedAt, m_undoStack, Command::unexecute(), and updateActions().
Referenced by CommandHistory(), MainWindow::handleOSCMessage(), undoActivated(), and updateActions().
| void CommandHistory::redo | ( | ) | [slot] |
Definition at line 297 of file CommandHistory.cpp.
References closeBundle(), commandExecuted(), documentRestored(), Command::execute(), m_redoStack, m_savedAt, m_undoStack, and updateActions().
Referenced by CommandHistory(), MainWindow::handleOSCMessage(), and redoActivated().
| void CommandHistory::undoActivated | ( | QAction * | ) | [protected, slot] |
Definition at line 404 of file CommandHistory.cpp.
References m_actionCounts, and undo().
Referenced by CommandHistory().
| void CommandHistory::redoActivated | ( | QAction * | ) | [protected, slot] |
Definition at line 413 of file CommandHistory.cpp.
References m_actionCounts, and redo().
Referenced by CommandHistory().
| void CommandHistory::bundleTimerTimeout | ( | ) | [protected, slot] |
Definition at line 210 of file CommandHistory.cpp.
References closeBundle().
Referenced by addToBundle().
| void CommandHistory::commandExecuted | ( | ) | [signal] |
Emitted whenever a command has just been executed or unexecuted, whether by addCommand, undo, or redo.
Referenced by addCommand(), redo(), and undo().
| void CommandHistory::commandExecuted | ( | Command * | ) | [signal] |
Emitted whenever a command has just been executed, whether by addCommand or redo.
| void CommandHistory::commandUnexecuted | ( | Command * | ) | [signal] |
Emitted whenever a command has just been unexecuted, whether by addCommand or undo.
Referenced by undo().
| void CommandHistory::documentRestored | ( | ) | [signal] |
| void CommandHistory::addToCompound | ( | Command * | command, | |
| bool | execute | |||
| ) | [protected] |
Definition at line 216 of file CommandHistory.cpp.
References MacroCommand::addCommand(), Command::execute(), and m_currentCompound.
Referenced by addCommand().
| void CommandHistory::addToBundle | ( | Command * | command, | |
| bool | execute | |||
| ) | [protected] |
Definition at line 174 of file CommandHistory.cpp.
References MacroCommand::addCommand(), addCommand(), bundleTimerTimeout(), closeBundle(), Command::execute(), Command::getName(), m_bundleTimeout, m_bundleTimer, m_currentBundle, and m_currentBundleName.
Referenced by addCommand().
| void CommandHistory::closeBundle | ( | ) | [protected] |
Definition at line 203 of file CommandHistory.cpp.
References m_currentBundle, and m_currentBundleName.
Referenced by addCommand(), addToBundle(), bundleTimerTimeout(), clear(), documentSaved(), redo(), startCompoundOperation(), and undo().
| void CommandHistory::updateActions | ( | ) | [protected] |
Definition at line 422 of file CommandHistory.cpp.
References m_actionCounts, m_menuLimit, m_redoAction, m_redoMenu, m_redoMenuAction, m_redoStack, m_undoAction, m_undoMenu, m_undoMenuAction, m_undoStack, and undo().
Referenced by addCommand(), clear(), redo(), setMenuLimit(), and undo().
| void CommandHistory::clipCommands | ( | ) | [protected] |
Definition at line 356 of file CommandHistory.cpp.
References clipStack(), m_redoLimit, m_redoStack, m_savedAt, m_undoLimit, and m_undoStack.
Referenced by addCommand(), setRedoLimit(), setUndoLimit(), and undo().
| void CommandHistory::clipStack | ( | CommandStack & | stack, | |
| int | limit | |||
| ) | [protected] |
Definition at line 367 of file CommandHistory.cpp.
References clearStack(), and m_undoLimit.
Referenced by clipCommands().
| void CommandHistory::clearStack | ( | CommandStack & | stack | ) | [protected] |
Definition at line 392 of file CommandHistory.cpp.
Referenced by addCommand(), clear(), clipStack(), and ~CommandHistory().
CommandHistory * CommandHistory::m_instance [static, protected] |
QAction* CommandHistory::m_undoAction [protected] |
Definition at line 188 of file CommandHistory.h.
Referenced by CommandHistory(), registerMenu(), and updateActions().
QAction* CommandHistory::m_redoAction [protected] |
Definition at line 189 of file CommandHistory.h.
Referenced by CommandHistory(), registerMenu(), and updateActions().
QAction* CommandHistory::m_undoMenuAction [protected] |
Definition at line 190 of file CommandHistory.h.
Referenced by CommandHistory(), registerToolbar(), and updateActions().
QAction* CommandHistory::m_redoMenuAction [protected] |
Definition at line 191 of file CommandHistory.h.
Referenced by CommandHistory(), registerToolbar(), and updateActions().
QMenu* CommandHistory::m_undoMenu [protected] |
Definition at line 192 of file CommandHistory.h.
Referenced by CommandHistory(), updateActions(), and ~CommandHistory().
QMenu* CommandHistory::m_redoMenu [protected] |
Definition at line 193 of file CommandHistory.h.
Referenced by CommandHistory(), updateActions(), and ~CommandHistory().
std::map<QAction *, int> CommandHistory::m_actionCounts [protected] |
Definition at line 195 of file CommandHistory.h.
Referenced by redoActivated(), undoActivated(), and updateActions().
CommandStack CommandHistory::m_undoStack [protected] |
Definition at line 198 of file CommandHistory.h.
Referenced by addCommand(), clear(), clipCommands(), documentSaved(), redo(), undo(), updateActions(), and ~CommandHistory().
CommandStack CommandHistory::m_redoStack [protected] |
Definition at line 199 of file CommandHistory.h.
Referenced by addCommand(), clear(), clipCommands(), redo(), undo(), updateActions(), and ~CommandHistory().
int CommandHistory::m_undoLimit [protected] |
Definition at line 201 of file CommandHistory.h.
Referenced by clipCommands(), clipStack(), getUndoLimit(), and setUndoLimit().
int CommandHistory::m_redoLimit [protected] |
Definition at line 202 of file CommandHistory.h.
Referenced by clipCommands(), getRedoLimit(), and setRedoLimit().
int CommandHistory::m_menuLimit [protected] |
Definition at line 203 of file CommandHistory.h.
Referenced by getMenuLimit(), setMenuLimit(), and updateActions().
int CommandHistory::m_savedAt [protected] |
Definition at line 204 of file CommandHistory.h.
Referenced by addCommand(), clear(), clipCommands(), documentSaved(), redo(), undo(), and ~CommandHistory().
MacroCommand* CommandHistory::m_currentCompound [protected] |
Definition at line 206 of file CommandHistory.h.
Referenced by addCommand(), addToCompound(), endCompoundOperation(), and startCompoundOperation().
bool CommandHistory::m_executeCompound [protected] |
Definition at line 207 of file CommandHistory.h.
Referenced by addCommand(), and startCompoundOperation().
MacroCommand* CommandHistory::m_currentBundle [protected] |
Definition at line 210 of file CommandHistory.h.
Referenced by addCommand(), addToBundle(), and closeBundle().
QString CommandHistory::m_currentBundleName [protected] |
QTimer* CommandHistory::m_bundleTimer [protected] |
int CommandHistory::m_bundleTimeout [protected] |
Definition at line 213 of file CommandHistory.h.
Referenced by addToBundle(), getBundleTimeout(), and setBundleTimeout().
1.5.1