Workspace 6.21.5
Public Member Functions | Static Public Member Functions | List of all members
WorkspaceUndoGroup Class Reference

Provides an undo stack for each workspace. More...

#include <Workspace/Presentation/workspaceundogroup.h>

Inherits QUndoGroup.

Public Member Functions

 ~WorkspaceUndoGroup () override
 

Static Public Member Functions

static WorkspaceUndoGroupgetInstance ()
 
static QUndoStack & getUndoStack (DataExecution::Updatable &updatable)
 

Detailed Description

This class acts as a central place for managing undo stacks for Workspace objects. Clients call getUndoStack() to retrieve the undo stack appropriate for a particular Workspace, Operation, input or output. Nested workspaces share the undo stack with its parent all the way up to the root workspace. The undo stack for an operation that is not a Workspace is simply the undo stack for the Workspace that contains it. Similarly, the undo stack for an input or output is the undo stack for the operation that holds it.

Note
This class assumes that operations, inputs and outputs are not used in isolation. Rather, all operations must be contained in a Workspace and all inputs/outputs must be part of an operation. Only the root Workspace is allowed to effectively have nothing containing it.

Constructor & Destructor Documentation

◆ ~WorkspaceUndoGroup()

~WorkspaceUndoGroup ( )
override

Cleans up the Singleton instance.

Member Function Documentation

◆ getInstance()

WorkspaceUndoGroup & getInstance ( )
static
Returns
The singleton instance of this undo group.

◆ getUndoStack()

QUndoStack & getUndoStack ( DataExecution::Updatable updatable)
static
Parameters
updatableThe updatable object for which an undo stack is required.
Precondition
The result of updatable.getRootWorkspace() must not be a null pointer. What this generally means is that the updatable object must be an operation that is contained in a Workspace or be owned by such an operation, or it must be the root Workspace itself. If the updatable object is a connection, then the operations at each end of the connection must both be containined in the same Workspace.

If updatable is in a nested workspace (ie it has a parent workspace), this function recurses up the parent hierarchy until the top level workspace is found. The undo stack of the top level workspace is therefore always the one that determines the undo stack to use. One consequence of this is that getUndoStack() should never be called on an object which will have its workspace parent structure changed. In practice, this is generally not done anyway, so this should not be a huge restriction. A good practice is to create the workspace structure first before creating anything which might try to create undoable events on them. If a workspace is going to be reparented, then at the very least, the undo stack should be cleared first so that when the workspace is reparented, the previous undo stack will have no contents and can just lay around until the workspace is deleted. Once an operation is added to a Workspace it should never be removed except to delete it. Similarly, once an input or output is added to an operation (which happens upon creation), client code should never try to move it or remove it except when deleting that input/output.

Returns
The undo stack associated with the top level workspace under which updatable ultimately sits.