[qet] [984] Simplification du code permettant la mise a jour des conducteurs lors des deplacements et rotations d 'elements.

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


Revision: 984
Author:   xavier
Date:     2010-05-04 22:18:30 +0200 (Tue, 04 May 2010)
Log Message:
-----------
Simplification du code permettant la mise a jour des conducteurs lors des deplacements et rotations d'elements.

Modified Paths:
--------------
    branches/0.3/sources/conductor.cpp
    branches/0.3/sources/conductor.h
    branches/0.3/sources/diagram.cpp
    branches/0.3/sources/diagram.h
    branches/0.3/sources/diagramcommands.cpp
    branches/0.3/sources/diagramcontent.cpp
    branches/0.3/sources/diagramcontent.h
    branches/0.3/sources/terminal.cpp
    branches/0.3/sources/terminal.h

Modified: branches/0.3/sources/conductor.cpp
===================================================================
--- branches/0.3/sources/conductor.cpp	2010-05-02 22:21:53 UTC (rev 983)
+++ branches/0.3/sources/conductor.cpp	2010-05-04 20:18:30 UTC (rev 984)
@@ -134,18 +134,10 @@
 	@param b Borne
 	@param newpos position de la borne b
 */
-void Conductor::updateWithNewPos(const QRectF &rect, const Terminal *b, const QPointF &newpos) {
+void Conductor::updateWithNewPos(const QRectF &rect) {
 	QPointF p1, p2;
-	if (b == terminal1) {
-		p1 = newpos;
-		p2 = terminal2 -> dockConductor();
-	} else if (b == terminal2) {
-		p1 = terminal1 -> dockConductor();
-		p2 = newpos;
-	} else {
-		p1 = terminal1 -> dockConductor();
-		p2 = terminal2 -> dockConductor();
-	}
+	p1 = terminal1 -> dockConductor();
+	p2 = terminal2 -> dockConductor();
 	if (nbSegments() && !conductor_profiles[currentPathType()].isNull())
 		priv_modifieConductor(p1, terminal1 -> orientation(), p2, terminal2 -> orientation());
 	else

Modified: branches/0.3/sources/conductor.h
===================================================================
--- branches/0.3/sources/conductor.h	2010-05-02 22:21:53 UTC (rev 983)
+++ branches/0.3/sources/conductor.h	2010-05-04 20:18:30 UTC (rev 984)
@@ -61,7 +61,7 @@
 	/// @return true si ce conducteur est detruit
 	bool isDestroyed() const { return(destroyed); }
 	Diagram *diagram() const;
-	void updateWithNewPos(const QRectF &, const Terminal *, const QPointF &);
+	void updateWithNewPos(const QRectF &);
 	void update(const QRectF & = QRectF());
 	void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
 	QRectF boundingRect() const;

Modified: branches/0.3/sources/diagram.cpp
===================================================================
--- branches/0.3/sources/diagram.cpp	2010-05-02 22:21:53 UTC (rev 983)
+++ branches/0.3/sources/diagram.cpp	2010-05-04 20:18:30 UTC (rev 984)
@@ -845,7 +845,7 @@
 				if (elements_to_move.contains(other_terminal -> parentElement())) {
 					conductors_to_move << conductor;
 				} else {
-					conductors_to_update.insert(conductor, terminal);
+					conductors_to_update << conductor;
 				}
 			}
 		}
@@ -879,9 +879,8 @@
 	}
 	
 	// recalcule les autres conducteurs
