Add undo/redo support for folio add, delete, and reorder (#575)

Three new QUndoCommand subclasses (AddDiagramCommand, RemoveDiagramCommand,
MoveDiagramCommand) pushed onto the project's existing (already
project-scoped) undo stack, so folio structure edits are undoable
alongside every item-level edit already on that stack.

- QETProject::addDiagram()/detachDiagram() are the shared attach/detach
  primitives: they mutate the diagram list, connect/disconnect the two
  per-diagram signals set up at add time, and emit diagramAdded/
  diagramRemoved. AddDiagramCommand and RemoveDiagramCommand call these
  (via friend access) for both redo and undo, so a removed diagram is
  parked rather than destroyed -- it's only actually deleted if the
  command itself falls out of undo history while still detached.
- ProjectView reacts to diagramRemoved the same way it already reacted to
  diagramAdded (tearing down/rebuilding the tab), so both directions of
  both commands go through the same reactive path every other diagram
  listener (project database, cross-references, generic panel) already
  relies on.
- MoveDiagramCommand wraps a new ProjectView::setDiagramPosition(), which
  performs the tab move and the project's diagramOrderChanged() list
  reorder synchronously in one step, instead of relying on the queued
  tabMoved connection (needed for interactive drag-and-drop) to catch up
  later -- avoiding a second, redundant reorder from that queued call.
- Multi-folio delete and multi-folio move (QETDiagramEditor::removeDiagrams()
  and the moveDiagram*(QList<Diagram*>) batch slots) wrap their per-diagram
  loop in QUndoStack::beginMacro()/endMacro(), so a multi-select action is
  one undo step, matching current UX.
- Softened the delete confirmation's "this change is irreversible" wording
  now that it no longer is.

Verified headlessly (Xvfb + xdotool + scrot): add/undo/redo, delete/undo/
redo (single and multi-select, single undo step for the batch), and
move/undo/redo all behave correctly against a 7-folio project.
This commit is contained in:
ispyisail
2026-08-01 17:03:39 +12:00
parent c772e1d3ea
commit 55886e5e8a
12 changed files with 499 additions and 25 deletions
+2
View File
@@ -102,6 +102,7 @@ class ProjectView : public QWidget
void changeTabDown();
void changeFirstTab();
void changeLastTab();
void setDiagramPosition(Diagram *diagram, int new_position);
public slots:
void removeDiagram(DiagramView *diagram_view, bool silent = false);
@@ -168,6 +169,7 @@ class ProjectView : public QWidget
void setDisplayFallbackWidget(bool);
void adjustReadOnlyState();
void diagramAdded(Diagram *diagram);
void diagramRemoved(Diagram *diagram);
// attributes
private: