[qet] [3363] Conductor : minor change and replace some methode by function.

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


Revision: 3363
Author:   blacksun
Date:     2014-10-07 21:51:26 +0200 (Tue, 07 Oct 2014)
Log Message:
-----------
Conductor : minor change and replace some methode by function.

Modified Paths:
--------------
    trunk/sources/diagramcommands.cpp
    trunk/sources/qetgraphicsitem/conductor.cpp
    trunk/sources/qetgraphicsitem/conductor.h
    trunk/sources/qetgraphicsitem/conductortextitem.cpp

Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp	2014-10-06 22:06:26 UTC (rev 3362)
+++ trunk/sources/diagramcommands.cpp	2014-10-07 19:51:26 UTC (rev 3363)
@@ -286,7 +286,7 @@
 			QList <Conductor *> conductor_list;
 			conductor_list << c -> relatedPotentialConductors(false).toList();
 			if (conductor_list.count()) {
-				conductor_list.first() -> adjustTextItemPosition();
+				conductor_list.first() -> calculateTextItemPosition();
 			}
 		}
 	}
@@ -780,7 +780,7 @@
 		if (ConductorTextItem *cti = qgraphicsitem_cast<ConductorTextItem *>(dti)) {
 			cti -> forceRotateByUser(previous_rotate_by_user_[cti]);
 			(cti -> wasRotateByUser()) ? cti -> rotateBy(-applied_rotation_angle_) :
-										 cti -> parentConductor() -> adjustTextItemPosition();
+										 cti -> parentConductor() -> calculateTextItemPosition();
 		}
 		else {dti -> rotateBy(-applied_rotation_angle_);}
 	}

Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp	2014-10-06 22:06:26 UTC (rev 3362)
+++ trunk/sources/qetgraphicsitem/conductor.cpp	2014-10-07 19:51:26 UTC (rev 3363)
@@ -1090,18 +1090,11 @@
 }
 
 /**
-	@return La longueur totale du conducteur
-*/
-qreal Conductor::length() {
-	qreal length = 0.0;
-	
-	ConductorSegment *s = segments;
-	while (s -> hasNextSegment()) {
-		length += qAbs(s -> length());
-		s = s -> nextSegment();
-	}
-	
-	return(length);
+ * @brief Conductor::length
+ * @return the length of this conductor
+ */
+qreal Conductor::length() const{
+	return path().length();
 }
 
 /**
@@ -1191,16 +1184,8 @@
 	if (!text_item || !diagram()) return;
 
 	if (diagram() -> defaultConductorProperties.m_one_text_per_folio == true) {
-		QSet<Conductor *> conductor_list = relatedPotentialConductors(false);
-		Conductor *longuest_conductor = this;
+		Conductor *longuest_conductor = longuestConductorInPotential(this);
 
-		//Search the longuest conductor
-		foreach (Conductor *c, conductor_list) {
-			if (c -> length() > longuest_conductor -> length()) {
-				longuest_conductor = c;
-			}
-		}
-
 		//The longuest conductor isn't this conductor
 		//we call calculateTextItemPosition of the longuest conductor
 		if(longuest_conductor != this) {
@@ -1210,7 +1195,7 @@
 
 		//At this point this conductor is the longuest conductor
 		//we hide all text of conductor_list
-		foreach (Conductor *c, conductor_list) {
+		foreach (Conductor *c, relatedPotentialConductors(false)) {
 			c -> textItem() -> setVisible(false);
 		}
 	}
@@ -1351,15 +1336,6 @@
 }
 
 /**
-	S'assure que le texte du conducteur est a une position raisonnable
-	Cette methode ne fait rien si ce conducteur n'affiche pas son champ de
-	texte.
-*/
-void Conductor::adjustTextItemPosition() {
-	calculateTextItemPosition();
-}
-
-/**
 	@return true si le conducteur est mis en evidence
 */
 Conductor::Highlight Conductor::highlight() const {
@@ -1417,17 +1393,6 @@
 	}
 }
 
