diff --git a/sources/qetgraphicsitem/crossrefitem.cpp b/sources/qetgraphicsitem/crossrefitem.cpp index 3aa48f9c1..7b2cb23ae 100644 --- a/sources/qetgraphicsitem/crossrefitem.cpp +++ b/sources/qetgraphicsitem/crossrefitem.cpp @@ -35,10 +35,12 @@ CrossRefItem::CrossRefItem(Element *elmt, QGraphicsItem *parent) : QGraphicsObject(parent), element_ (elmt) { + m_properties = elmt->diagram()->defaultXRefProperties(); setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable); connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(autoPos())); connect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); connect(elmt->diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); + connect(elmt->diagram(), SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SLOT(updateLabel())); updateLabel(); } @@ -276,7 +278,7 @@ void CrossRefItem::fillCrossRef(QPainter &painter) { //find each no and nc of connected element to element_ foreach (Element *elmt, element_->linkedElements()) { - if (elmt->kindInformations()["type"].toString() == "power") continue; + if (elmt->kindInformations()["type"].toString() == "power" && !m_properties.showPowerContact()) continue; QString state = elmt->kindInformations()["state"].toString(); if (state == "NO") NO_list << elmt; else if (state == "NC") NC_list << elmt; diff --git a/sources/qetgraphicsitem/crossrefitem.h b/sources/qetgraphicsitem/crossrefitem.h index 936753c5f..60278fabb 100644 --- a/sources/qetgraphicsitem/crossrefitem.h +++ b/sources/qetgraphicsitem/crossrefitem.h @@ -19,6 +19,7 @@ #define CROSSREFITEM_H #include "qetgraphicsitem/qetgraphicsitem.h" +#include"properties/xrefproperties.h" class element; /** @@ -63,6 +64,7 @@ class CrossRefItem : public QGraphicsObject QRectF bounding_rect_ , text_rect_; QPicture drawing_; QPainterPath shape_path_; + XRefProperties m_properties; }; #endif // CROSSREFITEM_H diff --git a/sources/qetgraphicsitem/masterelement.cpp b/sources/qetgraphicsitem/masterelement.cpp index df2527b99..55b566af8 100644 --- a/sources/qetgraphicsitem/masterelement.cpp +++ b/sources/qetgraphicsitem/masterelement.cpp @@ -54,15 +54,15 @@ void MasterElement::linkToElement(Element *elmt) { connected_elements << elmt; elmt->linkToElement(this); - if (elmt->kindInformations()["type"].toString() != "power") { - if (!cri_) { + if (elmt->kindInformations()["type"].toString() == "power" && !diagram()->defaultXRefProperties().showPowerContact()) return; + + if (!cri_) { cri_ = new CrossRefItem(this); //create cross ref item if not yet diagram()->addItem(cri_); } connect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel())); cri_->updateLabel(); } - } } /** @@ -92,8 +92,17 @@ void MasterElement::unlinkElement(Element *elmt) { disconnect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel())); bool delete_cri = true; - foreach(Element *elmt, linkedElements()) - if (elmt->kindInformations()["type"].toString() != "power") delete_cri = false; + + //if power contact isn't show, make sure they are only power contacts linked + //or nothing befor remove cri_ + if (!diagram()->defaultXRefProperties().showPowerContact()) { + foreach(Element *elmt, linkedElements()) + if (elmt->kindInformations()["type"].toString() != "power") delete_cri = false; + } + //else only make sur list is empty + else { + if (!linkedElements().isEmpty()) delete_cri = false; + } if (delete_cri) { diagram()->removeItem(cri_); @@ -106,6 +115,25 @@ void MasterElement::unlinkElement(Element *elmt) { } } +/** + * @brief MasterElement::itemChange + * Réimplemente the protected method item change + * This is used to make connection/disconnection when this item is added/removed from a diagram + * @return + */ +QVariant MasterElement::itemChange(GraphicsItemChange change, const QVariant &value) { + if (change == QGraphicsItem::ItemSceneChange) { + if (diagram()) + disconnect(diagram(), SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SLOT(reLink())); + } + else if (change == QGraphicsItem::ItemSceneHasChanged) { + if (diagram()) + connect(diagram(), SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SLOT(reLink())); + } + return QetGraphicsItem::itemChange(change, value); +} + + /** * @brief MasterElement::updateLabel * update label of this element @@ -119,3 +147,17 @@ void MasterElement::updateLabel() { setTaggedText("label", "_", false): setTaggedText("label", label, true); } + +/** + * @brief MasterElement::reLink + * Relink all linked element. + * this method is notably used when xref properties changes + * for update the content of th e XRef + */ +void MasterElement::reLink() { + QList elmt_list = linkedElements(); + unlinkAllElements(); + foreach (Element *elmt, elmt_list) { + linkToElement(elmt); + } +} diff --git a/sources/qetgraphicsitem/masterelement.h b/sources/qetgraphicsitem/masterelement.h index 32d1170c5..cfec172c7 100644 --- a/sources/qetgraphicsitem/masterelement.h +++ b/sources/qetgraphicsitem/masterelement.h @@ -31,12 +31,18 @@ class MasterElement : public CustomElement virtual void linkToElement(Element *elmt); virtual void unlinkAllElements(); virtual void unlinkElement(Element *elmt); + + protected: + QVariant itemChange(GraphicsItemChange change, const QVariant &value); signals: public slots: void updateLabel(); + private slots: + void reLink(); + private: CrossRefItem *cri_; };