svgui  1.9
CommandHistory Class Reference

The CommandHistory class stores a list of executed commands and maintains Undo and Redo actions synchronised with those commands. More...

#include <CommandHistory.h>

Inheritance diagram for CommandHistory:
Collaboration diagram for CommandHistory:

Public Slots

virtual void documentSaved ()
 Checkpoint function that should be called when the document is saved. More...
 
void addExecutedCommand (Command *)
 Add a command to the history that has already been executed, without executing it again. More...
 
void addCommandAndExecute (Command *)
 Add a command to the history and also execute it. More...
 
void undo ()
 
void redo ()
 

Signals

void commandExecuted ()
 Emitted whenever a command has just been executed or unexecuted, whether by addCommand, undo, or redo. More...
 
void commandExecuted (Command *)
 Emitted whenever a command has just been executed, whether by addCommand or redo. More...
 
void commandUnexecuted (Command *)
 Emitted whenever a command has just been unexecuted, whether by addCommand or undo. More...
 
void documentRestored ()
 Emitted when the undo/redo stack has reached the same state at which the documentSaved slot was last called. More...
 
void activity (QString)
 Emitted when some activity happened (for activity logging). More...
 

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. More...
 
void addCommand (Command *command, bool execute, bool bundle=false)
 Add a command to the command history. More...
 
int getUndoLimit () const
 Return the maximum number of items in the undo history. More...
 
void setUndoLimit (int limit)
 Set the maximum number of items in the undo history. More...
 
int getRedoLimit () const
 Return the maximum number of items in the redo history. More...
 
void setRedoLimit (int limit)
 Set the maximum number of items in the redo history. More...
 
int getMenuLimit () const
 Return the maximum number of items visible in undo and redo menus. More...
 
void setMenuLimit (int limit)
 Set the maximum number of items in the menus. More...
 
int getBundleTimeout () const
 Return the time after which a bundle will be closed if nothing is added. More...
 
void setBundleTimeout (int msec)
 Set the time after which a bundle will be closed if nothing is added. More...
 
void startCompoundOperation (QString name, bool execute)
 Start recording commands to batch up into a single compound command. More...
 
void endCompoundOperation ()
 Finish recording commands and store the compound command. More...
 

Static Public Member Functions

static CommandHistorygetInstance ()
 

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 CommandHistorym_instance = 0
 

Detailed Description

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.

Member Typedef Documentation

◆ CommandStack

typedef std::stack<Command *> CommandHistory::CommandStack
protected

Definition at line 202 of file CommandHistory.h.

Constructor & Destructor Documentation

◆ ~CommandHistory()

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::CommandHistory ( )
protected

Member Function Documentation

◆ getInstance()

◆ clear()

void CommandHistory::clear ( )

◆ registerMenu()

void CommandHistory::registerMenu ( QMenu *  menu)

Definition at line 114 of file CommandHistory.cpp.

References m_redoAction, and m_undoAction.

◆ registerToolbar()

void CommandHistory::registerToolbar ( QToolBar *  toolbar)

Definition at line 121 of file CommandHistory.cpp.

References m_redoMenuAction, and m_undoMenuAction.

Referenced by ModelDataTableDialog::ModelDataTableDialog().

◆ addCommand() [1/2]

◆ addCommand() [2/2]

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().

◆ getUndoLimit()

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.

◆ setUndoLimit()

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.

◆ getRedoLimit()

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.

◆ setRedoLimit()

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.

◆ getMenuLimit()

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.

◆ setMenuLimit()

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().

◆ getBundleTimeout()

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.

◆ setBundleTimeout()

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.

◆ startCompoundOperation()

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().

◆ endCompoundOperation()

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().

◆ documentSaved

void CommandHistory::documentSaved ( )
virtualslot

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.

◆ addExecutedCommand

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().

◆ addCommandAndExecute

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().

◆ undo

◆ redo

void CommandHistory::redo ( )
slot

◆ undoActivated

void CommandHistory::undoActivated ( QAction *  action)
protectedslot

Definition at line 479 of file CommandHistory.cpp.

References m_actionCounts, and undo().

Referenced by CommandHistory().

◆ redoActivated

void CommandHistory::redoActivated ( QAction *  action)
protectedslot

Definition at line 488 of file CommandHistory.cpp.

References m_actionCounts, and redo().

Referenced by CommandHistory().

◆ bundleTimerTimeout

void CommandHistory::bundleTimerTimeout ( )
protectedslot

Definition at line 256 of file CommandHistory.cpp.

References closeBundle(), and m_currentBundle.

Referenced by addToBundle().

◆ commandExecuted [1/2]

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().

◆ commandExecuted [2/2]

void CommandHistory::commandExecuted ( Command *  )
signal

Emitted whenever a command has just been executed, whether by addCommand or redo.

◆ commandUnexecuted

void CommandHistory::commandUnexecuted ( Command *  )
signal

Emitted whenever a command has just been unexecuted, whether by addCommand or undo.

Referenced by undo().

◆ documentRestored

void CommandHistory::documentRestored ( )
signal

