Terminal strip item: also redraw an item just added to a folio

The redraw on change was connected in setTerminalStrip() only, used when
an item is read from the project. An item added with the "Add terminal
strip" dialog is built with TerminalStripItem(strip), which did not
connect: it was not redrawn after the terminal strip editor was applied,
until the project was reopened.

Both constructors now go through connectStrip().
This commit is contained in:
Laurent Trinques
2026-10-18 16:42:07 +02:00
parent 015811d243
commit ff18467117
2 changed files with 26 additions and 14 deletions
@@ -39,6 +39,7 @@ TerminalStripItem::TerminalStripItem(QPointer<TerminalStrip> strip,
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
setAcceptHoverEvents(true);
setDefaultLayout();
connectStrip(strip);
}
TerminalStripItem::TerminalStripItem(QGraphicsItem *parent) :
@@ -50,21 +51,8 @@ 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);
}
connectStrip(strip);
m_drawer.setStrip(QSharedPointer<TerminalStripDrawer::TrueTerminalStrip> {
new TerminalStripDrawer::TrueTerminalStrip { strip }});
m_pending_strip_uuid = QUuid();
@@ -271,6 +259,29 @@ TerminalStripLayoutPattern::DrawStyle TerminalStripItem::drawStyle() const {
return m_drawer.drawStyle();
}
/**
* @brief TerminalStripItem::connectStrip
* Redraw this item as soon as @a strip or one of its terminals changes
* (terminal strip editor applied, undo, redo...).
* The connections to the previous strip are removed.
* @param strip
*/
void TerminalStripItem::connectStrip(TerminalStrip *strip)
{
for (const auto &connection_ : std::as_const(m_strip_connections)) {
disconnect(connection_);
}
m_strip_connections.clear();
if (strip)
{
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);
}
}
/**
* @brief TerminalStripItem::stripChanged
* The strip or one of its terminals changed : the size of the drawing
@@ -76,6 +76,7 @@ class TerminalStripItem : public QetGraphicsItem
private:
void setDefaultLayout();
QString xrefToolTip(const TerminalStripDrawer::hoverTerminal &terminal) const;
void connectStrip(TerminalStrip *strip);
void stripChanged();
private: