[qet] [3035] cross ref item: bugfix

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 3035
Author:   blacksun
Date:     2014-04-28 21:00:49 +0200 (Mon, 28 Apr 2014)
Log Message:
-----------
cross ref item: bugfix

Modified Paths:
--------------
    trunk/sources/qetgraphicsitem/crossrefitem.cpp
    trunk/sources/qetgraphicsitem/crossrefitem.h
    trunk/sources/qetgraphicsitem/masterelement.cpp
    trunk/sources/qetgraphicsitem/masterelement.h

Modified: trunk/sources/qetgraphicsitem/crossrefitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.cpp	2014-04-28 16:46:13 UTC (rev 3034)
+++ trunk/sources/qetgraphicsitem/crossrefitem.cpp	2014-04-28 19:00:49 UTC (rev 3035)
@@ -40,7 +40,7 @@
 	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()));
+	connect(elmt->diagram(), SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SLOT(setProperties(XRefProperties)));
 	updateLabel();
 }
 
@@ -52,6 +52,7 @@
 	disconnect(m_element, SIGNAL(positionChange(QPointF)), 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(XRefProperties)), this, SLOT(setProperties(XRefProperties)));
 }
 
 /**
@@ -70,6 +71,13 @@
 	return m_shape_path;
 }
 
+void CrossRefItem::setProperties(XRefProperties xrp) {
+	if (m_properties != xrp) {
+		m_properties = xrp;
+		updateLabel();
+	}
+}
+
 /**
  * @brief CrossRefItem::updateLabel
  * Update the content of the item

Modified: trunk/sources/qetgraphicsitem/crossrefitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.h	2014-04-28 16:46:13 UTC (rev 3034)
+++ trunk/sources/qetgraphicsitem/crossrefitem.h	2014-04-28 19:00:49 UTC (rev 3035)
@@ -56,6 +56,7 @@
 	signals:
 
 	public slots:
+	void setProperties (XRefProperties xrp);
 	void updateLabel();
 	void autoPos();
 

Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp	2014-04-28 16:46:13 UTC (rev 3034)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp	2014-04-28 19:00:49 UTC (rev 3035)
@@ -88,53 +88,37 @@
 	if (connected_elements.contains(elmt)) {
 		connected_elements.removeOne(elmt);
 		elmt->unlinkElement(this);
-		//update the graphics cross ref
-		disconnect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel()));
 
-		bool delete_cri = true;
+		if (cri_) {
+			//update the graphics cross ref
+			disconnect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel()));
 
-		//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;
-		}
+			bool delete_cri = true;
 
-		if (delete_cri) {
-			diagram()->removeItem(cri_);
-			delete cri_;
-			cri_ = 0;
+			//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_);
+				delete cri_;
+				cri_ = 0;
+			}
+			else {
+				cri_->updateLabel();
+			}
 		}
-		else {
-			cri_->updateLabel();
-		}
 	}
 }
 
 /**
- * @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
  */
@@ -147,17 +131,3 @@
 				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 <Element *> elmt_list = linkedElements();
-	unlinkAllElements();
-	foreach (Element *elmt, elmt_list) {
-		linkToElement(elmt);
-	}
-}

Modified: trunk/sources/qetgraphicsitem/masterelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.h	2014-04-28 16:46:13 UTC (rev 3034)
+++ trunk/sources/qetgraphicsitem/masterelement.h	2014-04-28 19:00:49 UTC (rev 3035)
@@ -31,18 +31,12 @@
 	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_;
 };


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/