Fix text position shift when duplicating diagram pages

duplicateDiagram() called restoreText() on every newly loaded
element.  Each setPlainText() inside restoreText() is wrapped in
m_block_alignment except the last one, so finishAlignment() ran on
elements whose positions came straight from the XML — shifting
center and right-aligned texts.

Fix: use toXml(true, true) which handles correctTextPos/restoreText
internally for Slave and Report elements only, and call restoreText()
on the target for those same element types to recalculate their text
positions for the actual resolved text.
This commit is contained in:
Kellermorph
2026-09-13 18:50:38 +02:00
parent 51209d30b6
commit a5fe544415
+18 -14
View File
@@ -658,21 +658,14 @@ void ElementsPanelWidget::duplicateDiagram()
BorderProperties bp = source_diagram->border_and_titleblock.exportBorder();
new_diagram->border_and_titleblock.importBorder(bp);
for (QGraphicsItem *item : source_diagram->items()) {
if (Element *elmt = dynamic_cast<Element *>(item)) {
source_diagram->correctTextPos(elmt);
}
}
QDomDocument doc = source_diagram->toXml();
// Serialize the whole diagram with is_copy_command=true.
// This is the same mechanism as Ctrl+C: toXml(true, true)
// internally calls correctTextPos/restoreText for Slave and
// Report elements only — producing correct text positions
// in the XML. No manual correctTextPos/restoreText needed.
QDomDocument doc = source_diagram->toXml(true, true);
QDomElement diagram_elmt = doc.documentElement();
for (QGraphicsItem *item : source_diagram->items()) {
if (Element *elmt = dynamic_cast<Element *>(item)) {
source_diagram->restoreText(elmt);
}
}
new_diagram->fromXml(diagram_elmt, QPointF(0, 0), false, nullptr);
for (QGraphicsItem *item : new_diagram->items()) {
@@ -683,7 +676,18 @@ void ElementsPanelWidget::duplicateDiagram()
// of the project database, so duplicates fail to insert and
// silently vanish from nomenclature/summary tables.
elmt->newUuid();
new_diagram->restoreText(elmt);
// toXml(true, true) applied correctTextPos to Slave and
// Report elements, which shifted their text positions to
// match the stripped composite text. restoreText()
// recalculates the position for the actual resolved text.
// Only Slave and Report need this — other element types
// were not affected by correctTextPos.
if (elmt->linkType() == Element::Slave ||
elmt->linkType() & Element::AllReport)
{
new_diagram->restoreText(elmt);
}
}
else if (Conductor *cond = dynamic_cast<Conductor *>(item)) {
// Same reasoning for conductors: conductor.uuid is the PRIMARY