mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-05-26 16:30:03 +02:00
crossrefitem: display terminal names on contact symbols in Xref
When a slave element has named terminals in its element definition (.elmt), the terminal names (e.g. 13/14 for NO, 11/12 for NC, 12/13/14 for SW) are now displayed on each side of the contact symbol in the cross-reference view. - NO/NC contacts: name[0] on the left, name[1] on the right - SW contacts: name[0] (NO) top-left, name[1] (common) top-right, name[2] (NC) bottom-left Terminal names are read from Terminal::name() which is populated from TerminalData::m_name during element parsing. If terminals are not named, nothing is displayed (fully backward compatible). Users are expected to name their own terminals in the element editor to avoid duplicating elements in the official collection.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "element.h"
|
||||
#include "elementtextitemgroup.h"
|
||||
#include "qgraphicsitemutility.h"
|
||||
#include "terminal.h"
|
||||
|
||||
//define the height of the header.
|
||||
static int header = 5;
|
||||
@@ -627,6 +628,16 @@ void CrossRefItem::drawAsContacts(QPainter &painter)
|
||||
QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt)
|
||||
{
|
||||
QString str = elementPositionText(elmt);
|
||||
|
||||
// Collect terminal names from the element definition (.elmt)
|
||||
// e.g. name="13" and name="14" on each terminal
|
||||
QStringList terminal_names;
|
||||
for (Terminal *t : elmt->terminals()) {
|
||||
const QString tname = t->name();
|
||||
if (!tname.isEmpty())
|
||||
terminal_names << tname;
|
||||
}
|
||||
|
||||
int offset = m_drawed_contacts*10;
|
||||
QRectF bounding_rect = QRectF(0, offset, 24, 10);
|
||||
|
||||
@@ -643,15 +654,19 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt)
|
||||
painter.drawLine(0, offset+6, 8, offset+6);
|
||||
painter.drawLine(16, offset+6, 24, offset+6);
|
||||
|
||||
///take example of this code for display the terminal text
|
||||
/*QFont font = QETApp::diagramTextsFont(4);
|
||||
font.setBold(true);
|
||||
painter.setFont(font);
|
||||
QRectF bt(0, offset, 24, 10);
|
||||
int txt = 10 + m_drawed_contacts;
|
||||
painter.drawText(bt, Qt::AlignLeft|Qt::AlignTop, QString::number(txt));
|
||||
painter.drawText(bt, Qt::AlignRight|Qt::AlignTop, QString::number(txt));
|
||||
painter.setFont(QETApp::diagramTextsFont(5));*/
|
||||
// Draw terminal names on each side of the contact symbol
|
||||
// terminal_names[0] on the left, terminal_names[1] on the right
|
||||
if (!terminal_names.isEmpty()) {
|
||||
QFont font = QETApp::diagramTextsFont(4);
|
||||
font.setBold(true);
|
||||
painter.setFont(font);
|
||||
QRectF bt(0, offset, 24, 10);
|
||||
if (terminal_names.size() >= 1)
|
||||
painter.drawText(bt, Qt::AlignLeft|Qt::AlignTop, terminal_names[0]);
|
||||
if (terminal_names.size() >= 2)
|
||||
painter.drawText(bt, Qt::AlignRight|Qt::AlignTop, terminal_names[1]);
|
||||
painter.setFont(QETApp::diagramTextsFont(5));
|
||||
}
|
||||
|
||||
//draw open contact
|
||||
if (flags &NO) {
|
||||
@@ -768,6 +783,28 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt)
|
||||
};
|
||||
painter.drawPolyline(p2, 3);
|
||||
|
||||
// Draw terminal names for switch contact (3 terminals)
|
||||
// terminal_names[0] = NO side (top left)
|
||||
// terminal_names[1] = NC side (bottom left)
|
||||
// terminal_names[2] = common side (right)
|
||||
if (!terminal_names.isEmpty()) {
|
||||
QFont font = QETApp::diagramTextsFont(4);
|
||||
font.setBold(true);
|
||||
painter.setFont(font);
|
||||
// Sort order from parseTerminal (top->bottom, left->right):
|
||||
// [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
|
||||
if (terminal_names.size() >= 2)
|
||||
painter.drawText(QRectF(16, offset+4, 8, 6),
|
||||
Qt::AlignRight|Qt::AlignTop, terminal_names[1]); // 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
|
||||
painter.setFont(QETApp::diagramTextsFont(5));
|
||||
}
|
||||
|
||||
//Draw the half ellipse off delay
|
||||
if (flags &Delay)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user