diff --git a/sources/qetgraphicsitem/crossrefitem.cpp b/sources/qetgraphicsitem/crossrefitem.cpp index a17ad2c22..3aa48f9c1 100644 --- a/sources/qetgraphicsitem/crossrefitem.cpp +++ b/sources/qetgraphicsitem/crossrefitem.cpp @@ -31,15 +31,14 @@ * @param elmt element to dispaly the cross ref * @param parent parent QetGraphicsItem */ -CrossRefItem::CrossRefItem(Element *elmt, QetGraphicsItem *parent) : - QetGraphicsItem(parent), +CrossRefItem::CrossRefItem(Element *elmt, QGraphicsItem *parent) : + QGraphicsObject(parent), element_ (elmt) { - snap_to_grid_=false; - setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable); + setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable); connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(autoPos())); connect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); - connect(diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); + connect(elmt->diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); updateLabel(); } @@ -50,7 +49,7 @@ CrossRefItem::CrossRefItem(Element *elmt, QetGraphicsItem *parent) : CrossRefItem::~CrossRefItem() { disconnect(element_, SIGNAL(positionChange(QPointF)), this, SLOT(autoPos())); disconnect(element_, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); - disconnect(diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); + disconnect(element_->diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); } /** @@ -189,7 +188,7 @@ void CrossRefItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti */ void CrossRefItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { element_->setHighlighted(true); - QetGraphicsItem::mouseMoveEvent(e); + QGraphicsObject::mouseMoveEvent(e); } /** @@ -199,7 +198,7 @@ void CrossRefItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { */ void CrossRefItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { element_->setHighlighted(false); - QetGraphicsItem::mouseReleaseEvent(e); + QGraphicsObject::mouseReleaseEvent(e); } /** diff --git a/sources/qetgraphicsitem/crossrefitem.h b/sources/qetgraphicsitem/crossrefitem.h index fd86cc1c9..936753c5f 100644 --- a/sources/qetgraphicsitem/crossrefitem.h +++ b/sources/qetgraphicsitem/crossrefitem.h @@ -29,13 +29,13 @@ class element; * It's the responsability of the parent to informe displayed slave are moved, * by calling the slot @updateLabel */ -class CrossRefItem : public QetGraphicsItem +class CrossRefItem : public QGraphicsObject { Q_OBJECT //Methods public: - explicit CrossRefItem(Element *elmt, QetGraphicsItem *parent = 0); + explicit CrossRefItem(Element *elmt, QGraphicsItem *parent = 0); ~CrossRefItem(); QRectF boundingRect() const; diff --git a/sources/qetgraphicsitem/masterelement.cpp b/sources/qetgraphicsitem/masterelement.cpp index 3eebe7c20..df2527b99 100644 --- a/sources/qetgraphicsitem/masterelement.cpp +++ b/sources/qetgraphicsitem/masterelement.cpp @@ -55,7 +55,10 @@ void MasterElement::linkToElement(Element *elmt) { elmt->linkToElement(this); if (elmt->kindInformations()["type"].toString() != "power") { - if (!cri_) cri_ = new CrossRefItem(this, this); //create cross ref item if not yet + 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(); } @@ -93,6 +96,7 @@ void MasterElement::unlinkElement(Element *elmt) { if (elmt->kindInformations()["type"].toString() != "power") delete_cri = false; if (delete_cri) { + diagram()->removeItem(cri_); delete cri_; cri_ = 0; }