Terminal strip editor: cable cells worked out from the project cables

The Cable and Color / wire number columns now show what the cables of
the project say (designation and core colour or number), worked out
from the conductors wired to the terminal, instead of only the values
typed in by hand (patch by Laurent);

Values typed in by hand are still shown, and the cells still editable,
when no cable of the project is wired to the terminal;

A value worked out from a cable is never written back into the element,
so a cable renamed or removed cannot leave a stale value behind.
This commit is contained in:
Kellermorph
2026-10-19 18:40:56 +02:00
parent a12fb43bcb
commit 9e37fa2ca7
5 changed files with 95 additions and 5 deletions
+80 -2
View File
@@ -23,6 +23,50 @@
#include "terminalcatalog.h"
#include "../qetgraphicsitem/conductor.h"
#include "../qetinformation.h"
#include "../qetgraphicsitem/terminal.h"
#include "../diagram.h"
#include "../cable/cable.h"
#include "../cable/cablemanager.h"
namespace
{
/**
* The cable cores wired to one terminal element, worked out from
* the cables of the project (PR #1438). A core knows its
* conductor, and CableManager::refreshLabels() writes the cable
* and the core into the properties of that conductor, so reading
* the conductors of the element is enough.
* Each pair is (cable designation, core colour or number).
*/
QList<QPair<QString, QString>> wiredCores(Element *element)
{
QList<QPair<QString, QString>> cores;
if (!element || !element->diagram()) {
return cores;
}
const auto project = element->diagram()->project();
for (const auto terminal : element->terminals())
{
for (const auto conductor : terminal->conductors())
{
const auto properties = conductor->ownProperties();
const auto cable = CableManager::cableByUuid(project, properties.m_cable_uuid);
if (!cable || cable->designation().isEmpty()) {
continue;
}
auto wire = cable->colorOfCore(properties.m_cable_slot);
if (wire.isEmpty() && properties.m_cable_slot >= 0) {
wire = QString::number(properties.m_cable_slot + 1);
}
const QPair<QString, QString> core(cable->designation(), wire);
if (!cores.contains(core)) {
cores.append(core);
}
}
}
return cores;
}
}
/**
* @brief RealTerminal
@@ -291,18 +335,52 @@ QString RealTerminal::Xref() const
* @return The name of the cable (hose) connected to this terminal.
* The value is stored in the informations of the element.
*/
QString RealTerminal::cable() const {
QString RealTerminal::cable() const
{
const auto cores = wiredCores(m_element.data());
if (!cores.isEmpty())
{
QStringList cables;
for (const auto &core : cores) {
if (!cables.contains(core.first)) {
cables.append(core.first);
}
}
return cables.join(QStringLiteral(", "));
}
if (hasData()) {
return terminalData().m_informations.value(cableInfoKey()).toString();
}
return QString();
}
/**
* @brief RealTerminal::cableIsAutomatic
* @return true when the cable and the core of this terminal come from
* a cable of the project wired to it, false when they are the values
* typed in by the user in the terminal strip editor.
*/
bool RealTerminal::cableIsAutomatic() const {
return !wiredCores(m_element.data()).isEmpty();
}
/**
* @brief RealTerminal::cableWire
* @return The color / number of the wire of the cable, connected to this terminal.
*/
QString RealTerminal::cableWire() const {
QString RealTerminal::cableWire() const
{
const auto cores = wiredCores(m_element.data());
if (!cores.isEmpty())
{
QStringList wires;
for (const auto &core : cores) {
wires.append(core.second);
}
return wires.join(QStringLiteral(", "));
}
if (hasData()) {
return terminalData().m_informations.value(cableWireInfoKey()).toString();
}
+1
View File
@@ -73,6 +73,7 @@ class RealTerminal
QString Xref() const;
QString cable() const;
QString cableWire() const;
bool cableIsAutomatic() const;
bool isShield() const;
QColor color() const;
QColor stripeColor() const;
@@ -35,6 +35,7 @@ struct modelRealTerminalData
mrtd.Xref_ = real_t->Xref();
mrtd.cable_ = real_t->cable();
mrtd.cable_wire = real_t->cableWire();
mrtd.cable_auto_ = real_t->cableIsAutomatic();
mrtd.conductor_ = real_t->conductor();
mrtd.led_ = real_t->isLed();
mrtd.shield_ = real_t->isShield();
@@ -60,6 +61,7 @@ struct modelRealTerminalData
QString Xref_;
QString cable_;
QString cable_wire;
bool cable_auto_ = false; //True when cable_ and cable_wire come from the cables of the project
QString conductor_;
bool led_ = false;
bool shield_ = false;
@@ -245,8 +245,13 @@ void TerminalStripEditor::apply()
current_data.m_informations.addValue(key, value);
}
};
set_info(RealTerminal::cableInfoKey(), data_.cable_);
set_info(RealTerminal::cableWireInfoKey(), data_.cable_wire);
//A cable worked out from the cables of the project is
//never written in the element: it would stay there,
//out of date, once the cable is renamed or removed
if (!data_.cable_auto_) {
set_info(RealTerminal::cableInfoKey(), data_.cable_);
set_info(RealTerminal::cableWireInfoKey(), data_.cable_wire);
}
set_info(RealTerminal::shieldInfoKey(), data_.shield_ ? QStringLiteral("true") : QString());
//The color and the section are stored with the dot as decimal separator, whatever the locale
set_info(RealTerminal::colorInfoKey(), TerminalColor::toSpec(data_.color_, data_.stripe_color_));
@@ -497,8 +497,12 @@ Qt::ItemFlags TerminalStripModel::flags(const QModelIndex &index) const
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
auto c = index.column();
//The cable cells are only edited by hand when no cable
//of the project is wired to the terminal
if ((c == CABLE_CELL || c == CABLE_WIRE_CELL)
&& !dataAtRow(index.row()).cable_auto_)
flags = flags | Qt::ItemIsEditable;
if (c == LABEL_CELL || c == TYPE_CELL || c == FUNCTION_CELL
|| c == CABLE_CELL || c == CABLE_WIRE_CELL
|| c == COLOR_CELL || c == SECTION_CELL || c == WIDTH_CELL)
flags = flags | Qt::ItemIsEditable;
if (c == LED_CELL || c == SHIELD_CELL || c == SEPARATOR_CELL) {