mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-10 22:24:13 +02:00
Keep a coil's contacts in the order the file saved them
On opening a project, a coil and its contacts are linked in the order the folios' items are visited. When contacts are on an earlier folio than the coil they link first, so the coil's list followed the folio order instead of the file's, and contacts on one folio swapped places from run to run. Saving the same project twice could then give two different files. After linking, Element::initLink() now puts the linked elements back in the order the file listed them. Elements linked but not in that list keep their place after it. Test: tst_resaveunchanged::savedLinkOrderKept reverses a coil's two contacts in m_000.qet and checks a resave keeps that order; it fails without the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Wga9B92BNurDEtxxtCDxf
This commit is contained in:
@@ -1642,6 +1642,7 @@ void Element::initLink(QETProject *prj)
|
||||
}
|
||||
}
|
||||
}
|
||||
restoreSavedLinkOrder();
|
||||
tmp_uuids_link.clear();
|
||||
}
|
||||
|
||||
@@ -1669,9 +1670,36 @@ void Element::initLink(const QList<Element *> &candidates)
|
||||
}
|
||||
}
|
||||
}
|
||||
restoreSavedLinkOrder();
|
||||
tmp_uuids_link.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::restoreSavedLinkOrder
|
||||
Put connected_elements back in the order tmp_uuids_link saved them.
|
||||
Partners link in the order the folios' items are visited, and for
|
||||
items at the same height that order changes from run to run, so a
|
||||
master's contacts were saved in a different order each time.
|
||||
Linked elements missing from the saved list keep their place after it.
|
||||
*/
|
||||
void Element::restoreSavedLinkOrder()
|
||||
{
|
||||
QList<Element *> ordered;
|
||||
for (const auto &link_info : std::as_const(tmp_uuids_link)) {
|
||||
for (Element *elmt : std::as_const(connected_elements)) {
|
||||
if (elmt->uuid() == link_info.uuid && !ordered.contains(elmt)) {
|
||||
ordered << elmt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Element *elmt : std::as_const(connected_elements)) {
|
||||
if (!ordered.contains(elmt))
|
||||
ordered << elmt;
|
||||
}
|
||||
connected_elements = ordered;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Element::linkTypeToString
|
||||
* \deprecated use instead ElementData::typeToString
|
||||
|
||||
Reference in New Issue
Block a user