mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-03 10:34:14 +02:00
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:
+36
-10
@@ -34,6 +34,7 @@
|
||||
#include "TerminalStrip/terminalstrip.h"
|
||||
#include "qetxml.h"
|
||||
#include "qetversion.h"
|
||||
#include "undocommand/adddiagramcommand.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QHash>
|
||||
@@ -1348,6 +1349,8 @@ bool QETProject::usesTitleBlockTemplate(const TitleBlockTemplateLocation &locati
|
||||
/**
|
||||
@brief QETProject::addNewDiagram
|
||||
Add a new diagram in project at position pos.
|
||||
This is pushed as an undoable AddDiagramCommand: use undoStack()->undo()
|
||||
to remove it again.
|
||||
@param pos
|
||||
@return the new created diagram
|
||||
*/
|
||||
@@ -1363,14 +1366,15 @@ Diagram *QETProject::addNewDiagram(int pos)
|
||||
diagram->border_and_titleblock.importTitleBlock(defaultTitleBlockProperties());
|
||||
diagram->defaultConductorProperties = defaultConductorProperties();
|
||||
|
||||
addDiagram(diagram, pos);
|
||||
emit diagramAdded(this, diagram);
|
||||
m_undo_stack->push(new AddDiagramCommand(this, diagram, pos));
|
||||
return(diagram);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::removeDiagram
|
||||
Remove diagram from project
|
||||
Remove diagram from project immediately (not undoable). UI code should
|
||||
generally go through ProjectView::removeDiagram() instead, which pushes
|
||||
an undoable RemoveDiagramCommand.
|
||||
@param diagram
|
||||
*/
|
||||
void QETProject::removeDiagram(Diagram *diagram)
|
||||
@@ -1380,13 +1384,8 @@ void QETProject::removeDiagram(Diagram *diagram)
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_diagrams_list.removeAll(diagram))
|
||||
{
|
||||
emit diagramRemoved(this, diagram);
|
||||
diagram->deleteLater();
|
||||
}
|
||||
|
||||
updateDiagramsFolioData();
|
||||
detachDiagram(diagram);
|
||||
diagram->deleteLater();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1930,6 +1929,33 @@ void QETProject::addDiagram(Diagram *diagram, int pos)
|
||||
}
|
||||
|
||||
updateDiagramsFolioData();
|
||||
emit diagramAdded(this, diagram);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::detachDiagram
|
||||
Inverse of addDiagram(): removes \p diagram from this project's diagram
|
||||
list and disconnects the signals set up by addDiagram(), without
|
||||
destroying it. Used by RemoveDiagramCommand (and removeDiagram()) so a
|
||||
removed diagram can be parked and later reinserted by undo.
|
||||
@param diagram
|
||||
*/
|
||||
void QETProject::detachDiagram(Diagram *diagram)
|
||||
{
|
||||
if (!diagram || !m_diagrams_list.contains(diagram)) {
|
||||
return;
|
||||
}
|
||||
|
||||
disconnect(&diagram->border_and_titleblock,
|
||||
&BorderTitleBlock::needFolioData,
|
||||
this,
|
||||
&QETProject::updateDiagramsFolioData);
|
||||
disconnect(diagram, &Diagram::usedTitleBlockTemplateChanged,
|
||||
this, &QETProject::usedTitleBlockTemplateChanged);
|
||||
|
||||
m_diagrams_list.removeAll(diagram);
|
||||
updateDiagramsFolioData();
|
||||
emit diagramRemoved(this, diagram);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user