From ddc71553e2c9bdc25695a69951e13c7480e765fa Mon Sep 17 00:00:00 2001 From: Laurent Trinques Date: Sun, 18 Oct 2026 16:04:20 +0200 Subject: [PATCH] Terminal strip item: redraw the strip as soon as it changes TerminalStripItem was connected to nothing: after applying the terminal strip editor (width, catalog terminal, color, type...), undo or redo, the strip drawn on the folio kept its old drawing until something else made the scene repaint, and its bounding rect was not updated when the width of the terminals changed. - TerminalStrip::dataChanged() is emitted when the data of the strip is set, and when the data of the element of one of its terminals changes (Element::setElementData(), Element::setElementInformations()). - TerminalStripItem connects to dataChanged(), orderChanged(), bridgeChanged() and bridgeColorChanged() of its strip, and updates its geometry and redraws itself. --- .../GraphicsItem/terminalstripitem.cpp | 26 +++++++++++++++++++ .../GraphicsItem/terminalstripitem.h | 2 ++ sources/TerminalStrip/terminalstrip.cpp | 11 ++++++++ sources/TerminalStrip/terminalstrip.h | 4 +++ sources/qetgraphicsitem/element.cpp | 21 +++++++++++++++ 5 files changed, 64 insertions(+) diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp b/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp index 07139e595..1a758c145 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp +++ b/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp @@ -22,6 +22,7 @@ #include "../../project/projectpropertieshandler.h" #include "../../qetgraphicsitem/qgraphicsitemutility.h" #include "../terminalstrip.h" +#include "../terminalstripbridge.h" #include "../physicalterminal.h" #include "../realterminal.h" #include "../ui/terminalstripeditorwindow.h" @@ -49,7 +50,21 @@ TerminalStripItem::TerminalStripItem(QGraphicsItem *parent) : void TerminalStripItem::setTerminalStrip(TerminalStrip *strip) { + for (const auto &connection_ : std::as_const(m_strip_connections)) { + disconnect(connection_); + } + m_strip_connections.clear(); + m_strip = strip; + if (strip) + { + //Redraw as soon as the strip or one of its terminals changes + //(terminal strip editor applied, undo, redo...) + m_strip_connections << connect(strip, &TerminalStrip::orderChanged, this, &TerminalStripItem::stripChanged) + << connect(strip, &TerminalStrip::bridgeChanged, this, &TerminalStripItem::stripChanged) + << connect(strip, &TerminalStrip::bridgeColorChanged, this, &TerminalStripItem::stripChanged) + << connect(strip, &TerminalStrip::dataChanged, this, &TerminalStripItem::stripChanged); + } m_drawer.setStrip(QSharedPointer { new TerminalStripDrawer::TrueTerminalStrip { strip }}); m_pending_strip_uuid = QUuid(); @@ -256,6 +271,17 @@ TerminalStripLayoutPattern::DrawStyle TerminalStripItem::drawStyle() const { return m_drawer.drawStyle(); } +/** + * @brief TerminalStripItem::stripChanged + * The strip or one of its terminals changed : the size of the drawing + * can change (width of the terminals, number of terminals...), redraw it. + */ +void TerminalStripItem::stripChanged() +{ + prepareGeometryChange(); + update(); +} + void TerminalStripItem::setDefaultLayout() { if (m_strip && m_strip->project()) { diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripitem.h b/sources/TerminalStrip/GraphicsItem/terminalstripitem.h index b126dbddc..c77596aa3 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripitem.h +++ b/sources/TerminalStrip/GraphicsItem/terminalstripitem.h @@ -76,9 +76,11 @@ class TerminalStripItem : public QetGraphicsItem private: void setDefaultLayout(); QString xrefToolTip(const TerminalStripDrawer::hoverTerminal &terminal) const; + void stripChanged(); private: QPointer m_strip; + QList m_strip_connections; TerminalStripDrawer::TerminalStripDrawer m_drawer; QUuid m_pending_strip_uuid; }; diff --git a/sources/TerminalStrip/terminalstrip.cpp b/sources/TerminalStrip/terminalstrip.cpp index 71a0cc0c4..7740cbef8 100644 --- a/sources/TerminalStrip/terminalstrip.cpp +++ b/sources/TerminalStrip/terminalstrip.cpp @@ -100,6 +100,17 @@ TerminalStripData TerminalStrip::data() const { */ void TerminalStrip::setData(const TerminalStripData &data) { m_data = data; + emit dataChanged(); +} + +/** + * @brief TerminalStrip::terminalDataChanged + * Called when the data of the element of one of the terminals of this strip + * is changed (Element::setElementData(), Element::setElementInformations()) : + * the items which draw this strip on the folios are redrawn. + */ +void TerminalStrip::terminalDataChanged() { + emit dataChanged(); } bool TerminalStrip::addTerminal(QSharedPointer real_t) diff --git a/sources/TerminalStrip/terminalstrip.h b/sources/TerminalStrip/terminalstrip.h index 9aa2201f5..96111ff99 100644 --- a/sources/TerminalStrip/terminalstrip.h +++ b/sources/TerminalStrip/terminalstrip.h @@ -53,6 +53,9 @@ class TerminalStrip : public QObject void orderChanged(); //Emitted when the order of the physical terminal is changed void bridgeChanged(); void bridgeColorChanged(QSharedPointer bridge); + //Emitted when the data of the strip (name...) or of one of its + //terminals (width, color, type...) is changed : what is drawn changes + void dataChanged(); public: TerminalStrip(QETProject *project); @@ -79,6 +82,7 @@ class TerminalStrip : public QObject TerminalStripData data() const; void setData(const TerminalStripData &data); + void terminalDataChanged(); bool addTerminal (QSharedPointer real_t); void addTerminals (QVector> real_t_vector); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index f2d61692f..72dd2a02c 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -39,6 +39,8 @@ #include "../undocommand/changeelementinformationcommand.h" #include "../undocommand/setautonumcontextcommand.h" #include "crossrefitem.h" +#include "terminalelement.h" +#include "../TerminalStrip/terminalstrip.h" #include "dynamicelementtextitem.h" #include "elementtextitemgroup.h" #include "iostream" @@ -2087,6 +2089,22 @@ void Element::setUuid(const QUuid &uuid) diagram()->project()->dataBase()->elementUuidChanged(this, old_uuid); } +namespace { +/** + @brief notifyTerminalStrip + If @a element is a terminal of a terminal strip, tell the strip that the + data of the terminal changed, so that the strip is redrawn on the folios. +*/ +void notifyTerminalStrip(Element *element) +{ + if (auto terminal_ = dynamic_cast(element)) { + if (auto strip_ = terminal_->parentTerminalStrip()) { + strip_->terminalDataChanged(); + } + } +} +} + /** @brief Element::storeInformation Write this symbol's information to its project's store, once it is @@ -2116,6 +2134,7 @@ void Element::setElementInformations(DiagramContext dc) } storeInformation(); emit elementInfoChange(old_info, m_data.m_informations); + notifyTerminalStrip(this); // Propagate label change to linked PLC slaves (label is changed via // setElementInformations through the undo stack, not via setElementData) @@ -2204,6 +2223,8 @@ void Element::setElementData(ElementData data) } emit elementInfoChange(old_info, m_data.m_informations); } + //Type, function, led... of a terminal are not informations + notifyTerminalStrip(this); // Propagate PLC master data changes to linked slaves if (m_data.m_type == ElementData::Master && m_data.m_master_type == ElementData::PLC)