From 91552373cfe0b9efc3128a9964e1444de15f6899 Mon Sep 17 00:00:00 2001 From: blacksun Date: Mon, 28 Apr 2014 15:41:58 +0000 Subject: [PATCH] Cross ref item: user can select if xref must be displayed has a table or a contacts list. Option is found in config dialog under the tab Cross ref. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3033 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/projectconfigpages.cpp | 2 +- sources/properties/xrefproperties.cpp | 11 +- sources/properties/xrefproperties.h | 9 + sources/qetgraphicsitem/crossrefitem.cpp | 235 ++++++++++++++++++----- sources/qetgraphicsitem/crossrefitem.h | 22 ++- sources/ui/xrefpropertieswidget.cpp | 22 ++- sources/ui/xrefpropertieswidget.ui | 29 ++- 7 files changed, 273 insertions(+), 57 deletions(-) diff --git a/sources/projectconfigpages.cpp b/sources/projectconfigpages.cpp index b5f6b948e..211166cd3 100644 --- a/sources/projectconfigpages.cpp +++ b/sources/projectconfigpages.cpp @@ -288,7 +288,7 @@ void ProjectNewDiagramConfigPage::initWidgets() { conductor_ = new ConductorPropertiesWidget(); conductor_ -> setContentsMargins(0, 0, 0, 0); report_ = new ReportPropertieWidget("_"); - xref_ = new XRefPropertiesWidget(); + xref_ = new XRefPropertiesWidget(XRefProperties()); } /** diff --git a/sources/properties/xrefproperties.cpp b/sources/properties/xrefproperties.cpp index 21b50ff2e..8a80b27f6 100644 --- a/sources/properties/xrefproperties.cpp +++ b/sources/properties/xrefproperties.cpp @@ -33,6 +33,8 @@ XRefProperties::XRefProperties() */ void XRefProperties::toSettings(QSettings &settings, const QString prefix) const { settings.setValue(prefix + "showpowerctc", m_show_power_ctc); + QString display = m_display == Cross? "cross" : "contacts"; + settings.setValue(prefix + "displayhas", display); } /** @@ -43,6 +45,8 @@ void XRefProperties::toSettings(QSettings &settings, const QString prefix) const */ void XRefProperties::fromSettings(const QSettings &settings, const QString prefix) { m_show_power_ctc = settings.value(prefix + "showpowerctc", false).toBool(); + QString display = settings.value(prefix + "displayhas", "cross").toString(); + display == "cross"? m_display = Cross : m_display = Contacts; } /** @@ -52,6 +56,8 @@ void XRefProperties::fromSettings(const QSettings &settings, const QString prefi */ void XRefProperties::toXml(QDomElement &xml_element) const { xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "fasle"); + QString display = m_display == Cross? "cross" : "contacts"; + xml_element.setAttribute("displayhas", display); } /** @@ -61,10 +67,13 @@ void XRefProperties::toXml(QDomElement &xml_element) const { */ void XRefProperties::fromXml(const QDomElement &xml_element) { m_show_power_ctc = xml_element.attribute("showpowerctc") == "true"; + QString display = xml_element.attribute("displayhas", "cross"); + display == "cross"? m_display = Cross : m_display = Contacts; } bool XRefProperties::operator ==(const XRefProperties &xrp) const{ - return (m_show_power_ctc == xrp.m_show_power_ctc); + return (m_show_power_ctc == xrp.m_show_power_ctc && + m_display == xrp.m_display); } bool XRefProperties::operator !=(const XRefProperties &xrp) const { diff --git a/sources/properties/xrefproperties.h b/sources/properties/xrefproperties.h index e77d5b0f3..aa9e64690 100644 --- a/sources/properties/xrefproperties.h +++ b/sources/properties/xrefproperties.h @@ -29,6 +29,11 @@ class XRefProperties : public PropertiesInterface public: XRefProperties(); + enum DisplayHas { + Cross, + Contacts + }; + virtual void toSettings (QSettings &settings, const QString = QString()) const; virtual void fromSettings (const QSettings &settings, const QString = QString()); virtual void toXml (QDomElement &xml_element) const; @@ -40,8 +45,12 @@ class XRefProperties : public PropertiesInterface void setShowPowerContac (const bool a) {m_show_power_ctc = a;} bool showPowerContact () const {return m_show_power_ctc;} + void setDisplayHas (const DisplayHas dh) {m_display = dh;} + DisplayHas displayHas () const {return m_display;} + private: bool m_show_power_ctc; + DisplayHas m_display; }; #endif // XREFPROPERTIES_H diff --git a/sources/qetgraphicsitem/crossrefitem.cpp b/sources/qetgraphicsitem/crossrefitem.cpp index befffe5fc..ec047a00e 100644 --- a/sources/qetgraphicsitem/crossrefitem.cpp +++ b/sources/qetgraphicsitem/crossrefitem.cpp @@ -84,50 +84,14 @@ void CrossRefItem::updateLabel() { pen_.setWidthF(0.2); qp.setPen(pen_); - //calcul the size of the cross - setUpCrossBoundingRect(); + XRefProperties::DisplayHas dh = m_properties.displayHas(); + if (dh == XRefProperties::Cross) { + drawHasCross(qp); + } + else if (dh == XRefProperties::Contacts) { + drawHasContacts(qp); + } - //draw the cross - QRectF br = boundingRect(); - qp.drawLine(br.width()/2, 0, br.width()/2, br.height()); //vertical line - qp.drawLine(br.width()/2-(crossWidth/2), header, br.width()/2+(crossWidth/2), header); //horizontal line - - //draw the symbolic NO - qreal xoffset = br.width()/2 - 25; - qp.drawLine(xoffset+5, 3, xoffset+10, 3); - QPointF p1[3] = { - QPointF(xoffset+10, 0), - QPointF(xoffset+15, 3), - QPointF(xoffset+20, 3), - }; - qp.drawPolyline(p1,3); - - //draw the symbolic NC - xoffset = br.width()/2; - QPointF p2[3] = { - QPointF(xoffset+5, 3), - QPointF(xoffset+10, 3), - QPointF(xoffset+10, 0) - }; - qp.drawPolyline(p2,3); - QPointF p3[3] = { - QPointF(xoffset+9, 0), - QPointF(xoffset+15, 3), - QPointF(xoffset+20, 3), - }; - qp.drawPolyline(p3,3); - - ///keep this code for possible next feature - ///choice to use symbolic or text. - //draw the header - /*qp.setFont(QETApp::diagramTextsFont(7)); - QRectF header_rect (0,0,30,10); - qp.drawText(header_rect, Qt::AlignCenter, "NO"); - header_rect.setRect(30, 0, 30, 10); - qp.drawText(header_rect, Qt::AlignCenter, "NC");*/ - - //and fill it - fillCrossRef(qp); AddExtraInfo(qp); qp.end(); @@ -241,6 +205,181 @@ void CrossRefItem::setUpCrossBoundingRect() { m_bounding_rect = default_bounding; } +/** + * @brief CrossRefItem::drawHasCross + * Draw this crossref with a cross + * @param painter, painter to use + */ +void CrossRefItem::drawHasCross(QPainter &painter) { + //calcul the size of the cross + setUpCrossBoundingRect(); + + //draw the cross + QRectF br = boundingRect(); + painter.drawLine(br.width()/2, 0, br.width()/2, br.height()); //vertical line + painter.drawLine(br.width()/2-(crossWidth/2), header, br.width()/2+(crossWidth/2), header); //horizontal line + + //draw the symbolic NO + qreal xoffset = br.width()/2 - 25; + painter.drawLine(xoffset+5, 3, xoffset+10, 3); + QPointF p1[3] = { + QPointF(xoffset+10, 0), + QPointF(xoffset+15, 3), + QPointF(xoffset+20, 3), + }; + painter.drawPolyline(p1,3); + + //draw the symbolic NC + xoffset = br.width()/2; + QPointF p2[3] = { + QPointF(xoffset+5, 3), + QPointF(xoffset+10, 3), + QPointF(xoffset+10, 0) + }; + painter.drawPolyline(p2,3); + QPointF p3[3] = { + QPointF(xoffset+9, 0), + QPointF(xoffset+15, 3), + QPointF(xoffset+20, 3), + }; + painter.drawPolyline(p3,3); + + ///keep this code for possible next feature + ///choice to use symbolic or text. + //draw the header + /*qp.setFont(QETApp::diagramTextsFont(7)); + QRectF header_rect (0,0,30,10); + qp.drawText(header_rect, Qt::AlignCenter, "NO"); + header_rect.setRect(30, 0, 30, 10); + qp.drawText(header_rect, Qt::AlignCenter, "NC");*/ + + //and fill it + fillCrossRef(painter); +} + +/** + * @brief CrossRefItem::drawHasContacts + * Draw this crossref with symbolic contacts + * @param painter painter to use + */ +void CrossRefItem::drawHasContacts(QPainter &painter) { + m_drawed_contacts = 0; + + painter.save(); + QPen pen_; + pen_.setWidthF(0.3); + painter.setPen(pen_); + painter.setFont(QETApp::diagramTextsFont(5)); + + //Draw each linked contact + foreach (Element *elmt, m_element->linkedElements()) { + DiagramContext info = elmt->kindInformations(); + + for (int i=0; idiagram()->folioIndex() + 1); + contact_str += "-"; + contact_str += elmt->diagram()->convertPosition(elmt -> scenePos()).toString(); + drawContact(painter, option, contact_str); + } + } + + QRectF br(0,0,crossWidth, m_drawed_contacts*10+4); + m_bounding_rect = br; + m_shape_path.addRect(br); + painter.restore(); +} + +/** + * @brief CrossRefItem::drawContact + * draw one contacte, the type of contact to draw is define in ctc. + * @param painter painter to use + * @param ctc option for draw the contact, see enum CONTACTS + */ +void CrossRefItem::drawContact(QPainter &painter, int flags, QString str) { + int offset = m_drawed_contacts*10; + + //draw the basic line + painter.drawLine(0, offset+6, 8, offset+6); + painter.drawLine(16, offset+6, 24, offset+6); + + ///take exemple 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 open contact + if (flags &NO) { + painter.drawLine(8, offset+9, 16, offset+6); + } + //draw close contact + if (flags &NC) { + QPointF p1[3] = { + QPointF(8, offset+6), + QPointF(9, offset+6), + QPointF(9, offset+2.5) + }; + painter.drawPolyline(p1,3); + painter.drawLine(8, offset+3, 16, offset+6); + } + + //draw half circle for power contact + if (flags &Power) { + QRectF arc(4, offset+4, 4, 4); + if (flags &NO) + painter.drawArc(arc, 180*16, 180*16); + else + painter.drawArc(arc, 0, 180*16); + } + + // draw half circle for delay contact + if(flags &DelayOn || flags &DelayOff) { + // for delay on contact + if (flags &DelayOn) { + if (flags &NO) { + painter.drawLine(12, offset+4, 12, offset+6); + QRectF r(9.5, offset+1, 5, 3); + painter.drawArc(r, 180*16, 180*16); + } + if (flags &NC) { + painter.drawLine(QPointF(13.5, offset+2), QPointF(13.5, offset+3.5)); + QRectF r(11, offset-1, 5, 3); + painter.drawArc(r, 180*16, 180*16); + } + } + // for delay off contact + else { + if (flags &NO) { + painter.drawLine(12, offset+3, 12, offset+6); + QRectF r(9.5, offset+2, 5, 3); + painter.drawArc(r, 0, 180*16); + } + if (flags &NC) { + painter.drawLine(QPointF(13.5, offset+1), QPointF(13.5, offset+3.5)); + QRectF r(11, offset, 5, 3); + painter.drawArc(r, 0, 180*16); + } + } + } + + painter.drawText(20, offset, 30, 10, Qt::AlignRight | Qt::AlignVCenter, str); + ++m_drawed_contacts; +} + /** * @brief CrossRefItem::fillCrossRef * Fill the content of the cross ref @@ -262,13 +401,16 @@ void CrossRefItem::fillCrossRef(QPainter &painter) { painter.setFont(QETApp::diagramTextsFont(5)); qreal middle_cross = m_bounding_rect.width()/2; - //fill the NO + QString contact_str; + int i =0; + //fill the NO foreach (Element *elmt, NO_list) { + ++i; contact_str += QString::number(elmt->diagram()->folioIndex() + 1); contact_str += "-"; contact_str += elmt->diagram()->convertPosition(elmt -> scenePos()).toString(); - contact_str += "\n"; + if(NO_list.size() > i) contact_str += "\n"; } QRectF rect_(middle_cross - (crossWidth/2), header, @@ -278,11 +420,12 @@ void CrossRefItem::fillCrossRef(QPainter &painter) { //fill the NC contact_str.clear(); + i = 0; foreach (Element *elmt, NC_list) { contact_str += QString::number(elmt->diagram()->folioIndex() + 1); contact_str += "-"; contact_str += elmt->diagram()->convertPosition(elmt -> scenePos()).toString(); - contact_str += "\n"; + if (NC_list.size() > i) contact_str += "\n"; } rect_.setRect(middle_cross, header, diff --git a/sources/qetgraphicsitem/crossrefitem.h b/sources/qetgraphicsitem/crossrefitem.h index 888bc59d2..74d74584f 100644 --- a/sources/qetgraphicsitem/crossrefitem.h +++ b/sources/qetgraphicsitem/crossrefitem.h @@ -42,6 +42,14 @@ class CrossRefItem : public QGraphicsObject enum { Type = UserType + 1009 }; virtual int type() const { return Type; } + enum CONTACTS { + NO = 1, + NC = 2, + Power = 4, + DelayOn = 8, + DelayOff = 16 + }; + QRectF boundingRect() const; virtual QPainterPath shape() const; @@ -52,14 +60,17 @@ class CrossRefItem : public QGraphicsObject void autoPos(); protected: - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *e); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *e); + virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *e); + virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *e); private: void setUpCrossBoundingRect(); - void fillCrossRef(QPainter &painter); - void AddExtraInfo(QPainter &painter); + void drawHasCross (QPainter &painter); + void drawHasContacts (QPainter &painter); + void drawContact (QPainter &painter, int flags, QString str = QString()); + void fillCrossRef (QPainter &painter); + void AddExtraInfo (QPainter &painter); //Attributes private: @@ -68,6 +79,7 @@ class CrossRefItem : public QGraphicsObject QPicture m_drawing; QPainterPath m_shape_path; XRefProperties m_properties; + int m_drawed_contacts; }; #endif // CROSSREFITEM_H diff --git a/sources/ui/xrefpropertieswidget.cpp b/sources/ui/xrefpropertieswidget.cpp index c3434dacd..5ba441a4e 100644 --- a/sources/ui/xrefpropertieswidget.cpp +++ b/sources/ui/xrefpropertieswidget.cpp @@ -31,6 +31,7 @@ XRefPropertiesWidget::XRefPropertiesWidget(XRefProperties properties, QWidget *p m_properties(properties) { ui->setupUi(this); + connect(ui->m_display_has_cross_rb, SIGNAL(toggled(bool)), ui->m_show_power_cb, SLOT(setEnabled(bool))); updateDisplay(); } @@ -40,6 +41,7 @@ XRefPropertiesWidget::XRefPropertiesWidget(XRefProperties properties, QWidget *p */ XRefPropertiesWidget::~XRefPropertiesWidget() { + disconnect(ui->m_display_has_cross_rb, SIGNAL(toggled(bool)), ui->m_show_power_cb, SLOT(setEnabled(bool))); delete ui; } @@ -58,7 +60,10 @@ void XRefPropertiesWidget::setProperties(const XRefProperties &properties) { * @return the propertie edited by this widget */ XRefProperties XRefPropertiesWidget::properties() { - m_properties.setShowPowerContac(ui->cb_show_power->isChecked()); + if (ui->m_display_has_cross_rb->isChecked()) m_properties.setDisplayHas(XRefProperties::Cross); + else if (ui->m_display_has_contacts_rb->isChecked()) m_properties.setDisplayHas(XRefProperties::Contacts); + m_properties.setShowPowerContac(ui->m_show_power_cb->isChecked()); + return m_properties; } @@ -68,7 +73,9 @@ XRefProperties XRefPropertiesWidget::properties() { * @param ro */ void XRefPropertiesWidget::setReadOnly(bool ro) { - ui->cb_show_power->setDisabled(ro); + ui->m_display_has_cross_rb->setDisabled(ro); + ui->m_display_has_contacts_rb->setDisabled(ro); + ui->m_show_power_cb->setDisabled(ro); } /** @@ -76,5 +83,14 @@ void XRefPropertiesWidget::setReadOnly(bool ro) { * Update display with the content of the properties */ void XRefPropertiesWidget::updateDisplay() { - ui->cb_show_power->setChecked(m_properties.showPowerContact()); + XRefProperties::DisplayHas dh = m_properties.displayHas(); + if (dh == XRefProperties::Cross) { + ui->m_display_has_cross_rb->setChecked(true); + } + else if (dh == XRefProperties::Contacts) { + ui->m_display_has_contacts_rb->setChecked(true); + } + + ui->m_show_power_cb->setChecked(m_properties.showPowerContact()); + ui->m_show_power_cb->setDisabled(!ui->m_display_has_cross_rb->isChecked()); } diff --git a/sources/ui/xrefpropertieswidget.ui b/sources/ui/xrefpropertieswidget.ui index a68522154..477fcf0ef 100644 --- a/sources/ui/xrefpropertieswidget.ui +++ b/sources/ui/xrefpropertieswidget.ui @@ -15,7 +15,34 @@ - + + + Représentation: + + + + + + + + Afficher en croix + + + + + + + Afficher en contacts + + + + + + + + + + Afficher les contacts de puissance dans la croix