Terminal strip editor: add spare terminals, numbered, counted in the nomenclature

A spare (reserved) terminal is a terminal of a strip which is drawn on no
folio. RealTerminal already foresaw it ("a terminal set by user but not
present on any folio") but every terminal needed an element.

- RealTerminal::createSpare(): a terminal without element, with its own
  data (label, type, function, led, informations: section, width, catalog
  terminal, color, manufacturer...). Saved in the strip:
  <real_terminal spare_uuid="..." type="..." function="..."><informations>
  Older versions ignore these terminals.
- TerminalStrip::insertSpareTerminals() / insertTerminals(): insert at a
  position of the strip. Undoable commands AddSpareTerminalsCommand and
  ChangeSpareTerminalDataCommand.
- Terminal strip editor: "Add spare terminals..." button. The terminals
  are inserted after the selected terminal (at the end if none), numbered
  from its label ("X1:12" -> "X1:13", "X1:14", leading zeros kept), with
  its properties if asked. The labels can be changed or removed in the
  table, like the other cells; the Xref column shows "Spare". Moving a
  spare terminal to the independent terminals removes it (undoable).
- Nomenclature: the spare terminals are in the new spare_terminal table,
  added to element_nomenclature_view (UNION ALL, same columns), after the
  folios, in the order of their strip. exclude_from_bom is honoured.
- The modified cells of the editor model are kept by real terminal, not by
  element, since a spare terminal has none.
This commit is contained in:
Laurent Trinques
2026-10-18 16:24:14 +02:00
parent ddc71553e2
commit 015811d243
16 changed files with 747 additions and 70 deletions
@@ -19,6 +19,7 @@
#include "../../qetgraphicsitem/terminalelement.h"
#include "../realterminal.h"
#include "../physicalterminal.h"
#include "../terminalstrip.h"
/**
* @brief AddTerminalToStripCommand::AddTerminalToStripCommand
@@ -234,3 +235,72 @@ void MoveTerminalCommand::redo()
m_new_strip->addTerminals(m_terminal);
}
}
/**
* @brief AddSpareTerminalsCommand::AddSpareTerminalsCommand
* @param strip : the strip where the spare terminals are inserted
* @param pos : position of the first spare terminal in the strip,
* -1 to add them at the end of the strip
* @param spare_terminals : spare terminals made by RealTerminal::createSpare()
* @param parent : parent undo command
*/
AddSpareTerminalsCommand::AddSpareTerminalsCommand(TerminalStrip *strip, int pos,
const QVector<QSharedPointer<RealTerminal>> &spare_terminals,
QUndoCommand *parent) :
QUndoCommand{parent},
m_strip{strip},
m_pos{pos},
m_spare_terminals{spare_terminals}
{
const auto count = spare_terminals.size();
const auto strip_name = strip ? strip->name() : QString();
setText(strip_name.isEmpty()
? QObject::tr("Add %n spare terminals", "", count)
: QObject::tr("Add %n spare terminals to terminal group %1", "", count).arg(strip_name));
}
void AddSpareTerminalsCommand::undo()
{
if (m_strip) {
m_strip->removeTerminals(m_physical_terminals);
}
}
void AddSpareTerminalsCommand::redo()
{
if (!m_strip) {
return;
}
//The first time the physical terminals are made,
//after an undo the same ones are inserted again
if (m_physical_terminals.isEmpty()) {
m_physical_terminals = m_strip->insertSpareTerminals(m_pos, m_spare_terminals);
} else {
m_strip->insertTerminals(m_pos, m_physical_terminals);
}
}
/**
* @brief ChangeSpareTerminalDataCommand::ChangeSpareTerminalDataCommand
* @param spare_terminal : the spare terminal to change
* @param new_data : the new data of the terminal
* @param parent : parent undo command
*/
ChangeSpareTerminalDataCommand::ChangeSpareTerminalDataCommand(const QSharedPointer<RealTerminal> &spare_terminal,
const ElementData &new_data,
QUndoCommand *parent) :
QUndoCommand{parent},
m_spare_terminal{spare_terminal},
m_old_data{spare_terminal->spareData()},
m_new_data{new_data}
{
setText(QObject::tr("Modify the spare terminal %1").arg(spare_terminal->label()));
}
void ChangeSpareTerminalDataCommand::undo() {
m_spare_terminal->setSpareData(m_old_data);
}
void ChangeSpareTerminalDataCommand::redo() {
m_spare_terminal->setSpareData(m_new_data);
}