Emitted when the undo/redo stack has reached the same state at which the documentSaved slot was last called.

Referenced by redo(), and undo().

◆ activity

void CommandHistory::activity ( QString  )
signal

Emitted when some activity happened (for activity logging).

Referenced by addCommand(), closeBundle(), redo(), and undo().

◆ addToCompound()

void CommandHistory::addToCompound ( Command *  command,
bool  execute 
)
protected

Definition at line 266 of file CommandHistory.cpp.

References m_currentCompound.

Referenced by addCommand().

◆ addToBundle()

void CommandHistory::addToBundle ( Command *  command,
bool  execute 
)
protected

◆ closeBundle()

void CommandHistory::closeBundle ( )
protected

◆ updateActions()

void CommandHistory::updateActions ( )
protected

◆ clipCommands()

void CommandHistory::clipCommands ( )
protected

◆ clipStack()

void CommandHistory::clipStack ( CommandStack stack,
int  limit 
)
protected

Definition at line 438 of file CommandHistory.cpp.

References clearStack(), and m_undoLimit.

Referenced by clipCommands().

◆ clearStack()

void CommandHistory::clearStack ( CommandStack stack)
protected

Definition at line 465 of file CommandHistory.cpp.

Referenced by addCommand(), clear(), clipStack(), and ~CommandHistory().

Member Data Documentation

◆ m_instance

CommandHistory * CommandHistory::m_instance = 0
staticprotected

Definition at line 191 of file CommandHistory.h.

Referenced by getInstance().

◆ m_undoAction

QAction* CommandHistory::m_undoAction
protected

Definition at line 193 of file CommandHistory.h.

Referenced by CommandHistory(), registerMenu(), and updateActions().

◆ m_redoAction

QAction* CommandHistory::m_redoAction
protected

Definition at line 194 of file CommandHistory.h.

Referenced by CommandHistory(), registerMenu(), and updateActions().

◆ m_undoMenuAction

QAction* CommandHistory::m_undoMenuAction
protected

Definition at line 195 of file CommandHistory.h.

Referenced by CommandHistory(), registerToolbar(), and updateActions().

◆ m_redoMenuAction

QAction* CommandHistory::m_redoMenuAction
protected

Definition at line 196 of file CommandHistory.h.

Referenced by CommandHistory(), registerToolbar(), and updateActions().

◆ m_undoMenu

QMenu* CommandHistory::m_undoMenu
protected

Definition at line 197 of file CommandHistory.h.

Referenced by CommandHistory(), updateActions(), and ~CommandHistory().

◆ m_redoMenu

QMenu* CommandHistory::m_redoMenu
protected

Definition at line 198 of file CommandHistory.h.

Referenced by CommandHistory(), updateActions(), and ~CommandHistory().

◆ m_actionCounts

std::map<QAction *, int> CommandHistory::m_actionCounts
protected

Definition at line 200 of file CommandHistory.h.

Referenced by redoActivated(), undoActivated(), and updateActions().

◆ m_undoStack

CommandStack CommandHistory::m_undoStack
protected

◆ m_redoStack

CommandStack CommandHistory::m_redoStack
protected

◆ m_undoLimit

int CommandHistory::m_undoLimit
protected

Definition at line 206 of file CommandHistory.h.

Referenced by clipCommands(), clipStack(), getUndoLimit(), and setUndoLimit().

◆ m_redoLimit

int CommandHistory::m_redoLimit
protected

Definition at line 207 of file CommandHistory.h.

Referenced by clipCommands(), getRedoLimit(), and setRedoLimit().

◆ m_menuLimit

int CommandHistory::m_menuLimit
protected

Definition at line 208 of file CommandHistory.h.

Referenced by getMenuLimit(), setMenuLimit(), and updateActions().

◆ m_savedAt

int CommandHistory::m_savedAt
protected

◆ m_currentCompound

MacroCommand* CommandHistory::m_currentCompound
protected

◆ m_executeCompound

bool CommandHistory::m_executeCompound
protected

Definition at line 212 of file CommandHistory.h.

Referenced by addCommand(), and startCompoundOperation().

◆ m_currentBundle

MacroCommand* CommandHistory::m_currentBundle
protected

Definition at line 215 of file CommandHistory.h.

Referenced by addCommand(), addToBundle(), bundleTimerTimeout(), and closeBundle().

◆ m_bundling

bool CommandHistory::m_bundling
protected

Definition at line 216 of file CommandHistory.h.

Referenced by addCommand(), and addToBundle().

◆ m_currentBundleName

QString CommandHistory::m_currentBundleName
protected

Definition at line 217 of file CommandHistory.h.

Referenced by addToBundle(), and closeBundle().

◆ m_bundleTimer

QTimer* CommandHistory::m_bundleTimer
protected

Definition at line 218 of file CommandHistory.h.

Referenced by addToBundle().

◆ m_bundleTimeout

int CommandHistory::m_bundleTimeout
protected

Definition at line 219 of file CommandHistory.h.

Referenced by addToBundle(), getBundleTimeout(), and setBundleTimeout().


The documentation for this class was generated from the following files: