Class SBCUndoStack#
This class describes an undo stack.
#include <SBCUndoStack.hpp>
Public Functions#
| Type | Name |
|---|---|
| SBCUndoStack () Constructors and destructors. |
|
| void | beginHolding (const std::string & name) Begins holding. |
| void | beginUndoCommandGroup (const std::string & name) Begins a new command group to the current command group. |
| void | clear () Clears the stack. |
| void | connectUndoSignalToSlot (SBCReferenceTarget * observer, void(SBCReferenceTarget::*)(SBCUndoEvent *) functionPointer) Connects the undo signal to the slot of the observer. |
| void | disableHolding () Pauses holding. |
| void | disableUndoRedo () Disables undo and redo. |
| void | disconnectUndoSignalFromSlot (SBCReferenceTarget * observer, void(SBCReferenceTarget::*)(SBCUndoEvent *) functionPointer) Disconnects the undo signal to the slot of the observer. |
| void | enableHolding () Resumes holding. |
| void | enableUndoRedo () Enables undo and redo. |
| void | endHolding () Ends holding. |
| void | endUndoCommandGroup () Ends a new command group to the current command group. |
| SBCContainerVector< SBCUndoCommand * > * | getCommandVector () const Returns a vector of undo commands. |
| unsigned int | getDisablingUndoRedoCounter () Returns the counter for disabling undo and redo. |
| unsigned int | getNextRedoIndex () const Returns the next redo index. |
| void | hold (SBCUndoCommand * undoCommand) Adds a new command to the current command group. |
| void | hold (void * object) Holds an object allocated on the heap. |
| void | hold (SBPointerTarget * pointerTarget) Holds a pointer target allocated on the heap. |
| void | holdArray (void * array) Holds an array allocated on the heap. |
| bool | isHolding () const Storing commands. |
| bool | isRedoing () const Returns true while redoing. |
| bool | isUndoing () const Returns true while undoing. |
| virtual void | print (unsigned int offset=0) const Prints debugging information. |
| void | redo () Redo one command. |
| void | undo () Undo and redo. |
| bool | undoSignalIsConnectedToSlot (SBCReferenceTarget * observer, void(SBCReferenceTarget::*)(SBCUndoEvent *) functionPointer) const Returns whether the undo signal is connected to the slot of the observer. |
| virtual | ~SBCUndoStack () Destructor. |
Protected Attributes#
| Type | Name |
|---|---|
| SBCUndoStackData * | dataPointer A pointer to the private data. |
Public Functions Documentation#
function SBCUndoStack#
Constructors and destructors.
Constructs a new SBCUndoStack object.
Default constructor
The stack is initialized with an empty command history.
function beginHolding#
Begins holding.
Begins a holding block with the given name.
Commands added after this call will be grouped together until endHolding is called.
Parameters:
nameThe name of the holding block.
function beginUndoCommandGroup#
Begins a new command group to the current command group.
Begins a new undo command group within the current holding block.
The new group allows commands to be nested hierarchically.
Parameters:
nameThe name of the command group.
function clear#
Clears the stack.
Clears all commands from the undo stack.
All commands are deleted and the stack becomes empty.
function connectUndoSignalToSlot#
Connects the undo signal to the slot of the observer.
void SBCUndoStack::connectUndoSignalToSlot (
SBCReferenceTarget * observer,
void(SBCReferenceTarget::*)( SBCUndoEvent *) functionPointer
)
Connects the undo signal to a slot on a reference target.
This function registers the observer's slot to receive undo events, creating the signal object if it does not already exist.
Parameters:
referenceTargetThe object whose slot will receive undo events.functionPointerPointer to the member function to be called when an undo event occurs.
function disableHolding#
Pauses holding.
Disables holding temporarily.
Subsequent calls to beginHolding will have no effect until enableHolding is called.
function disableUndoRedo#
Disables undo and redo.
Increments the counter that disables undo and redo operations.
function disconnectUndoSignalFromSlot#
Disconnects the undo signal to the slot of the observer.
void SBCUndoStack::disconnectUndoSignalFromSlot (
SBCReferenceTarget * observer,
void(SBCReferenceTarget::*)( SBCUndoEvent *) functionPointer
)
Disconnects the undo signal from the specified slot of the observer.
This function unregisters the observer's slot so that it no longer receives undo events.
Parameters:
referenceTargetThe observer whose slot connection should be removed.functionPointerPointer to the observer's member function that receives the undo event.
function enableHolding#
Resumes holding.
Re-enables holding after it has been disabled.
Decrements the internal disabling counter, allowing holding to be resumed.
function enableUndoRedo#
Enables undo and redo.
Decrements the counter that disables undo and redo operations.
function endHolding#
Ends holding.
Ends the current holding block.
If any commands were recorded, they are added to the command history; otherwise the holding block is discarded.
function endUndoCommandGroup#
Ends a new command group to the current command group.
Ends the most recently started undo command group.
Restores the parent command group as the current context, effectively closing the most recent group.
function getCommandVector#
Returns a vector of undo commands.
Returns a pointer to the vector containing undo commands.
Returns:
Pointer to the command vector, or nullptr if the internal data is unavailable.
function getDisablingUndoRedoCounter#
Returns the counter for disabling undo and redo.
Returns the current counter value for disabling undo and redo.
Returns:
The disabling undo/redo counter.
function getNextRedoIndex#
Returns the next redo index.
Returns the index of the next command that will be redone.
Returns:
The next redo index, or 0 if the internal data is unavailable.
function hold [1/3]#
Adds a new command to the current command group.
Adds an undo command to the current holding block.
The command is added as a child of the current command group, transferring ownership to the stack.
Parameters:
undoCommandPointer to the command to be held. Ownership is transferred to the stack.
function hold [2/3]#
Holds an object allocated on the heap.
Holds a raw object on the heap.
The object will be deleted when the command is destroyed.
Parameters:
objectPointer to the object to hold.
function hold [3/3]#
Holds a pointer target allocated on the heap.
The pointer target will be released when the command is destroyed.
Parameters:
pointerTargetPointer to the target to hold.
function holdArray#
Holds an array allocated on the heap.
The array will be deleted when the command is destroyed.
Parameters:
arrayPointer to the array to hold.
function isHolding#
Storing commands.
Checks whether the stack is currently holding commands.
Returns true while holding
Returns:
true if holding is active and not disabled; otherwise false.
function isRedoing#
Returns true while redoing.
Returns whether a redo operation is currently in progress.
Returns:
true if redoing; otherwise false.
function isUndoing#
Returns true while undoing.
Returns whether an undo operation is currently in progress.
Returns:
true if undoing; otherwise false.
function print#
Prints debugging information.
Prints debugging information about the undo stack.
This function outputs the contents of the undo stack to standard output, indicating which commands are undoable and which are redoable, using the provided indentation level.
Parameters:
offsetThe indentation level (in tabs) for the printed output.
function redo#
Redo one command.
Performs a redo operation on the next command, if possible.
This function verifies that redo can be performed, updates the internal state, invokes the redo operation on the next command, and emits an undo signal.
function undo#
Undo and redo.
Performs an undo operation on the most recent command, if possible.
Undo one command
This function checks whether undo can be performed, updates the internal state, invokes the undo operation on the current command, and emits an undo signal.
function undoSignalIsConnectedToSlot#
Returns whether the undo signal is connected to the slot of the observer.
bool SBCUndoStack::undoSignalIsConnectedToSlot (
SBCReferenceTarget * observer,
void(SBCReferenceTarget::*)( SBCUndoEvent *) functionPointer
) const
Checks whether the undo signal is connected to the specified slot of the observer.
This function returns true if the given observer's slot is currently registered to receive undo events.
Parameters:
referenceTargetThe observer whose slot connection is being queried.functionPointerPointer to the observer's member function that receives the undo event.
Returns:
true if the undo signal is connected to the slot; otherwise false.
function ~SBCUndoStack#
Destructor.
Destroys the SBCUndoStack and releases its resources.
All held commands are cleared and the internal data is deleted.
Protected Attributes Documentation#
variable dataPointer#
A pointer to the private data.