mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-13 18:14:13 +02:00
2e0fe44174
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.
53 lines
1.6 KiB
C++
53 lines
1.6 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include "setautonumcontextcommand.h"
|
|
|
|
#include <utility>
|
|
|
|
/**
|
|
@brief SetAutoNumContextCommand::SetAutoNumContextCommand
|
|
@param setter the QETProject setter to call on undo/redo
|
|
(addConductorAutoNum/addElementAutoNum/addFolioAutoNum, bound to a project)
|
|
@param key the numerotation context's name/key
|
|
@param old_context the context's value before this placement
|
|
@param new_context the context's value after this placement
|
|
@param parent parent undo command
|
|
*/
|
|
SetAutoNumContextCommand::SetAutoNumContextCommand(
|
|
Setter setter,
|
|
const QString &key,
|
|
const NumerotationContext &old_context,
|
|
const NumerotationContext &new_context,
|
|
QUndoCommand *parent) :
|
|
QUndoCommand(parent),
|
|
m_setter(std::move(setter)),
|
|
m_key(key),
|
|
m_old_context(old_context),
|
|
m_new_context(new_context)
|
|
{}
|
|
|
|
void SetAutoNumContextCommand::redo()
|
|
{
|
|
m_setter(m_key, m_new_context);
|
|
}
|
|
|
|
void SetAutoNumContextCommand::undo()
|
|
{
|
|
m_setter(m_key, m_old_context);
|
|
}
|