diff --git a/sources/qetgraphicsitem/crossrefitem.cpp b/sources/qetgraphicsitem/crossrefitem.cpp index 9e39ea545..aa3d26196 100644 --- a/sources/qetgraphicsitem/crossrefitem.cpp +++ b/sources/qetgraphicsitem/crossrefitem.cpp @@ -493,11 +493,29 @@ void CrossRefItem::setUpCrossBoundingRect(QPainter &painter) QStringList no_str, nc_str; + // Helper lambda: build "[13-14] pos" string for an element + // Takes the first 2 named terminals — users are expected to name + // their terminals in the element editor (see commit on Contact mode) + auto buildLabel = [this](Element *elmt) -> QString { + QStringList tnames; + for (Terminal *t : elmt->terminals()) { + const QString tn = t->name(); + if (!tn.isEmpty()) { + tnames << tn; + if (tnames.size() >= 2) break; + } + } + QString pos = elementPositionText(elmt, true); + if (!tnames.isEmpty()) + return QStringLiteral("[") + tnames.join("-") + QStringLiteral("] ") + pos; + return pos; + }; + for (auto elmt : NOElements()) { - no_str.append(elementPositionText(elmt, true)); + no_str.append(buildLabel(elmt)); } for (auto elmt : NCElements()) { - nc_str.append(elementPositionText(elmt, true)); + nc_str.append(buildLabel(elmt)); } //There is no string to display, we return now @@ -795,13 +813,13 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt) // [0]=12 (NO, top-left), [1]=14 (common, top-center), [2]=13 (NC, bottom-center) if (terminal_names.size() >= 1) painter.drawText(QRectF(0, offset, 8, 8), - Qt::AlignLeft|Qt::AlignTop, terminal_names[0]); // 12 NO left + Qt::AlignLeft|Qt::AlignTop, terminal_names[1]); // 12 NO left if (terminal_names.size() >= 2) painter.drawText(QRectF(16, offset+4, 8, 6), - Qt::AlignRight|Qt::AlignTop, terminal_names[1]); // 14 common right + Qt::AlignRight|Qt::AlignTop, terminal_names[2]); // 14 common right if (terminal_names.size() >= 3) painter.drawText(QRectF(0, offset+9, 8, 6), - Qt::AlignLeft|Qt::AlignTop, terminal_names[2]); // 13 NC left-bottom + Qt::AlignLeft|Qt::AlignTop, terminal_names[0]); // 13 NC left-bottom painter.setFont(QETApp::diagramTextsFont(5)); } @@ -903,7 +921,25 @@ void CrossRefItem::fillCrossRef(QPainter &painter) m_hovered_contact == elmt ? pen.setColor(Qt::blue) :pen.setColor(Qt::black); painter.setPen(pen); + // Collect terminal names and build "[13-14]" style label + // Takes the first 2 named terminals — users are expected to name + // their terminals in the element editor (see commit on Contact mode) + QStringList tnames; + for (Terminal *t : elmt->terminals()) { + const QString tn = t->name(); + if (!tn.isEmpty()) { + tnames << tn; + if (tnames.size() >= 2) break; + } + } + QString terminal_label; + if (!tnames.isEmpty()) + terminal_label = QStringLiteral("[") + tnames.join("-") + QStringLiteral("]"); + QString str = elementPositionText(elmt, true); + if (!terminal_label.isEmpty()) + str = terminal_label + QStringLiteral(" ") + str; + QRectF bounding = painter.boundingRect( QRectF(no_top_left, QSize(middle_cross, 1)), @@ -932,7 +968,25 @@ void CrossRefItem::fillCrossRef(QPainter &painter) :pen.setColor(Qt::black); painter.setPen(pen); + // Collect terminal names and build "[11-12]" style label + // Takes the first 2 named terminals — users are expected to name + // their terminals in the element editor (see commit on Contact mode) + QStringList tnames_nc; + for (Terminal *t : elmt->terminals()) { + const QString tn = t->name(); + if (!tn.isEmpty()) { + tnames_nc << tn; + if (tnames_nc.size() >= 2) break; + } + } + QString terminal_label; + if (!tnames_nc.isEmpty()) + terminal_label = QStringLiteral("[") + tnames_nc.join("-") + QStringLiteral("]"); + QString str = elementPositionText(elmt, true); + if (!terminal_label.isEmpty()) + str = terminal_label + QStringLiteral(" ") + str; + QRectF bounding = painter.boundingRect( QRectF(nc_top_left, QSize(middle_cross, 1)),