From 10bf0411bb40fd38fbe7c1440a7a41101d93c0e2 Mon Sep 17 00:00:00 2001 From: Levi Jetzer Date: Wed, 2 Sep 2026 18:24:47 +0200 Subject: [PATCH] Add "Potentiel" field to the terminal editor (element editor) New QLineEdit (m_potential_le) between Type and Nom: an optional, symbol-author-chosen grouping identifier shared by terminals that belong to the same physical terminal within a multi-terminal block. Stored as TerminalData::m_potential (new field, persisted as the "potential" XML attribute, empty by default). Used by relatedPotentialTerminal() in terminal.cpp: when potential_isolating is enabled on a Terminal-type element, terminals sharing a non-empty, matching potential value now stay electrically linked to each other instead of every terminal in the block being isolated from every other one. Tooltip on the field for explanation --- sources/editor/graphicspart/partterminal.cpp | 9 ++++++ sources/editor/graphicspart/partterminal.h | 5 ++++ sources/editor/ui/terminaleditor.cpp | 22 ++++++++++++++ sources/editor/ui/terminaleditor.h | 15 +++++----- sources/editor/ui/terminaleditor.ui | 22 +++++++++++--- sources/properties/terminaldata.cpp | 5 ++++ sources/properties/terminaldata.h | 12 ++++++++ sources/qetgraphicsitem/terminal.cpp | 30 ++++++++++++++++++-- sources/qetgraphicsitem/terminal.h | 1 + 9 files changed, 108 insertions(+), 13 deletions(-) diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 194ae0aec..1516d804c 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -476,6 +476,15 @@ void PartTerminal::setMasterLabelIndex(int index) emit masterLabelIndexChanged(); } +void PartTerminal::setPotential(const QString &potential) +{ + if (d->m_potential == potential) return; + prepareGeometryChange(); + d->m_potential = potential; + update(); + emit potentialChanged(); +} + /** Updates the position of the second point according to the position and orientation of the terminal. diff --git a/sources/editor/graphicspart/partterminal.h b/sources/editor/graphicspart/partterminal.h index d0ba05da9..c1aec6de4 100644 --- a/sources/editor/graphicspart/partterminal.h +++ b/sources/editor/graphicspart/partterminal.h @@ -44,6 +44,7 @@ class PartTerminal : public CustomElementGraphicPart Q_PROPERTY(QColor label_color READ labelColor WRITE setLabelColor) Q_PROPERTY(bool use_master_label READ useMasterLabel WRITE setUseMasterLabel) Q_PROPERTY(int master_label_index READ masterLabelIndex WRITE setMasterLabelIndex) + Q_PROPERTY(QString potential READ potential WRITE setPotential) public: // constructors, destructor @@ -56,6 +57,7 @@ class PartTerminal : public CustomElementGraphicPart void orientationChanged(); void nameChanged(); void terminalTypeChanged(); + void potentialChanged(); void showNameChanged(); void labelPosChanged(); void labelFontChanged(); @@ -140,6 +142,9 @@ class PartTerminal : public CustomElementGraphicPart int masterLabelIndex() const { return d->m_master_label_index; } void setMasterLabelIndex(int index); + QString potential() const { return d->m_potential; } + void setPotential(const QString &potential); + void setNewUuid(); QRectF labelRect() const; diff --git a/sources/editor/ui/terminaleditor.cpp b/sources/editor/ui/terminaleditor.cpp index f3d23b7d9..c2097853b 100644 --- a/sources/editor/ui/terminaleditor.cpp +++ b/sources/editor/ui/terminaleditor.cpp @@ -84,6 +84,7 @@ void TerminalEditor::updateForm() ui->m_orientation_cb->setCurrentIndex(ui->m_orientation_cb->findData(m_part->property("orientation"))); ui->m_name_le->setText(m_part->terminalName()); ui->m_type_cb->setCurrentIndex(ui->m_type_cb->findData(m_part->terminalType())); + ui->m_potential_le->setText(m_part->potential()); ui->m_show_name_cb->setChecked(m_part->showName()); ui->m_label_x_dsb->setValue(m_part->labelPos().x()); @@ -263,6 +264,24 @@ void TerminalEditor::nameEdited() m_locked=false; } +void TerminalEditor::potentialEdited() +{ + if (m_locked) { + return; + } + + m_locked = true; + QString potential_(ui->m_potential_le->text()); + + if (m_part->potential() != potential_) + { + auto undo = new QPropertyUndoCommand(m_part, "potential", m_part->property("potential"), potential_); + undo->setText(tr("Modifier le potentiel d'une borne")); + undoStack().push(undo); + } + m_locked = false; +} + /** * @brief TerminalEditor::typeEdited */ @@ -457,6 +476,8 @@ void TerminalEditor::activeConnections(bool active) this, &TerminalEditor::labelAlignClicked); m_editor_connections << connect(ui->m_label_frame_cb, &QCheckBox::toggled, this, &TerminalEditor::labelFrameEdited); + m_editor_connections << connect(ui->m_potential_le, &QLineEdit::editingFinished, + this, &TerminalEditor::potentialEdited); m_editor_connections << connect(ui->m_use_master_label_cb, &QCheckBox::toggled, this, &TerminalEditor::useMasterLabelEdited); m_editor_connections << connect(ui->m_master_label_cb, QOverload::of(&QComboBox::activated), @@ -486,6 +507,7 @@ void TerminalEditor::activeChangeConnections(bool active) m_change_connections << connect(m_part, &PartTerminal::labelVAlignmentChanged, this, &TerminalEditor::updateForm); m_change_connections << connect(m_part, &PartTerminal::labelFrameChanged, this, &TerminalEditor::updateForm); m_change_connections << connect(m_part, &PartTerminal::labelColorChanged, this, &TerminalEditor::updateForm); + m_change_connections << connect(m_part, &PartTerminal::potentialChanged, this, &TerminalEditor::updateForm); m_change_connections << connect(m_part, &PartTerminal::useMasterLabelChanged, this, &TerminalEditor::updateForm); m_change_connections << connect(m_part, &PartTerminal::masterLabelIndexChanged, this, &TerminalEditor::updateForm); } else { diff --git a/sources/editor/ui/terminaleditor.h b/sources/editor/ui/terminaleditor.h index 7c15d9f2c..5b2d9a83e 100644 --- a/sources/editor/ui/terminaleditor.h +++ b/sources/editor/ui/terminaleditor.h @@ -58,19 +58,20 @@ class TerminalEditor : public ElementItemEditor void orientationEdited(); void nameEdited(); void typeEdited(); + void potentialEdited(); void showNameEdited(); void labelPosEdited(); void labelFontClicked(); void labelSizeEdited(); void labelRotationEdited(); void labelAlignClicked(); - void labelFrameEdited(); - void labelColorClicked(); - void activeConnections(bool active); - void activeChangeConnections(bool active); - void useMasterLabelEdited(); - void masterLabelIndexEdited(); - bool updateMasterLabelVisibility(); + void labelFrameEdited(); + void labelColorClicked(); + void activeConnections(bool active); + void activeChangeConnections(bool active); + void useMasterLabelEdited(); + void masterLabelIndexEdited(); + bool updateMasterLabelVisibility(); private: Ui::TerminalEditor *ui; diff --git a/sources/editor/ui/terminaleditor.ui b/sources/editor/ui/terminaleditor.ui index 6dc2388cb..33eb50047 100644 --- a/sources/editor/ui/terminaleditor.ui +++ b/sources/editor/ui/terminaleditor.ui @@ -48,7 +48,7 @@ - + @@ -61,7 +61,7 @@ - + Nom : @@ -78,7 +78,21 @@ - + + + + Potentiel: + + + + + + + Sans effet si "Isolation du potentiel" n'est pas cochée (toutes les bornes du bloc restent alors reliées). Si elle est cochée : les bornes partageant la même valeur restent reliées entre elles, les autres sont isolées. + + + + Nom de la borne @@ -214,7 +228,7 @@ - + Étiquette du maître diff --git a/sources/properties/terminaldata.cpp b/sources/properties/terminaldata.cpp index 1805ba3c9..f8a371107 100644 --- a/sources/properties/terminaldata.cpp +++ b/sources/properties/terminaldata.cpp @@ -129,6 +129,9 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const xml_element.setAttribute("label_color", m_label_color.name()); } + if (!m_potential.isEmpty()) + xml_element.setAttribute("potential", m_potential); + // Save master label override settings if (m_use_master_label) { xml_element.setAttribute("use_master_label", "true"); @@ -207,6 +210,8 @@ bool TerminalData::fromXml (const QDomElement &xml_element) m_label_color = QColor(color_str); } + m_potential = xml_element.attribute("potential"); + // Read master label override settings m_use_master_label = (xml_element.attribute("use_master_label") == QLatin1String("true")); m_master_label_index = xml_element.attribute("master_label_index", "0").toInt(); diff --git a/sources/properties/terminaldata.h b/sources/properties/terminaldata.h index 9032e6b2c..7d269b4cd 100644 --- a/sources/properties/terminaldata.h +++ b/sources/properties/terminaldata.h @@ -103,6 +103,18 @@ class TerminalData : public PropertiesInterface */ QString m_name; + /** + @brief m_potential + An optional, symbol-author-chosen grouping identifier shared by + terminals that belong to the same physical terminal within + a multi-terminal block. When potential_isolating is enabled + on the parent element, terminals sharing a non-empty, + matching m_potential stay linked to each other; terminals + with different (or empty) values become isolated from each + other. Empty by default. + */ + QString m_potential; + /** @brief m_pos Position of the terminal. The second point is calculated diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index ec862b39c..a09efec12 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -927,6 +927,18 @@ TerminalData::Type Terminal::terminalType() const return d->m_type; } +/** + @brief Terminal::potential + @return this terminal's own potential-group identifier (@see + TerminalData::m_potential). + An author-chosen grouping used only + within a single multi-terminal element. +*/ +QString Terminal::potential() const +{ + return d->m_potential; +} + /** @brief Terminal::setUseMasterLabel Set whether this terminal uses a label from the master's contact group @@ -977,8 +989,22 @@ QList relatedPotentialTerminal ( { // English: Check if the user activated the potential isolation checkbox for this terminal if (terminal->parentElement()->elementInformations().value(QStringLiteral("potential_isolating")).toString() == QLatin1String("true")) { - // English: Potential is isolated. Return an empty list so it does not propagate to the other side. - return QList(); + // English: Potential is isolated -- but terminals sharing this + // terminal's own, non-empty potential-group identifier + // (@see TerminalData::m_potential, set per-terminal in the + // element editor) still belong to the same physical terminal + // and stay linked to each other. An empty/unset potential on + // every terminal reproduces the previous, fully-isolated + // behavior exactly, so existing elements are unaffected. + const QString this_potential = terminal->potential(); + QList same_potential; + if (!this_potential.isEmpty()) { + for (Terminal *t : terminal->parentElement()->terminals()) { + if (t != terminal && t->potential() == this_potential) + same_potential << t; + } + } + return same_potential; } QList terminals = terminal->parentElement()->terminals(); diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index a6eae784c..e5e17b4fa 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -79,6 +79,7 @@ class Terminal : public QGraphicsObject QString name () const; QString baseName () const; TerminalData::Type terminalType() const; + QString potential() const; bool useMasterLabel() const { return d->m_use_master_label; } void setUseMasterLabel(bool use); int masterLabelIndex() const { return d->m_master_label_index; }