Skip to content

BUG: Fix MRML scene undo/redo mechanism

Andras Lasso requested to merge github/fork/lassoan/undo-redo-fixes into master

MRML scene undo/redo mechanism has been disabled for a long time and this commit keeps it that way. However, this commit contain a number of fixes for problems that initial testing of the undo/redo mechanism revealed. While the undo/redo infrastructure is still not ready for general use, these fixes allow enabling it for selected nodes in custom applications.

  • Add flag to enable/disable undo/redo tracking for nodes. This allows enabling undo/redo only for selected nodes, that are implemented carefully to work well with undo/redo.
  • Enforce maximum stack size on undo and redo stacks.
  • Node IDs that are referenced within the node stack and are not within the scene are considered to be in use for the purpose of generating unique node ids (this makes sure no node ID conflicts can occur between new nodes and nodes that were restored from the undo stack).
  • Add missing SaveStateForUndo calls into Markups widgets.
  • Always save the full scene state - saving only state of selected nodes can break node references and make the state of the scene inconsistent. Even if a Slice core module would think that as a result of a user action only specific nodes are updated, due to behavior of custom modules, it is possible that a simple node change triggers events that change state of other nodes, which would not be possible to revert without saving the state of all nodes.
  • Add flag to be able to disable automatic display node creation for Markups.
  • Removed SaveStateForUndo calls from logic and MRML classes. Undo/Redo should be handled at the application/GUI level and not at MRML library level (at the library level it is not known when is a good time to save a new state).

Co-authored-by: Kyle Sunderland sunderlandkyl@gmail.com

Merge request reports

Loading