[qet] [3426] Master element: improve how the comment is displayed when there isn 't linked to a slave

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


Revision: 3426
Author:   blacksun
Date:     2014-10-31 11:22:46 +0100 (Fri, 31 Oct 2014)
Log Message:
-----------
Master element: improve how the comment is displayed when there isn't linked to a slave

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

Modified: trunk/sources/qetgraphicsitem/crossrefitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.cpp	2014-10-30 22:20:35 UTC (rev 3425)
+++ trunk/sources/qetgraphicsitem/crossrefitem.cpp	2014-10-31 10:22:46 UTC (rev 3426)
@@ -56,15 +56,7 @@
  * @brief CrossRefItem::~CrossRefItem
  * Default destructor
  */
-CrossRefItem::~CrossRefItem() {
-	if(m_properties.snapTo() == XRefProperties::Bottom) {
-		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()));
-}
+CrossRefItem::~CrossRefItem() {}
 
 /**
  * @brief CrossRefItem::boundingRect
@@ -163,8 +155,10 @@
  * Update the content of the item
  */
 void CrossRefItem::updateLabel() {
-	//init the shape
-	m_shape_path= QPainterPath();
+	//init the shape and bounding rect
+	m_shape_path    = QPainterPath();
+	m_bounding_rect = QRectF();
+
 	//init the painter
 	QPainter qp;
 	qp.begin(&m_drawing);
@@ -173,13 +167,15 @@
 	qp.setPen(pen_);
 	qp.setFont(QETApp::diagramTextsFont(5));
 
-	XRefProperties::DisplayHas dh = m_properties.displayHas();
-	if (dh == XRefProperties::Cross) {
-		drawHasCross(qp);
+	//Draw cross or contact, only if master element is linked.
+	if (! m_element->linkedElements().isEmpty()) {
+		XRefProperties::DisplayHas dh = m_properties.displayHas();
+
+		if (dh == XRefProperties::Cross)
+			drawHasCross(qp);
+		else if (dh == XRefProperties::Contacts)
+			drawHasContacts(qp);
 	}
-	else if (dh == XRefProperties::Contacts) {
-		drawHasContacts(qp);
-	}
 
 	AddExtraInfo(qp);
 	qp.end();
@@ -371,8 +367,8 @@
 			else if (state == "SW") option = SW;
 
 			QString type = info["type"].toString();
-			if (type == "power") option += Power;
-			else if (type == "delayOn") option += DelayOn;
+				 if (type == "power")    option += Power;
+			else if (type == "delayOn")  option += DelayOn;
 			else if (type == "delayOff") option += DelayOff;
 
 			drawContact(painter, option, elementPositionText(elmt));

Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp	2014-10-30 22:20:35 UTC (rev 3425)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp	2014-10-31 10:22:46 UTC (rev 3426)
@@ -17,7 +17,6 @@
 */
 #include "masterelement.h"
 #include "crossrefitem.h"
-#include "commentitem.h"
 
 /**
  * @brief MasterElement::MasterElement
@@ -29,8 +28,7 @@
  */
 MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
 	CustomElement(location, qgi, s, state),
-	cri_ (nullptr),
-	m_ci (nullptr)
+	cri_ (nullptr)
 {
 	link_type_ = Master;
 	connect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
@@ -42,8 +40,6 @@
  */
 MasterElement::~MasterElement() {
 	unlinkAllElements();
-	if (m_ci) delete m_ci;
-	disconnect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
 }
 
 /**
@@ -63,13 +59,6 @@
 		connect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
 		connect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
 		cri_ -> updateLabel();
-
-		//If there is a comment item, we delete it
-		//because cross ref item display comment too.
-		if (m_ci) {
-			delete m_ci;
-			m_ci = nullptr;
-		}
 	}
 }
 
@@ -101,14 +90,8 @@
 		disconnect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
 		disconnect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
 
-		if (linkedElements().isEmpty()) {
-			delete cri_;
-			cri_ = nullptr;
-			updateLabel();
-		}
-		else {
-			cri_->updateLabel();
-		}
+		if (aboutDeleteXref()) return;
+		cri_ -> updateLabel();
 	}
 }
 
@@ -120,10 +103,7 @@
 void MasterElement::initLink(QETProject *project) {
 	//Create the link with other element if needed
 	CustomElement::initLink(project);
-
-	//If no link that mean there are no cross ref item (cri)
-	//So we call @updateLabel for add comment item (m_ci) if needed.
-	if (!cri_) updateLabel();
+	updateLabel();
 }
 
 /**
@@ -140,19 +120,39 @@
 				setTaggedText("label", "_", false):
 				setTaggedText("label", label, true);
 
-	if (cri_) return;
+	//Delete or update the xref
+	if (cri_) {
+		aboutDeleteXref();
+	}
+	else {
+		QString comment   = elementInformations()["comment"].toString();
+		bool    must_show = elementInformations().keyMustShow("comment");
 
-	//At this point there isn't a cross ref item displayed,
-	//but if element have comment and must be show, we add a comment item
+		if (! (comment.isEmpty() || !must_show)) {
+			cri_ = new CrossRefItem(this);
+		}
+	}
+}
 
+/**
+ * @brief MasterElement::aboutDeleteXref
+ * Check if Xref item must be displayed, if not, delete it.
+ * If Xref item is deleted or already not used (nullptr) return true;
+ * Else return false if Xref item is used
+ * @return
+ */
+bool MasterElement::aboutDeleteXref() {
+	if(!cri_) return true;
+
 	QString comment   = elementInformations()["comment"].toString();
 	bool    must_show = elementInformations().keyMustShow("comment");
 
-	if (!(comment.isEmpty() || !must_show) && !m_ci) {
-		m_ci = new CommentItem(this);
+	//Delete Xref item if there isn't reason to display it
+	if (linkedElements().isEmpty() && (comment.isEmpty() || !must_show)) {
+		delete cri_;
+		cri_ = nullptr;
+		return true;
 	}
-	else if ((comment.isEmpty() || !must_show) && m_ci) {
-		delete m_ci;
-		m_ci = nullptr;
-	}
+
+	return false;
 }

Modified: trunk/sources/qetgraphicsitem/masterelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.h	2014-10-30 22:20:35 UTC (rev 3425)
+++ trunk/sources/qetgraphicsitem/masterelement.h	2014-10-31 10:22:46 UTC (rev 3426)
@@ -21,7 +21,6 @@
 #include "customelement.h"
 
 class CrossRefItem;
-class CommentItem;
 
 /**
  * @brief The MasterElement class
@@ -48,8 +47,10 @@
 		void updateLabel();
 
 	private:
+		bool aboutDeleteXref ();
+
+	private:
 		CrossRefItem *cri_;
-		CommentItem *m_ci;
 };
 
 #endif // MASTERELEMENT_H


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