From 2e1ba464300df5d8e1481fa54f1b5a5cdb42841b Mon Sep 17 00:00:00 2001 From: ispyisail Date: Thu, 13 Aug 2026 22:01:37 +1200 Subject: [PATCH] Export slave cross-reference labels to DXF Cross-references were missing from DXF exports, as reported on the forum: https://qelectrotech.org/forum/viewtopic.php?id=2481 generateDxf() walks the scene and collects items by cast. A slave element's cross-reference label ("(6-G15)", pointing back to its master) is a plain QGraphicsTextItem hung off a DynamicElementTextItem as a child, so it matches neither the IndependentTextItem nor the DynamicElementTextItem branch and was dropped on the floor. Nothing was wrong with the label itself; it was simply never collected. Collect it through the existing DynamicElementTextItem::slaveXrefItem() accessor and draw it with the same placement, rotation and multi-line handling as the other text items, using defaultTextColor() since a bare QGraphicsTextItem has no DiagramTextItem::color(). Measured on examples/industrial.qet, comparing against the PDF export (which renders the whole scene and so shows everything): before after PDF slave xrefs "(n-Xn)" 0 41 41 folio/position strings 317 358 403 The slave cross-references now match the PDF exactly. Still missing, and not addressed here: the master-side cross-reference table drawn by CrossRefItem, which accounts for the remaining 45 strings. CrossRefItem is a QGraphicsObject that renders itself with custom QPainter code in three different modes (drawAsCross, drawAsContacts, drawAsPlcTable) including contact symbols and rules, so giving it a DXF representation is a larger piece of work than this. --- sources/exportdialog.cpp | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/sources/exportdialog.cpp b/sources/exportdialog.cpp index 7e2b9f7ac..f2b10ebec 100644 --- a/sources/exportdialog.cpp +++ b/sources/exportdialog.cpp @@ -472,6 +472,10 @@ void ExportDialog::generateDxf( QList list_conductors; QList list_texts; QList list_images; + //Slave cross-reference labels. They hang off a DynamicElementTextItem + //as plain QGraphicsTextItem children, so neither cast below picks them + //up and they were missing from the DXF entirely. + QList list_xref_texts; QList list_lines; QList list_rectangles; //QList list_ellipses; @@ -493,6 +497,9 @@ void ExportDialog::generateDxf( list_shapes << dii; } else if (DynamicElementTextItem *deti = qgraphicsitem_cast(qgi)) { list_texts << deti; + if (QGraphicsTextItem *xref = deti->slaveXrefItem()) { + list_xref_texts << xref; + } } else if (QetGraphicsTableItem *gti = qgraphicsitem_cast(qgi)) { list_tables << gti; } @@ -688,6 +695,42 @@ void ExportDialog::generateDxf( } } + //Draw the slave cross-reference labels + for (QGraphicsTextItem *xref : std::as_const(list_xref_texts)) + { + qreal fontSize = xref->font().pointSizeF(); + if (fontSize < 0) + fontSize = xref->font().pixelSize(); + + qreal angle = xref->rotation(); + QGraphicsItem *parent = xref->parentItem(); + while (parent) { + angle += parent->rotation(); + parent = parent->parentItem(); + } + + qreal angler = angle * M_PI/180; + int xdir = -sin(angler); + int ydir = -cos(angler); + qreal x = xref->scenePos().x() + + xdir * fontSize * 1.8 + - ydir * fontSize; + qreal y = xref->scenePos().y() + - ydir * fontSize * 1.8 + - xdir * fontSize * 0.9; + + const QStringList lines = xref->toPlainText().split('\n'); + const qreal offset = fontSize * 1.6; + for (const QString &line : lines) { + if (line.size() > 0 && line != QLatin1String("_")) { + Createdxf::drawText(file_path, line, QPointF(x, y), fontSize, + 360-angle, Createdxf::dxfColor(xref->defaultTextColor()), 0.72); + } + x += offset * xdir; + y -= offset * ydir; + } + } + Createdxf::dxfEnd(file_path); saveReloadDiagramParameters(diagram, false);