From e3cc8d449de499ee012ff66a2e33fbd604517d09 Mon Sep 17 00:00:00 2001 From: blacksun Date: Thu, 23 Oct 2014 08:48:30 +0000 Subject: [PATCH] Improve signal of position changed, between linked elements git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3394 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/qetgraphicsitem/crossrefitem.cpp | 21 +++++++++++---------- sources/qetgraphicsitem/masterelement.cpp | 6 ++++-- sources/qetgraphicsitem/qetgraphicsitem.cpp | 4 +--- sources/qetgraphicsitem/qetgraphicsitem.h | 1 - sources/qetgraphicsitem/reportelement.cpp | 6 ++++-- sources/qetgraphicsitem/slaveelement.cpp | 6 ++++-- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/sources/qetgraphicsitem/crossrefitem.cpp b/sources/qetgraphicsitem/crossrefitem.cpp index 5d94da5ff..31128ae5b 100644 --- a/sources/qetgraphicsitem/crossrefitem.cpp +++ b/sources/qetgraphicsitem/crossrefitem.cpp @@ -37,14 +37,15 @@ CrossRefItem::CrossRefItem(Element *elmt) : m_element (elmt) { m_properties = elmt->diagram()->defaultXRefProperties(elmt->kindInformations()["type"].toString()); - 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()), this, SLOT(updateProperties())); + + 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()), this, SLOT(updateProperties())); //set specific behavior related to the parent item. if(m_properties.snapTo() == XRefProperties::Bottom) { - connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(autoPos())); - connect(elmt, SIGNAL(rotationChanged()), this, SLOT(autoPos())); + connect(elmt, SIGNAL(yChanged()), this, SLOT(autoPos())); + connect(elmt, SIGNAL(rotationChanged()), this, SLOT(autoPos())); } else { setTextParent(); } @@ -57,12 +58,12 @@ CrossRefItem::CrossRefItem(Element *elmt) : */ CrossRefItem::~CrossRefItem() { if(m_properties.snapTo() == XRefProperties::Bottom) { - disconnect(m_element, SIGNAL(positionChange(QPointF)), this, SLOT(autoPos())); - disconnect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos())); + disconnect(m_element, SIGNAL(yChanged()), this, SLOT(autoPos())); + disconnect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos())); } - disconnect(m_element, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); - disconnect(m_element->diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); - disconnect(m_element->diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateProperties())); + disconnect(m_element, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); + disconnect(m_element -> diagram() -> project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); + disconnect(m_element -> diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateProperties())); } /** diff --git a/sources/qetgraphicsitem/masterelement.cpp b/sources/qetgraphicsitem/masterelement.cpp index b798d535f..5c2d50f3f 100644 --- a/sources/qetgraphicsitem/masterelement.cpp +++ b/sources/qetgraphicsitem/masterelement.cpp @@ -56,7 +56,8 @@ void MasterElement::linkToElement(Element *elmt) { elmt->linkToElement(this); if (!cri_) cri_ = new CrossRefItem(this); //create cross ref item if not yet - connect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel())); + connect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel())); + connect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel())); cri_->updateLabel(); } } @@ -86,7 +87,8 @@ void MasterElement::unlinkElement(Element *elmt) { elmt->unlinkElement(this); //update the graphics cross ref - disconnect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel())); + disconnect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel())); + disconnect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel())); if (linkedElements().isEmpty()) { delete cri_; diff --git a/sources/qetgraphicsitem/qetgraphicsitem.cpp b/sources/qetgraphicsitem/qetgraphicsitem.cpp index 801431413..4f5cb9d36 100644 --- a/sources/qetgraphicsitem/qetgraphicsitem.cpp +++ b/sources/qetgraphicsitem/qetgraphicsitem.cpp @@ -29,8 +29,7 @@ QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent): is_movable_(true), first_move_(true), snap_to_grid_(true) -{ -} +{} QetGraphicsItem::~QetGraphicsItem() {} @@ -53,7 +52,6 @@ void QetGraphicsItem::setPos(const QPointF &p) { if (pp == pos() || !is_movable_) return; if (scene() && snap_to_grid_) { QGraphicsItem::setPos(pp); - emit positionChange(pos()); } else QGraphicsItem::setPos(pp); } diff --git a/sources/qetgraphicsitem/qetgraphicsitem.h b/sources/qetgraphicsitem/qetgraphicsitem.h index 21020d275..0001fa3fd 100644 --- a/sources/qetgraphicsitem/qetgraphicsitem.h +++ b/sources/qetgraphicsitem/qetgraphicsitem.h @@ -40,7 +40,6 @@ class QetGraphicsItem : public QGraphicsObject { virtual QString name()const {return QString("");} signals: - void positionChange(QPointF); public slots: diff --git a/sources/qetgraphicsitem/reportelement.cpp b/sources/qetgraphicsitem/reportelement.cpp index 0f51c194b..6e9d1c073 100644 --- a/sources/qetgraphicsitem/reportelement.cpp +++ b/sources/qetgraphicsitem/reportelement.cpp @@ -55,7 +55,8 @@ void ReportElement::linkToElement(Element * elmt) { if ((elmt->linkType() == inverse_report) && i) { unlinkAllElements(); connected_elements << elmt; - connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel())); + connect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel())); + connect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel())); connect(diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); updateLabel(); elmt->linkToElement(this); @@ -71,7 +72,8 @@ void ReportElement::unlinkAllElements(){ QList tmp_elmt = connected_elements; foreach(Element *elmt, connected_elements) { - disconnect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel())); + disconnect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel())); + disconnect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel())); disconnect(diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); } connected_elements.clear(); diff --git a/sources/qetgraphicsitem/slaveelement.cpp b/sources/qetgraphicsitem/slaveelement.cpp index 47ec93954..8c7bc1536 100644 --- a/sources/qetgraphicsitem/slaveelement.cpp +++ b/sources/qetgraphicsitem/slaveelement.cpp @@ -56,7 +56,8 @@ void SlaveElement::linkToElement(Element *elmt) { if(!isFree()) unlinkAllElements(); connected_elements << elmt; updateLabel(); - connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel())); + connect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel())); + connect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel())); connect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); elmt->linkToElement(this); } @@ -84,7 +85,8 @@ void SlaveElement::unlinkElement(Element *elmt) { //Ensure elmt is linked to this element if (connected_elements.contains(elmt)) { connected_elements.removeOne(elmt); - disconnect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel())); + disconnect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel())); + disconnect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel())); disconnect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); delete Xref_item; Xref_item = NULL; updateLabel();