mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-29 14:14:15 +02:00
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:
@@ -355,6 +355,20 @@ void PlcLinkWidget::on_m_unlink_pb_clicked()
|
||||
return;
|
||||
|
||||
LinkElementCommand *undo = new LinkElementCommand(m_element);
|
||||
|
||||
// Store the current group index so makeLink() can
|
||||
// restore PLC variables and terminal labels on undo.
|
||||
for (Element *elmt : m_element->linkedElements())
|
||||
{
|
||||
if (elmt->linkType() == Element::Master)
|
||||
{
|
||||
int idx = elmt->groupIndexForElement(m_element);
|
||||
if (idx >= 0)
|
||||
undo->setGroupIndex(idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
undo->unlinkAll();
|
||||
m_element->diagram()->undoStack().push(undo);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user