mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-14 10:34:14 +02:00
Cover auto-numbering counter changes with undo/redo
Placing an auto-numbered element or conductor advances a shared NumerotationContext counter (QETProject::addConductorAutoNum/ addElementAutoNum) as a side effect that sat entirely outside the undo stack. Undoing the placement removed the visible number but left the counter advanced, so every undo of an auto-numbered placement silently burned a number, with no way to get it back short of a manual reset. Adds SetAutoNumContextCommand, a small QUndoCommand storing the old/new NumerotationContext and calling the matching add*AutoNum() setter on undo()/redo() -- the same shape QPropertyUndoCommand already uses next to it in ConductorAutoNumerotation::applyText(). Wires it into the two conductor call sites (the static newProperties(), and numerateNewConductor(), both in ConductorAutoNumerotation) and the element call site (Element::setUpFormula(), called from DiagramEventAddElement::addElement() when a new element is dropped onto a diagram). setUpFormula() now takes an optional parent QUndoCommand; addElement() calls it before pushing its own undo_object so the counter change lands in the same undo macro as the element's placement -- one Ctrl+Z reverts both together, instead of leaving the counter adrift. The project-properties config dialog's own add*AutoNum() calls (editing the numbering rule itself, not a side effect of placing something) are deliberately left untouched, as are the load-time folio-sequential bookkeeping calls in Diagram::loadElmtFolioSeq()/loadCndFolioSeq() and the bulk folio-renumbering passes in QETProject -- none of those run as part of an undoable user gesture. Implements the scope proposed in discussion #608.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "qet.h"
|
||||
#include "qetdiagrameditor.h"
|
||||
#include "ui/potentialselectordialog.h"
|
||||
#include "undocommand/setautonumcontextcommand.h"
|
||||
|
||||
/**
|
||||
@brief ConductorAutoNumerotation::ConductorAutoNumerotation
|
||||
@@ -156,7 +157,16 @@ void ConductorAutoNumerotation::newProperties(
|
||||
autonum::setSequential(formula, seq, context, diagram, autoNum_name);
|
||||
|
||||
NumerotationContextCommands ncc (context, diagram);
|
||||
diagram->project()->addConductorAutoNum(autoNum_name, ncc.next());
|
||||
NumerotationContext new_context = ncc.next();
|
||||
|
||||
QETProject *project = diagram->project();
|
||||
auto *undo = new SetAutoNumContextCommand(
|
||||
[project](const QString &k, const NumerotationContext &c) {project->addConductorAutoNum(k, c);},
|
||||
autoNum_name,
|
||||
context,
|
||||
new_context);
|
||||
undo->setText(QObject::tr("Numéroter automatiquement un conducteur", "undo caption"));
|
||||
diagram->undoStack().push(undo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +255,21 @@ void ConductorAutoNumerotation::numerateNewConductor()
|
||||
autoNum_name);
|
||||
|
||||
NumerotationContextCommands ncc (context, m_diagram);
|
||||
m_diagram->project()->addConductorAutoNum(autoNum_name, ncc.next());
|
||||
NumerotationContext new_context = ncc.next();
|
||||
|
||||
QETProject *project = m_diagram->project();
|
||||
auto setter = [project](const QString &k, const NumerotationContext &c) {project->addConductorAutoNum(k, c);};
|
||||
|
||||
if (m_parent_undo)
|
||||
{
|
||||
new SetAutoNumContextCommand(setter, autoNum_name, context, new_context, m_parent_undo);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto *undo = new SetAutoNumContextCommand(setter, autoNum_name, context, new_context);
|
||||
undo->setText(QObject::tr("Numéroter automatiquement un conducteur", "undo caption"));
|
||||
m_diagram->undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
applyText(autonum::AssignVariables::formulaToLabel(
|
||||
|
||||
Reference in New Issue
Block a user