[qet] qet/qet: [5371] Conductor is an herited class of QGraphicsObject, instead of QObject and QGraphicsPathItem

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


Revision: 5371
Author:   blacksun
Date:     2018-05-18 21:36:27 +0200 (Fri, 18 May 2018)
Log Message:
-----------
Conductor is an herited class of QGraphicsObject, instead of QObject and QGraphicsPathItem

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

Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp	2018-05-18 18:28:04 UTC (rev 5370)
+++ trunk/sources/qetgraphicsitem/conductor.cpp	2018-05-18 19:36:27 UTC (rev 5371)
@@ -73,8 +73,6 @@
  * @param p2 : second terminal of this conductor.
  */
 Conductor::Conductor(Terminal *p1, Terminal* p2) :
-	QObject(),
-	QGraphicsPathItem(nullptr),
 	terminal1(p1),
 	terminal2(p2),
 	m_mouse_over(false),
@@ -167,7 +165,7 @@
 	else
 		generateConductorPath(p1, terminal1 -> orientation(), p2, terminal2 -> orientation());
 	calculateTextItemPosition();
-	QGraphicsPathItem::update(rect);
+	QGraphicsObject::update(rect);
 }
 
 /**
@@ -608,7 +606,7 @@
  */
 void Conductor::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
-	QGraphicsPathItem::mousePressEvent(event);
+	QGraphicsObject::mousePressEvent(event);
 	
 	if (event->modifiers() & Qt::ControlModifier)
 		setSelected(!isSelected());
@@ -621,7 +619,7 @@
 void Conductor::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 {
 	if (!(event -> modifiers() & Qt::ControlModifier))
-		QGraphicsPathItem::mouseReleaseEvent(event);
+		QGraphicsObject::mouseReleaseEvent(event);
 }
 
 /**
@@ -684,7 +682,7 @@
 		adjusteHandlerPos();
 	}
 	
-	return(QGraphicsPathItem::itemChange(change, value));
+	return(QGraphicsObject::itemChange(change, value));
 }
 
 /**
@@ -1443,6 +1441,21 @@
 	}
 }
 
+void Conductor::setPath(const QPainterPath &path)
+{
+	if(path == m_path)
+		return;
+	
+	prepareGeometryChange();
+	m_path = path;
+	update();
+}
+
+QPainterPath Conductor::path() const
+{
+	return m_path;
+}
+
 /**
  * @brief Conductor::setPropertiesToPotential
  * @param properties
@@ -1723,8 +1736,10 @@
 		// determine si le point est une bifurcation ou non
 		bool is_bend = false;
 		Qt::Corner current_bend_type = Qt::TopLeftCorner;
-		foreach(ConductorBend cb, bends_list) {
-			if (cb.first == point) {
+		foreach(ConductorBend cb, bends_list)
+		{
+			if (cb.first == point)
+			{
 				is_bend = true;
 				current_bend_type = cb.second;
 				break;
@@ -1735,22 +1750,28 @@
 		
 		bool is_junction = false;
 		QPointF scene_point = mapToScene(point);
-		foreach(Conductor *c, other_conductors) {
-			// exprime le point dans les coordonnees de l'autre conducteur
+		foreach(Conductor *c, other_conductors)
+		{
+				// exprime le point dans les coordonnees de l'autre conducteur
 			QPointF conductor_point = c -> mapFromScene(scene_point);
-			// recupere les segments de l'autre conducteur
+				// recupere les segments de l'autre conducteur
 			QList<ConductorSegment *> c_segments = c -> segmentsList();
-			if (c_segments.isEmpty()) continue;
-			// parcoure les segments a la recherche d'un point commun
-			for (int j = 0 ; j < c_segments.count() ; ++ j) {
+			if (c_segments.isEmpty())
+				continue;
+				// parcoure les segments a la recherche d'un point commun
+			for (int j = 0 ; j < c_segments.count() ; ++ j)
+			{
 				ConductorSegment *segment = c_segments[j];
-				// un point commun a ete trouve sur ce segment
-				if (isContained(conductor_point, segment -> firstPoint(), segment -> secondPoint())) {
+					// un point commun a ete trouve sur ce segment
+				if (isContained(conductor_point, segment -> firstPoint(), segment -> secondPoint()))
+				{
 					is_junction = true;
 					// ce point commun ne doit pas etre une bifurcation identique a celle-ci
 					QList<ConductorBend> other_conductor_bends = c -> bends();
-					foreach(ConductorBend cb, other_conductor_bends) {
-						if (cb.first == conductor_point && cb.second == current_bend_type) {
+					foreach(ConductorBend cb, other_conductor_bends)
+					{
+						if (cb.first == conductor_point && cb.second == current_bend_type)
+						{
 							is_junction = false;
 						}
 					}

Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h	2018-05-18 18:28:04 UTC (rev 5370)
+++ trunk/sources/qetgraphicsitem/conductor.h	2018-05-18 19:36:27 UTC (rev 5371)
@@ -39,7 +39,7 @@
 	This class represents a conductor, i.e. a wire between two element
 	terminals.
 */
-class Conductor : public QObject, public QGraphicsPathItem
+class Conductor : public QGraphicsObject
 {
 	Q_OBJECT
 
@@ -90,6 +90,8 @@
 		ConductorSegment *middleSegment();
 		QPointF posForText(Qt::Orientations &flag);
 		void refreshText();
+		void setPath(const QPainterPath &path);
+		QPainterPath path() const;
 
 	public:
 		static bool valideXml (QDomElement &);
@@ -181,6 +183,7 @@
 		static QPen conductor_pen;
 		static QBrush conductor_brush;
 		static bool pen_and_brush_initialized;
+		QPainterPath m_path;
 	
 	private:
 		void segmentsToPath();


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