From 1a2fea84ff460f0a18ec1bda277b2a7656f12721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tade=C3=A1=C5=A1=20Pila=C5=99?= Date: Wed, 22 Jun 2022 18:02:13 +0200 Subject: [PATCH] Add 'Other' option for slave device contact type This option alows for displaying XRef without contact drawing. This is useful for spliting one physical part into multiple logical elements when the slave element is not a switch. --- .../ui/elementpropertieseditorwidget.cpp | 1 + sources/properties/elementdata.cpp | 6 +++++- sources/properties/elementdata.h | 3 ++- sources/qetgraphicsitem/crossrefitem.cpp | 20 ++++++++++++++++++- sources/qetgraphicsitem/crossrefitem.h | 3 ++- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/sources/editor/ui/elementpropertieseditorwidget.cpp b/sources/editor/ui/elementpropertieseditorwidget.cpp index d72fdddc9..2a64cac81 100644 --- a/sources/editor/ui/elementpropertieseditorwidget.cpp +++ b/sources/editor/ui/elementpropertieseditorwidget.cpp @@ -128,6 +128,7 @@ void ElementPropertiesEditorWidget::setUpInterface() ui->m_state_cb->addItem(tr("Normalement ouvert"), ElementData::NO); ui->m_state_cb->addItem(tr("Normalement fermé"), ElementData::NC); ui->m_state_cb->addItem(tr("Inverseur"), ElementData::SW); + ui->m_state_cb->addItem(tr("Other"), ElementData::Other); ui->m_type_cb->addItem(tr("Simple"), ElementData::SSimple); ui->m_type_cb->addItem(tr("Puissance"), ElementData::Power); ui->m_type_cb->addItem(tr("Temporisé travail"), ElementData::DelayOn); diff --git a/sources/properties/elementdata.cpp b/sources/properties/elementdata.cpp index c7b16a24a..5db90c568 100644 --- a/sources/properties/elementdata.cpp +++ b/sources/properties/elementdata.cpp @@ -425,6 +425,8 @@ QString ElementData::slaveStateToString(ElementData::SlaveState type) return QStringLiteral("NC"); case SW: return QStringLiteral("SW"); + case Other: + return QStringLiteral("Other"); } } @@ -436,7 +438,9 @@ ElementData::SlaveState ElementData::slaveStateFromString(const QString &string) return ElementData::NC; } else if (string == QLatin1String("SW")) { return ElementData::SW; - } + } else if (string == QLatin1String("Other")){ + return ElementData::Other; + } qDebug() << "ElementData::slaveStateFromString : string : " << string diff --git a/sources/properties/elementdata.h b/sources/properties/elementdata.h index 9e57fbfab..701221bd5 100644 --- a/sources/properties/elementdata.h +++ b/sources/properties/elementdata.h @@ -64,7 +64,8 @@ class ElementData : public PropertiesInterface enum SlaveState { NO, NC, - SW + SW, + Other }; Q_ENUM(SlaveState) diff --git a/sources/qetgraphicsitem/crossrefitem.cpp b/sources/qetgraphicsitem/crossrefitem.cpp index 49700af99..217f4c68f 100644 --- a/sources/qetgraphicsitem/crossrefitem.cpp +++ b/sources/qetgraphicsitem/crossrefitem.cpp @@ -614,6 +614,7 @@ void CrossRefItem::drawAsContacts(QPainter &painter) if (state == "NO") option = NO; else if (state == "NC") option = NC; else if (state == "SW") option = SW; + else if (state == "Other") option = Other; QString type = info["type"].toString(); if (type == "power") option += Power; @@ -644,7 +645,7 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt) { QString str = elementPositionText(elmt); int offset = m_drawed_contacts*10; - QRectF bounding_rect; + QRectF bounding_rect = QRectF(0, offset, 24, 10); QPen pen = painter.pen(); m_hovered_contact == elmt ? pen.setColor(Qt::blue) :pen.setColor(Qt::black); @@ -819,6 +820,23 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt) //a switch contact take place of two normal contact m_drawed_contacts += 2; + }else if(flags &Other){ + //Draw position text + QRectF text_rect = painter.boundingRect( + QRectF(30, offset+5, 5, 10), + Qt::AlignLeft | Qt::AlignVCenter, + str); + painter.drawText(text_rect, + Qt::AlignLeft | Qt::AlignVCenter, + str); + bounding_rect = bounding_rect.united(text_rect); + + if (m_hovered_contacts_map.contains(elmt)) { + m_hovered_contacts_map.insert(elmt, bounding_rect); + } + else { + m_hovered_contacts_map.insert(elmt, bounding_rect); + } } return bounding_rect; diff --git a/sources/qetgraphicsitem/crossrefitem.h b/sources/qetgraphicsitem/crossrefitem.h index ef3a24132..2c5e97eb6 100644 --- a/sources/qetgraphicsitem/crossrefitem.h +++ b/sources/qetgraphicsitem/crossrefitem.h @@ -75,7 +75,8 @@ class CrossRefItem : public QGraphicsObject DelayOn = 16, DelayOff = 32, DelayOnOff = 64, - Delay = 112 + Delay = 112, + Other = 128 }; QRectF boundingRect() const override;