svgui
1.9
|
The CommandHistory class stores a list of executed commands and maintains Undo and Redo actions synchronised with those commands. More...
#include <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. | |
void | activity (QString) |
Emitted when some activity happened (for activity logging). | |
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 |
bool | m_bundling |
QString | m_currentBundleName |
QTimer * | m_bundleTimer |
int | m_bundleTimeout |
Static Protected Attributes | |
static CommandHistory * | m_instance = 0 |
The CommandHistory class stores a list of executed commands and maintains Undo and Redo actions synchronised with those commands.
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.
typedef std::stack<Command *> CommandHistory::CommandStack [protected] |
Definition at line 202 of file CommandHistory.h.
CommandHistory::~CommandHistory | ( | ) | [virtual] |
Definition at line 83 of file CommandHistory.cpp.
References clearStack(), m_redoMenu, m_redoStack, m_savedAt, m_undoMenu, and m_undoStack.
CommandHistory::CommandHistory | ( | ) | [protected] |
Definition at line 44 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 94 of file CommandHistory.cpp.
References CommandHistory(), and m_instance.
Referenced by ModelDataTableDialog::addCommand(), NoteLayer::addNoteOff(), FlexiNoteLayer::addNoteOff(), Layer::deleteCurrentMeasureRect(), TextLayer::editOpen(), ImageLayer::editOpen(), PropertyBox::editPlayParameters(), Pane::editSelectionEnd(), TextLayer::finish(), TimeInstantLayer::finish(), ImageLayer::finish(), NoteLayer::finish(), RegionLayer::finish(), TimeValueLayer::finish(), FlexiNoteLayer::finish(), SpectrogramLayer::measureDoubleClick(), Layer::measureEnd(), ModelDataTableDialog::ModelDataTableDialog(), PropertyBox::playAudibleButtonChanged(), PropertyBox::playGainDialChanged(), PropertyBox::playPanDialChanged(), PropertyBox::propertyControllerChanged(), ViewManager::setSelections(), and PropertyStack::showLayer().
void CommandHistory::clear | ( | ) |
Definition at line 101 of file CommandHistory.cpp.
References clearStack(), closeBundle(), m_redoStack, m_savedAt, m_undoStack, and updateActions().
void CommandHistory::registerMenu | ( | QMenu * | menu | ) |
Definition at line 114 of file CommandHistory.cpp.
References m_redoAction, and m_undoAction.
void CommandHistory::registerToolbar | ( | QToolBar * | toolbar | ) |
Definition at line 121 of file CommandHistory.cpp.
References m_redoMenuAction, and m_undoMenuAction.
Referenced by ModelDataTableDialog::ModelDataTableDialog().
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 128 of file CommandHistory.cpp.
References addToCompound(), m_currentCompound, and m_executeCompound.
Referenced by ModelDataTableDialog::addCommand(), addCommandAndExecute(), addExecutedCommand(), NoteLayer::addNoteOff(), FlexiNoteLayer::addNoteOff(), addToBundle(), Layer::deleteCurrentMeasureRect(), TextLayer::editOpen(), ImageLayer::editOpen(), PropertyBox::editPlayParameters(), endCompoundOperation(), TextLayer::finish(), TimeInstantLayer::finish(), ImageLayer::finish(), NoteLayer::finish(), RegionLayer::finish(), TimeValueLayer::finish(), FlexiNoteLayer::finish(), SpectrogramLayer::measureDoubleClick(), Layer::measureEnd(), PropertyBox::playAudibleButtonChanged(), PropertyBox::playGainDialChanged(), PropertyBox::playPanDialChanged(), PropertyBox::propertyControllerChanged(), ViewManager::setSelections(), and PropertyStack::showLayer().
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 141 of file CommandHistory.cpp.
References activity(), addToBundle(), addToCompound(), clearStack(), clipCommands(), closeBundle(), commandExecuted(), m_bundling, 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 389 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 398 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 407 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 414 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 282 of file CommandHistory.cpp.
References closeBundle(), m_currentCompound, and m_executeCompound.
Referenced by Pane::editSelectionEnd().
void CommandHistory::endCompoundOperation | ( | ) |
Finish recording commands and store the compound command.
Definition at line 301 of file CommandHistory.cpp.
References addCommand(), and m_currentCompound.
Referenced by Pane::editSelectionEnd().
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 420 of file CommandHistory.cpp.
References closeBundle(), m_savedAt, and m_undoStack.
void CommandHistory::addExecutedCommand | ( | Command * | 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 325 of file CommandHistory.cpp.
References addCommand().
void CommandHistory::addCommandAndExecute | ( | Command * | command | ) | [slot] |
Add a command to the history and also execute it.
Equivalent to addCommand(command, true).
Definition at line 331 of file CommandHistory.cpp.
References addCommand().
void CommandHistory::undo | ( | ) | [slot] |
Definition at line 337 of file CommandHistory.cpp.
References activity(), clipCommands(), closeBundle(), commandExecuted(), commandUnexecuted(), documentRestored(), m_redoStack, m_savedAt, m_undoStack, and updateActions().
Referenced by CommandHistory(), undoActivated(), and updateActions().
void CommandHistory::redo | ( | ) | [slot] |
Definition at line 363 of file CommandHistory.cpp.
References activity(), closeBundle(), commandExecuted(), documentRestored(), m_redoStack, m_savedAt, m_undoStack, and updateActions().
Referenced by CommandHistory(), and redoActivated().
void CommandHistory::undoActivated | ( | QAction * | action | ) | [protected, slot] |
Definition at line 479 of file CommandHistory.cpp.
References m_actionCounts, and undo().
Referenced by CommandHistory().
void CommandHistory::redoActivated | ( | QAction * | action | ) | [protected, slot] |
Definition at line 488 of file CommandHistory.cpp.
References m_actionCounts, and redo().
Referenced by CommandHistory().
void CommandHistory::bundleTimerTimeout | ( | ) | [protected, slot] |
Definition at line 256 of file CommandHistory.cpp.
References closeBundle(), and m_currentBundle.
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(), addToBundle(), 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::activity | ( | QString | ) | [signal] |
Emitted when some activity happened (for activity logging).
Referenced by addCommand(), closeBundle(), redo(), and undo().
void CommandHistory::addToCompound | ( | Command * | command, |
bool | execute | ||
) | [protected] |
Definition at line 266 of file CommandHistory.cpp.
References m_currentCompound.
Referenced by addCommand().
void CommandHistory::addToBundle | ( | Command * | command, |
bool | execute | ||
) | [protected] |
Definition at line 190 of file CommandHistory.cpp.
References addCommand(), bundleTimerTimeout(), closeBundle(), commandExecuted(), m_bundleTimeout, m_bundleTimer, m_bundling, m_currentBundle, m_currentBundleName, and updateActions().
Referenced by addCommand().
void CommandHistory::closeBundle | ( | ) | [protected] |
Definition at line 243 of file CommandHistory.cpp.
References activity(), m_currentBundle, and m_currentBundleName.
Referenced by addCommand(), addToBundle(), bundleTimerTimeout(), clear(), documentSaved(), redo(), startCompoundOperation(), and undo().
void CommandHistory::updateActions | ( | ) | [protected] |
Definition at line 497 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(), addToBundle(), clear(), redo(), setMenuLimit(), and undo().
void CommandHistory::clipCommands | ( | ) | [protected] |
Definition at line 427 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 438 of file CommandHistory.cpp.
References clearStack(), and m_undoLimit.
Referenced by clipCommands().
void CommandHistory::clearStack | ( | CommandStack & | stack | ) | [protected] |
Definition at line 465 of file CommandHistory.cpp.
Referenced by addCommand(), clear(), clipStack(), and ~CommandHistory().
CommandHistory * CommandHistory::m_instance = 0 [static, protected] |
Definition at line 191 of file CommandHistory.h.
Referenced by getInstance().
QAction* CommandHistory::m_undoAction [protected] |
Definition at line 193 of file CommandHistory.h.
Referenced by CommandHistory(), registerMenu(), and updateActions().
QAction* CommandHistory::m_redoAction [protected] |
Definition at line 194 of file CommandHistory.h.
Referenced by CommandHistory(), registerMenu(), and updateActions().
QAction* CommandHistory::m_undoMenuAction [protected] |
Definition at line 195 of file CommandHistory.h.
Referenced by CommandHistory(), registerToolbar(), and updateActions().
QAction* CommandHistory::m_redoMenuAction [protected] |
Definition at line 196 of file CommandHistory.h.
Referenced by CommandHistory(), registerToolbar(), and updateActions().
QMenu* CommandHistory::m_undoMenu [protected] |
Definition at line 197 of file CommandHistory.h.
Referenced by CommandHistory(), updateActions(), and ~CommandHistory().
QMenu* CommandHistory::m_redoMenu [protected] |
Definition at line 198 of file CommandHistory.h.
Referenced by CommandHistory(), updateActions(), and ~CommandHistory().
std::map<QAction *, int> CommandHistory::m_actionCounts [protected] |
Definition at line 200 of file CommandHistory.h.
Referenced by redoActivated(), undoActivated(), and updateActions().
CommandStack CommandHistory::m_undoStack [protected] |
Definition at line 203 of file CommandHistory.h.
Referenced by addCommand(), clear(), clipCommands(), documentSaved(), redo(), undo(), updateActions(), and ~CommandHistory().
CommandStack CommandHistory::m_redoStack [protected] |
Definition at line 204 of file CommandHistory.h.
Referenced by addCommand(), clear(), clipCommands(), redo(), undo(), updateActions(), and ~CommandHistory().
int CommandHistory::m_undoLimit [protected] |
Definition at line 206 of file CommandHistory.h.
Referenced by clipCommands(), clipStack(), getUndoLimit(), and setUndoLimit().
int CommandHistory::m_redoLimit [protected] |
Definition at line 207 of file CommandHistory.h.
Referenced by clipCommands(), getRedoLimit(), and setRedoLimit().
int CommandHistory::m_menuLimit [protected] |
Definition at line 208 of file CommandHistory.h.
Referenced by getMenuLimit(), setMenuLimit(), and updateActions().
int CommandHistory::m_savedAt [protected] |
Definition at line 209 of file CommandHistory.h.
Referenced by addCommand(), clear(), clipCommands(), documentSaved(), redo(), undo(), and ~CommandHistory().
MacroCommand* CommandHistory::m_currentCompound [protected] |
Definition at line 211 of file CommandHistory.h.
Referenced by addCommand(), addToCompound(), endCompoundOperation(), and startCompoundOperation().
bool CommandHistory::m_executeCompound [protected] |
Definition at line 212 of file CommandHistory.h.
Referenced by addCommand(), and startCompoundOperation().
MacroCommand* CommandHistory::m_currentBundle [protected] |
Definition at line 215 of file CommandHistory.h.
Referenced by addCommand(), addToBundle(), bundleTimerTimeout(), and closeBundle().
bool CommandHistory::m_bundling [protected] |
Definition at line 216 of file CommandHistory.h.
Referenced by addCommand(), and addToBundle().
QString CommandHistory::m_currentBundleName [protected] |
Definition at line 217 of file CommandHistory.h.
Referenced by addToBundle(), and closeBundle().
QTimer* CommandHistory::m_bundleTimer [protected] |
Definition at line 218 of file CommandHistory.h.
Referenced by addToBundle().
int CommandHistory::m_bundleTimeout [protected] |
Definition at line 219 of file CommandHistory.h.
Referenced by addToBundle(), getBundleTimeout(), and setBundleTimeout().