Fix undo not restoring PLC slave fields and stale connections on position change

Two additional bugs found after the initial xref cleanup:

1. Undo after unlink did not restore PLC variables (PLC_TYPE,
   PLC_ADDRESS, etc.) because PlcLinkWidget::on_m_unlink_pb_clicked()
   never stored the current group index in the LinkElementCommand.
   makeLink() only populates PLC fields when group_idx >= 0, so
   the slave was re-linked but appeared empty. Fixed by reading the
   group index from the master via groupIndexForElement() and calling
   setGroupIndex() before unlinking.

2. m_update_slave_Xref_connection was only cleared inside the
   if(m_slave_Xref_item) block in the updateXref() cleanup path.
   For AlignHCenter (Text field) position, no m_slave_Xref_item
   is ever created — the connections are stored in
   m_update_slave_Xref_connection but never cleaned up on unlink.
   On re-link, the old stale entries prevented new connections from
   being established. Fixed by clearing the list unconditionally
   in the cleanup path.
This commit is contained in:
Kellermorph
2026-09-14 16:19:37 +02:00
parent 00e75604b0
commit 9bfe18807f
3 changed files with 18 additions and 2 deletions
@@ -1470,11 +1470,12 @@ void DynamicElementTextItem::updateXref()
m_Xref_item = nullptr;
}
m_update_slave_Xref_connection.clear();
if(m_slave_Xref_item)
{
delete m_slave_Xref_item;
m_slave_Xref_item = nullptr;
m_update_slave_Xref_connection.clear();
//If position changed to Champ de texte, store xref in element info
if(m_parent_element->linkType() == Element::Slave &&