From 23f8e261e5338d8e503abf059f44ee3e86947a56 Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Wed, 30 Sep 2026 20:20:52 +0200 Subject: [PATCH] Element editor: save the moved position of the PLC table Moving the PLC table in the element editor was lost on save: the table came back at (0, 0) when the element was reopened, and it was drawn at (0, 0) in the diagram editor as well. PartPlcTable::toXml() wrote m_rect.x()/y(), which are the coordinates inside the item, and the move of a part never touches m_rect - it lives in pos() (CustomElementGraphicPart::mouseMoveEvent, or the decorator for a multi-selection). m_rect starts at the item origin, so x="0" y="0" was written whatever the user did, while fromXml() reads those two attributes as scene coordinates and hands them to setPos(). Every other part translates first, see PartRectangle::toXml() with sceneTopLeft(). The top-left corner is now mapped to scene coordinates before being written, which also covers a group transformation, since that one moves m_rect while pos() stays put. Both readers of the attribute need no change: ElementScene::fromXml() for the editor and Element() for the runtime drawing of the table (Element::drawPlcTable) already expect scene coordinates. Elements that still carry x="0" y="0" keep loading as before. Full build clean. Test suite: the same three failures as before the change (tst_menubarkeyboard, tst_databasefromdocument, tst_terminaluuids), each of them also failing on a build without this patch, so they are unrelated. --- sources/editor/graphicspart/partplctable.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sources/editor/graphicspart/partplctable.cpp b/sources/editor/graphicspart/partplctable.cpp index d4f474096..18f56d2b9 100644 --- a/sources/editor/graphicspart/partplctable.cpp +++ b/sources/editor/graphicspart/partplctable.cpp @@ -370,8 +370,13 @@ void PartPlcTable::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti const QDomElement PartPlcTable::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("plc_table"); - qreal x = qRound(m_rect.x() * 100.0) / 100.0; - qreal y = qRound(m_rect.y() * 100.0) / 100.0; + //The move of this part lives in pos(), not in m_rect (which always + //starts at the item origin), so the scene coordinates must be written + //here, exactly like every other part does (see PartRectangle::toXml). + //Otherwise the position is silently reset to (0, 0) on the next load. + const QPointF top_left = mapToScene(m_rect.topLeft()); + qreal x = qRound(top_left.x() * 100.0) / 100.0; + qreal y = qRound(top_left.y() * 100.0) / 100.0; xml_element.setAttribute("x", QString::number(x)); xml_element.setAttribute("y", QString::number(y));