-/**
-	@return les conducteurs avec lesquels ce conducteur partage des bornes
-	communes
-*/
-QSet<Conductor *> Conductor::relatedConductors() const {
-	QList<Conductor *> other_conductors_list = terminal1 -> conductors();
-	other_conductors_list += terminal2 -> conductors();
-	QSet<Conductor *> other_conductors = other_conductors_list.toSet();
-	other_conductors.remove(const_cast<Conductor *>(this));
-	return(other_conductors);
-}
 
 /**
  * @brief Conductor::relatedPotentialConductors
@@ -1527,20 +1492,6 @@
 }
 
 /**
-	@param a reel
-	@param b reel
-	@param c reel
-	@return true si a est entre b et c ou est egal a l'un des deux
-*/
-bool isBetween(qreal a, qreal b, qreal c) {
-	if (b <= c) {
-		return(a >= b && a <= c);
-	} else {
-		return(a <= b && a >= c);
-	}
-}
-
-/**
 	@param a point
 	@param b point
 	@param c point
@@ -1560,7 +1511,7 @@
 	QList<QPointF> junctions_list;
 	
 	// pour qu'il y ait des jonctions, il doit y avoir d'autres conducteurs et des bifurcations
-	QSet<Conductor *> other_conductors = relatedConductors();
+	QList<Conductor *> other_conductors = relatedConductors(this);
 	QList<ConductorBend> bends_list = bends();
 	if (other_conductors.isEmpty() || bends_list.isEmpty()) {
 		return(junctions_list);
@@ -1787,3 +1738,32 @@
 		return(points.at(point_index));
 	}
 }
+
+/**
+ * @brief longuestConductorInPotential
+ * @param conductor : a conductor in the potential to search
+ * @param all_diagram : true -> search in the whole project, false -> search only in the diagram of conductor
+ * @return the longuest conductor in the same potential of conductor
+ */
+Conductor * longuestConductorInPotential(Conductor *conductor, bool all_diagram) {
+	Conductor *longuest_conductor = conductor;
+	//Search the longuest conductor
+	foreach (Conductor *c, conductor -> relatedPotentialConductors(all_diagram))
+		if (c -> length() > longuest_conductor -> length())
+			longuest_conductor = c;
+
+	return longuest_conductor;
+}
+
+/**
+ * @brief relatedConductors
+ * @param conductor
+ * @return return all conductors who share the same terminals of @conductor given as parametre,
+ * except @conductor himself.
+ */
+QList <Conductor *> relatedConductors(const Conductor *conductor) {
+	QList<Conductor *> other_conductors_list = conductor -> terminal1 -> conductors();
+	other_conductors_list << conductor -> terminal2->conductors();
+	other_conductors_list.removeAll(const_cast<Conductor *> (conductor));
+	return(other_conductors_list);
+}

Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h	2014-10-06 22:06:26 UTC (rev 3362)
+++ trunk/sources/qetgraphicsitem/conductor.h	2014-10-07 19:51:26 UTC (rev 3363)
@@ -86,7 +86,7 @@
 	virtual QPainterPath nearShape() const;
 	virtual QPainterPath variableShape(const qreal &) const;
 	virtual bool isNearConductor(const QPointF &);
-	qreal length();
+	qreal length() const;
 	ConductorSegment *middleSegment();
 	QPointF posForText(Qt::Orientations &flag);
 	bool containsPoint(const QPointF &) const;
@@ -103,7 +103,7 @@
 	void setProfiles(const ConductorProfilesGroup &);
 	ConductorProfilesGroup profiles() const;
 	void readProperties();
-	void adjustTextItemPosition();
+	void calculateTextItemPosition();
 	virtual Highlight highlight() const;
 	virtual void setHighlighted(Highlight);
 	void autoText();
@@ -165,12 +165,10 @@
 	void updateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
 	uint segmentsCount(QET::ConductorSegmentType = QET::Both) const;
 	QList<QPointF> segmentsToPoints() const;
-	QSet<Conductor *> relatedConductors() const;
 	QList<ConductorBend> bends() const;
 	QList<QPointF> junctions() const;
 	void pointsToSegments(QList<QPointF>);
 	bool hasClickedOn(QPointF, QPointF) const;
-	void calculateTextItemPosition();
 	Qt::Corner currentPathType() const;
 	void deleteSegments();
 	static int getCoeff(const qreal &, const qreal &);
@@ -183,4 +181,15 @@
 	static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &);
 	Terminal * relatedPotentialTerminal (Terminal *, const bool all_diagram = true);
 };
+
+Conductor * longuestConductorInPotential (Conductor *conductor, bool all_diagram = false);
+QList <Conductor *> relatedConductors (const Conductor *conductor);
+
+
+//return true if @a is between or at @b and @c.
+template <typename T>
+bool isBetween (const T a, const T b, const T c) {
+	return (b <= c)? (a >= b && a <= c) : (a <= b && a >= c);
+}
+
 #endif

Modified: trunk/sources/qetgraphicsitem/conductortextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductortextitem.cpp	2014-10-06 22:06:26 UTC (rev 3362)
+++ trunk/sources/qetgraphicsitem/conductortextitem.cpp	2014-10-07 19:51:26 UTC (rev 3363)
@@ -128,7 +128,7 @@
 	
 	moved_by_user_ = moved_by_user;
 	if (!moved_by_user && parent_conductor_) {
-		parent_conductor_ -> adjustTextItemPosition();
+		parent_conductor_ -> calculateTextItemPosition();
 	}
 	
 }
@@ -144,7 +144,7 @@
 
 	rotate_by_user_ = rotate_by_user;
 	if (!rotate_by_user && parent_conductor_) {
-		parent_conductor_ -> adjustTextItemPosition();
+		parent_conductor_ -> calculateTextItemPosition();
 	}
 }
 


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