-	const QHash<Conductor *, Terminal *> &conductors_modify = conductorsToUpdate();
-	foreach(Conductor *conductor, conductors_modify.keys()) {
-		conductor -> updateWithNewPos(QRectF(), conductors_modify[conductor], conductors_modify[conductor] -> dockConductor());
+	foreach(Conductor *conductor, conductorsToUpdate()) {
+		conductor -> updateWithNewPos(QRectF());
 	}
 	
 	// deplace les champs de texte
@@ -1090,7 +1089,7 @@
 	dc.elements           = elementsToMove().toList();
 	dc.textFields         = independentTextsToMove().toList();
 	dc.conductorsToMove   = conductorsToMove().toList();
-	dc.conductorsToUpdate = conductorsToUpdate();
+	dc.conductorsToUpdate = conductorsToUpdate().toList();
 	
 	// recupere les conducteurs selectionnes isoles (= non deplacables mais supprimables)
 	foreach(QGraphicsItem *qgi, items()) {

Modified: branches/0.3/sources/diagram.h
===================================================================
--- branches/0.3/sources/diagram.h	2010-05-02 22:21:53 UTC (rev 983)
+++ branches/0.3/sources/diagram.h	2010-05-04 20:18:30 UTC (rev 984)
@@ -79,7 +79,7 @@
 	bool moved_elements_fetched;
 	QSet<Element *> elements_to_move;
 	QSet<Conductor *> conductors_to_move;
-	QHash<Conductor *, Terminal *> conductors_to_update;
+	QSet<Conductor *> conductors_to_update;
 	QSet<IndependentTextItem *> texts_to_move;
 	QSet<ElementTextItem *> elements_texts_to_move;
 	QGIManager *qgi_manager;
@@ -158,7 +158,7 @@
 	void fetchMovedElements();
 	const QSet<Element *> &elementsToMove();
 	const QSet<Conductor *> &conductorsToMove();
-	const QHash<Conductor *, Terminal *> &conductorsToUpdate();
+	const QSet<Conductor *> &conductorsToUpdate();
 	const QSet<IndependentTextItem *> &independentTextsToMove();
 	const QSet<ElementTextItem *> &elementTextsToMove();
 	QSet<DiagramTextItem *> selectedTexts() const;
@@ -285,7 +285,7 @@
 }
 
 /// @return la liste des conducteurs a modifier (typiquement les conducteurs dont seul un element est deplace)
-inline const QHash<Conductor *, Terminal *> &Diagram::conductorsToUpdate() {
+inline const QSet<Conductor *> &Diagram::conductorsToUpdate() {
 	if (!moved_elements_fetched) fetchMovedElements();
 	return(conductors_to_update);
 }

Modified: branches/0.3/sources/diagramcommands.cpp
===================================================================
--- branches/0.3/sources/diagramcommands.cpp	2010-05-02 22:21:53 UTC (rev 983)
+++ branches/0.3/sources/diagramcommands.cpp	2010-05-04 20:18:30 UTC (rev 984)
@@ -353,12 +353,8 @@
 	}
 	
 	// recalcule les autres conducteurs
-	foreach(Conductor *conductor, content_to_move.conductorsToUpdate.keys()) {
-		conductor -> updateWithNewPos(
-			QRectF(),
-			content_to_move.conductorsToUpdate[conductor],
-			content_to_move.conductorsToUpdate[conductor] -> dockConductor()
-		);
+	foreach(Conductor *conductor, content_to_move.conductorsToUpdate) {
+		conductor -> updateWithNewPos(QRectF());
 	}
 	
 	// deplace les textes

Modified: branches/0.3/sources/diagramcontent.cpp
===================================================================
--- branches/0.3/sources/diagramcontent.cpp	2010-05-02 22:21:53 UTC (rev 983)
+++ branches/0.3/sources/diagramcontent.cpp	2010-05-04 20:18:30 UTC (rev 984)
@@ -52,7 +52,7 @@
 QList<Conductor *> DiagramContent::conductors(int filter) const {
 	QList<Conductor *> result;
 	if (filter & ConductorsToMove)   result += conductorsToMove;
-	if (filter & ConductorsToUpdate) result += conductorsToUpdate.keys();
+	if (filter & ConductorsToUpdate) result += conductorsToUpdate;
 	if (filter & OtherConductors)    result += otherConductors;
 	if (filter & SelectedOnly) {
 		foreach(Conductor *conductor, result) {
@@ -100,7 +100,7 @@
 		if (filter & Elements)           foreach(Element *element,     elements)                  { if (element   -> isSelected()) ++ count; }
 		if (filter & TextFields)         foreach(DiagramTextItem *dti, textFields)                { if (dti       -> isSelected()) ++ count; }
 		if (filter & ConductorsToMove)   foreach(Conductor *conductor, conductorsToMove)          { if (conductor -> isSelected()) ++ count; }
-		if (filter & ConductorsToUpdate) foreach(Conductor *conductor, conductorsToUpdate.keys()) { if (conductor -> isSelected()) ++ count; }
+		if (filter & ConductorsToUpdate) foreach(Conductor *conductor, conductorsToUpdate)        { if (conductor -> isSelected()) ++ count; }
 		if (filter & OtherConductors)    foreach(Conductor *conductor, otherConductors)           { if (conductor -> isSelected()) ++ count; }
 	} else {
 		if (filter & Elements)           count += elements.count();
@@ -143,7 +143,7 @@
 	/*
 	FIXME Le double-heritage QObject / QGraphicsItem a casse cet operateur
 	d << "  elements :" << c.elements << "\n";
-	d << "  conductorsToUpdate :" << c.conductorsToUpdate.keys() << "\n";
+	d << "  conductorsToUpdate :" << c.conductorsToUpdate << "\n";
 	d << "  conductorsToMove :" << c.conductorsToMove << "\n";
 	d << "  otherConductors :" << c.otherConductors << "\n";
 	*/

Modified: branches/0.3/sources/diagramcontent.h
===================================================================
--- branches/0.3/sources/diagramcontent.h	2010-05-02 22:21:53 UTC (rev 983)
+++ branches/0.3/sources/diagramcontent.h	2010-05-04 20:18:30 UTC (rev 984)
@@ -20,7 +20,6 @@
 #include <QtGui>
 class Conductor;
 class Element;
-class Terminal;
 class IndependentTextItem;
 /**
 	Cette classe est un conteneur pour passer facilement le contenu d'un schema
@@ -55,7 +54,7 @@
 	/// Champs de texte independants du schema
 	QList<IndependentTextItem *> textFields;
 	/// Conducteurs a mettre a jour du schema
-	QHash<Conductor *, Terminal *> conductorsToUpdate;
+	QList<Conductor *> conductorsToUpdate;
 	/// Conducteurs a deplacer du schema
 	QList<Conductor *> conductorsToMove;
 	/// Conducteurs isoles (ni a deplacer, ni a mettre a jour)

Modified: branches/0.3/sources/terminal.cpp
===================================================================
--- branches/0.3/sources/terminal.cpp	2010-05-02 22:21:53 UTC (rev 983)
+++ branches/0.3/sources/terminal.cpp	2010-05-04 20:18:30 UTC (rev 984)
@@ -372,20 +372,14 @@
 }
 
 /**
-	Met a jour l'eventuel conducteur relie a la Terminal.
+	Met a jour l'eventuel conducteur relie a la borne.
 	@param newpos Position de l'element parent a prendre en compte
 */
-void Terminal::updateConductor(QPointF newpos) {
+void Terminal::updateConductor() {
 	if (!scene() || !parentItem()) return;
 	foreach (Conductor *conductor, conductors_) {
 		if (conductor -> isDestroyed()) continue;
-		if (newpos == QPointF()) conductor -> update(QRectF());
-		else {
-			// determine la translation subie par l'element parent
-			QPointF translation = newpos - parentItem() -> pos();
-			// rafraichit le conducteur en tenant compte de la translation
-			conductor -> updateWithNewPos(QRectF(), this, dockConductor() + translation);
-		}
+		conductor -> update(QRectF());
 	}
 }
 

Modified: branches/0.3/sources/terminal.h
===================================================================
--- branches/0.3/sources/terminal.h	2010-05-02 22:21:53 UTC (rev 983)
+++ branches/0.3/sources/terminal.h	2010-05-04 20:18:30 UTC (rev 984)
@@ -61,7 +61,7 @@
 	QList<Conductor *> conductors() const;
 	QET::Orientation orientation() const;
 	QPointF dockConductor() const;
-	void updateConductor(QPointF = QPointF());
+	void updateConductor();
 	bool isLinkedTo(Terminal *);
 	bool canBeLinkedTo(Terminal *);
 	


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