[qet] [3066] Xref item: minor improvement

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


Revision: 3066
Author:   blacksun
Date:     2014-05-13 21:28:11 +0200 (Tue, 13 May 2014)
Log Message:
-----------
Xref item: minor improvement

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

Modified: trunk/sources/qetgraphicsitem/crossrefitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.cpp	2014-05-13 17:37:14 UTC (rev 3065)
+++ trunk/sources/qetgraphicsitem/crossrefitem.cpp	2014-05-13 19:28:11 UTC (rev 3066)
@@ -89,6 +89,27 @@
 	return txt;
 }
 
+/**
+ * @brief CrossRefItem::allElementsPositionText
+ * Return the text of all elements linked to @m_element, in several QString
+ * according to the type of linked elements. Each text of elements are separate by "\n"
+ * @param no_str the string of NO contacts
+ * @param nc_str the string of NC contacts
+ * @param add_prefix must add prefix to text (true) or not (false);
+ */
+void CrossRefItem::allElementsPositionText(QString &no_str, QString &nc_str, const bool &add_prefix) const {
+	QString *tmp_str;
+	foreach (Element *elmt, m_element->linkedElements()) {
+		QString state = elmt->kindInformations()["state"].toString();
+
+		if (state == "NO") tmp_str = &no_str;
+		else if (state == "NC") tmp_str = &nc_str;
+
+		if (!tmp_str->isEmpty()) *tmp_str += "\n";
+		*tmp_str += elementPositionText(elmt, add_prefix);
+	}
+}
+
 void CrossRefItem::setProperties(const XRefProperties &xrp) {
 	if (m_properties != xrp) {
 		m_properties = xrp;
@@ -256,17 +277,9 @@
 	//No need to calcul if nothing is linked
 	if (!m_element->isFree()) {
 
-		QString no_str, nc_str, *tmp_str;
-		foreach (Element *elmt, m_element->linkedElements()) {
-			QString state = elmt->kindInformations()["state"].toString();
+		QString no_str, nc_str;
+		allElementsPositionText(no_str, nc_str, true);
 
-			if (state == "NO") tmp_str = &no_str;
-			else if (state == "NC") tmp_str = &nc_str;
-
-			if (!tmp_str->isEmpty()) *tmp_str += "\n";
-			*tmp_str += elementPositionText(elmt, true);
-		}
-
 		//Adjust the size of default_bounding if needed.
 		//We calcule the size by using a single text
 		//because in the method fillCrossRef, the text is draw like this (aka single text)
@@ -435,46 +448,18 @@
 void CrossRefItem::fillCrossRef(QPainter &painter) {
 	if (m_element->isFree()) return;
 
-	QList <Element *> NO_list;
-	QList <Element *> NC_list;
+	QString no_str, nc_str;
+	allElementsPositionText(no_str, nc_str, true);
 
-	//find each no and nc of connected element to m_element
-	foreach (Element *elmt, m_element->linkedElements()) {
-		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;
-	}
-
 	qreal middle_cross = m_bounding_rect.width()/2;
 
-	QString contact_str;
-	int i =0;
-	//fill the NO
-	foreach (Element *elmt, NO_list) {
-		++i;
-		contact_str += elementPositionText(elmt, true);
-		if(NO_list.size() > i) contact_str += "\n";
-	}
-	QRectF rect_(0,
-				 header,
-				 middle_cross,
-				 m_bounding_rect.height()-header);
-	painter.drawText(rect_, Qt::AlignTop | Qt::AlignLeft, contact_str);
+	QRectF rect_(0, header, middle_cross, boundingRect().height()-header);
+	painter.drawText(rect_, Qt::AlignTop | Qt::AlignLeft, no_str);
 
-	//fill the NC
-	contact_str.clear();
-	i = 0;
-	foreach (Element *elmt, NC_list) {
-		++i;
-		contact_str += elementPositionText(elmt, true);
-		if (NC_list.size() > i) contact_str += "\n";
-	}
-	rect_.setRect(middle_cross,
-				  header,
-				  middle_cross,
-				  m_bounding_rect.height()-header);
-	painter.drawText(rect_, Qt::AlignTop | Qt::AlignRight, contact_str);
+	rect_.moveTopLeft(QPointF (middle_cross, header));
+	painter.drawText(rect_, Qt::AlignTop | Qt::AlignRight, nc_str);
+
+
 }
 
 /**
@@ -540,3 +525,4 @@
 		return;
 	}
 }
+

Modified: trunk/sources/qetgraphicsitem/crossrefitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.h	2014-05-13 17:37:14 UTC (rev 3065)
+++ trunk/sources/qetgraphicsitem/crossrefitem.h	2014-05-13 19:28:11 UTC (rev 3066)
@@ -53,6 +53,7 @@
 	QRectF boundingRect			() const;
 	virtual QPainterPath shape	() const;
 	QString elementPositionText (const Element *elmt, const bool &add_prefix = false) const;
+	void allElementsPositionText (QString &no_str, QString &nc_str,const bool &add_prefix = false) const;
 
 	signals:
 
@@ -87,3 +88,4 @@
 };
 
 #endif // CROSSREFITEM_H
+


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