[qet] [2600] from now, element himself don' t care of is authorized or not orientation

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


Revision: 2600
Author:   blacksun
Date:     2013-11-08 15:56:38 +0100 (Fri, 08 Nov 2013)
Log Message:
-----------
from now, element himself don't care of is authorized or not orientation
So element save with an unauthorized rotation, can be rotate.

Modified Paths:
--------------
    branches/devel/sources/diagram.cpp
    branches/devel/sources/diagramcommands.cpp
    branches/devel/sources/diagramcommands.h
    branches/devel/sources/diagramview.cpp
    branches/devel/sources/qetgraphicsitem/customelement.cpp
    branches/devel/sources/qetgraphicsitem/diagramimageitem.cpp
    branches/devel/sources/qetgraphicsitem/element.cpp
    branches/devel/sources/qetgraphicsitem/element.h
    branches/devel/sources/qetgraphicsitem/ghostelement.cpp
    branches/devel/sources/qetgraphicsitem/qetgraphicsitem.cpp
    branches/devel/sources/qetgraphicsitem/qetgraphicsitem.h
    branches/devel/sources/terminal.cpp

Modified: branches/devel/sources/diagram.cpp
===================================================================
--- branches/devel/sources/diagram.cpp	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/diagram.cpp	2013-11-08 14:56:38 UTC (rev 2600)
@@ -1256,20 +1256,11 @@
 */
 bool Diagram::canRotateSelection() const {
 	foreach(QGraphicsItem * qgi, selectedItems()) {
-		if (qgraphicsitem_cast<IndependentTextItem *>(qgi)) {
-			return(true);
-		} else if (qgraphicsitem_cast<ElementTextItem *>(qgi)) {
-			return(true);
-		} else if (qgraphicsitem_cast<ConductorTextItem *>(qgi)) {
-			return(true);
-		} else if (Element *e = qgraphicsitem_cast<Element *>(qgi)) {
-			// l'element est-il pivotable ?
-			if (e -> orientation().current() != e -> orientation().next()) {
-				return(true);
-			}
-		} else if (qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
-			return (true);
-		}
+		if (qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
+		qgraphicsitem_cast<ConductorTextItem *>(qgi) ||
+		qgraphicsitem_cast<DiagramImageItem *>(qgi) ||
+		qgraphicsitem_cast<ElementTextItem *>(qgi) ||
+		qgraphicsitem_cast<Element *>(qgi)) return (true);
 	}
 	return(false);
 }

Modified: branches/devel/sources/diagramcommands.cpp
===================================================================
--- branches/devel/sources/diagramcommands.cpp	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/diagramcommands.cpp	2013-11-08 14:56:38 UTC (rev 2600)
@@ -630,7 +630,7 @@
 	@param texts Textes a pivoter
 	@param parent QUndoCommand parent
 */
-RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &texts, const QList<DiagramImageItem *> &images, QUndoCommand *parent) :
+RotateElementsCommand::RotateElementsCommand(const QList<Element *> &elements, const QList<DiagramTextItem *> &texts, const QList<DiagramImageItem *> &images, QUndoCommand *parent) :
 	QUndoCommand(parent),
 	elements_to_rotate(elements),
 	texts_to_rotate(texts),
@@ -653,14 +653,14 @@
 
 /// defait le pivotement
 void RotateElementsCommand::undo() {
-	foreach(Element *e, elements_to_rotate.keys()) {
-		rotateElement(e, elements_to_rotate[e]);
+	foreach(Element *e, elements_to_rotate) {
+		e -> rotateBy(-applied_rotation_angle_);
 	}
 	foreach(DiagramTextItem *dti, texts_to_rotate) {
 		//ConductorTextItem have a default rotation angle, we apply a specific treatment
 		if (ConductorTextItem *cti = qgraphicsitem_cast<ConductorTextItem *>(dti)) {
 			cti -> forceRotateByUser(previous_rotate_by_user_[cti]);
-			(cti -> wasRotateByUser()) ? cti -> rotateBy(-appliedRotationAngle()) :
+			(cti -> wasRotateByUser()) ? cti -> rotateBy(-applied_rotation_angle_) :
 										 cti -> parentConductor() -> adjustTextItemPosition();
 		}
 		else {dti -> rotateBy(-applied_rotation_angle_);}
@@ -670,8 +670,8 @@
 
 /// refait le pivotement
 void RotateElementsCommand::redo() {
-	foreach(Element *e, elements_to_rotate.keys()) {
-		rotateElement(e, e -> orientation().next());
+	foreach(Element *e, elements_to_rotate) {
+		e -> rotateBy(applied_rotation_angle_);
 	}
 	foreach(DiagramTextItem *dti, texts_to_rotate) {
 		//we grab the previous rotation by user of each ConductorTextItem
@@ -685,50 +685,6 @@
 }
 
 /**
-	@return l'angle de rotation applique aux textes
-*/
-qreal RotateElementsCommand::appliedRotationAngle() const {
-	return(applied_rotation_angle_);
-}
-
-/**
-	@param angle l'angle de rotation a appliquer aux textes
-*/
-void RotateElementsCommand::setAppliedRotationAngle(const qreal &angle) {
-	applied_rotation_angle_ = QET::correctAngle(angle);
-}
-
-/**
-	Passe un element a une orientation donnee, en prenant soin de gerer ses textes enfants
-	@param element Element a orienter soigneusement
-	@param orientation Nouvelle orientation de l'element
-*/
-void RotateElementsCommand::rotateElement(Element *element, QET::Orientation orientation) {
-	qreal rotation_value = 90.0 * (orientation - element -> orientation().current());
-	element -> setOrientation(orientation);
-	//element -> update();
-	if (rotation_value) {
-		// repositionne les textes de l'element qui ne comportent pas l'option "FollowParentRotations"
-		foreach(ElementTextItem *eti, element -> texts()) {
-			if (!eti -> followParentRotations())  {
-				// on souhaite pivoter le champ de texte par rapport a son centre
-				QPointF eti_center = eti -> boundingRect().center();
-				// pour ce faire, on repere la position de son centre par rapport a son parent
-				QPointF parent_eti_center_before = eti -> mapToParent(eti_center);
-				// on applique ensuite une simple rotation contraire, qui sera donc appliquee sur le milieu du cote gauche du champ de texte
-				eti -> rotateBy(-rotation_value);
-				// on regarde ensuite la nouvelle position du centre du champ de texte par rapport a son parent
-				QPointF parent_eti_center_after = eti -> mapToParent(eti_center);
-				// on determine la translation a appliquer
-				QPointF eti_translation = parent_eti_center_before - parent_eti_center_after;
-				// on applique cette translation
-				eti -> setPos(eti -> pos() + eti_translation);
-			}
-		}
-	}
-}
-
-/**
 	Constructeur
 	@param previous_state Hash associant les textes impactes par l'action et leur angle de rotation avant l'action
 	@param applied_rotation Nouvel angle de rotation, a appliquer au textes concernes

Modified: branches/devel/sources/diagramcommands.h
===================================================================
--- branches/devel/sources/diagramcommands.h	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/diagramcommands.h	2013-11-08 14:56:38 UTC (rev 2600)
@@ -330,7 +330,7 @@
 class RotateElementsCommand : public QUndoCommand {
 	// constructors, destructor
 	public:
-	RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &, const QList<DiagramImageItem *> &, QUndoCommand * = 0);
+	RotateElementsCommand(const QList<Element *> &elements, const QList<DiagramTextItem *> &, const QList<DiagramImageItem *> &, QUndoCommand * = 0);
 	virtual ~RotateElementsCommand();
 	private:
 	RotateElementsCommand(const RotateElementsCommand &);
@@ -339,14 +339,11 @@
 	public:
 	virtual void undo();
 	virtual void redo();
-	qreal appliedRotationAngle() const;
-	void setAppliedRotationAngle(const qreal &);
-	static void rotateElement(Element *, QET::Orientation);
 	
 	// attributes
 	private:
 	/// hold rotated elements along with their former orientation
-	QHash<Element *, QET::Orientation> elements_to_rotate;
+	QList<Element *> elements_to_rotate;
 	/// text items to be rotated
 	QList<DiagramTextItem *> texts_to_rotate;
 	/// images item to be rotated

Modified: branches/devel/sources/diagramview.cpp
===================================================================
--- branches/devel/sources/diagramview.cpp	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/diagramview.cpp	2013-11-08 14:56:38 UTC (rev 2600)
@@ -144,12 +144,12 @@
 	if (scene -> isReadOnly()) return;
 	
 	// recupere les elements et les champs de texte a pivoter
-	QHash<Element *, QET::Orientation> elements_to_rotate;
+	QList<Element *> elements_to_rotate;
 	QList<DiagramTextItem *> texts_to_rotate;
 	QList<DiagramImageItem *> images_to_rotate;
 	foreach (QGraphicsItem *item, scene -> selectedItems()) {
 		if (Element *e = qgraphicsitem_cast<Element *>(item)) {
-			elements_to_rotate.insert(e, e -> orientation().current());
+			elements_to_rotate << e;
 		} else if (ConductorTextItem *cti = qgraphicsitem_cast<ConductorTextItem *>(item)) {
 			texts_to_rotate << cti;
 		} else if (IndependentTextItem *iti = qgraphicsitem_cast<IndependentTextItem *>(item)) {

Modified: branches/devel/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- branches/devel/sources/qetgraphicsitem/customelement.cpp	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/qetgraphicsitem/customelement.cpp	2013-11-08 14:56:38 UTC (rev 2600)
@@ -702,7 +702,9 @@
 	@return true si l'attribut "orientation" est valide, false sinon
 */
 bool CustomElement::validOrientationAttribute(const QDomElement &e) {
-	return(ori.fromString(e.attribute("orientation")));
+	int ori = e.attribute("orientation").toInt();
+	if(ori >= 0 && ori <=3) return true;
+	return false;
 }
 
 /**

Modified: branches/devel/sources/qetgraphicsitem/diagramimageitem.cpp
===================================================================
--- branches/devel/sources/qetgraphicsitem/diagramimageitem.cpp	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/qetgraphicsitem/diagramimageitem.cpp	2013-11-08 14:56:38 UTC (rev 2600)
@@ -192,7 +192,7 @@
 	setPixmap(pixmap);
 
 	setScale(e.attribute("size").toDouble());
-	setRotationAngle(e.attribute("rotation").toDouble());
+	applyRotation(e.attribute("rotation").toDouble());
 	setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
 
 	return (true);

Modified: branches/devel/sources/qetgraphicsitem/element.cpp
===================================================================
--- branches/devel/sources/qetgraphicsitem/element.cpp	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/qetgraphicsitem/element.cpp	2013-11-08 14:56:38 UTC (rev 2600)
@@ -70,9 +70,7 @@
 		Diagram *dia = diagram();
 		if (dia && options -> levelOfDetail == 1.0 && widget) {
 			// calcule la rotation qu'a subi l'element
-			qreal applied_rotation = 90.0 * (ori.current() - ori.defaultOrientation());
-			while (applied_rotation < 360.0) applied_rotation += 360.0;
-			while (applied_rotation > 360.0) applied_rotation -= 360.0;
+			qreal applied_rotation = 90.0 * orientation();
 			if (applied_rotation == 90.0) painter -> translate(1.0, -1.0);
 			else if (applied_rotation == 180.0) painter -> translate(-1.0, -1.0);
 			else if (applied_rotation == 270.0) painter -> translate(-1.0, 1.0);
@@ -167,25 +165,38 @@
 }
 
 /**
-	Permet de specifier l'orientation de l'element
-	@param o la nouvelle orientation de l'objet
-	@return true si l'orientation a pu etre appliquee, false sinon
-*/
-bool Element::setOrientation(QET::Orientation o) {
-	// verifie que l'orientation demandee est acceptee
-	if (!ori.accept(o)) return(false);
-	prepareGeometryChange();
-	// rotation en consequence et rafraichissement de l'element graphique
-	qreal rotation_value = 90.0 * (o - ori.current());
-	applyRotation(rotation_value);
-	ori.setCurrent(o);
-	update();
+ * @brief Element::rotateBy
+ * this methode is redefined for handle child item
+ * @param angle
+ */
+void Element::rotateBy(const qreal &angle) {
+	qreal applied_angle = QET::correctAngle(angle);
+	applyRotation(applied_angle + rotation());
+
+	//update the path of conductor
 	foreach(QGraphicsItem *qgi, childItems()) {
 		if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
 			p -> updateConductor();
 		}
 	}
-	return(true);
+
+	// repositionne les textes de l'element qui ne comportent pas l'option "FollowParentRotations"
+	foreach(ElementTextItem *eti, texts()) {
+		if (!eti -> followParentRotations())  {
+			// on souhaite pivoter le champ de texte par rapport a son centre
+			QPointF eti_center = eti -> boundingRect().center();
+			// pour ce faire, on repere la position de son centre par rapport a son parent
+			QPointF parent_eti_center_before = eti -> mapToParent(eti_center);
+			// on applique ensuite une simple rotation contraire, qui sera donc appliquee sur le milieu du cote gauche du champ de texte
+			eti -> rotateBy(-applied_angle);
+			// on regarde ensuite la nouvelle position du centre du champ de texte par rapport a son parent
+			QPointF parent_eti_center_after = eti -> mapToParent(eti_center);
+			// on determine la translation a appliquer
+			QPointF eti_translation = parent_eti_center_before - parent_eti_center_after;
+			// on applique cette translation
+			eti -> setPos(eti -> pos() + eti_translation);
+		}
+	}
 }
 
 /*** Methodes protegees ***/
@@ -371,11 +382,11 @@
 	// orientation
 	bool conv_ok;
 	int read_ori = e.attribute("orientation").toInt(&conv_ok);
-	if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = ori.defaultOrientation();
+	if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0;
 	if (handle_inputs_rotation) {
-		RotateElementsCommand::rotateElement(this, (QET::Orientation)read_ori);
+		rotateBy(90*read_ori);
 	} else {
-		setOrientation((QET::Orientation)read_ori);
+		applyRotation(90*read_ori);
 	}
 	return(true);
 }
@@ -397,7 +408,7 @@
 	// position, selection et orientation
 	element.setAttribute("x", QString("%1").arg(pos().x()));
 	element.setAttribute("y", QString("%1").arg(pos().y()));
-	element.setAttribute("orientation", QString("%1").arg(ori.current()));
+	element.setAttribute("orientation", QString("%1").arg(orientation()));
 	
 	/* recupere le premier id a utiliser pour les bornes de cet element */
 	int id_terminal = 0;

Modified: branches/devel/sources/qetgraphicsitem/element.h
===================================================================
--- branches/devel/sources/qetgraphicsitem/element.h	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/qetgraphicsitem/element.h	2013-11-08 14:56:38 UTC (rev 2600)
@@ -19,7 +19,6 @@
 #define ELEMENT_H
 #include <QtGui>
 #include "terminal.h"
-#include "orientationset.h"
 #include "qetgraphicsitem.h"
 class Diagram;
 class ElementTextItem;
@@ -43,14 +42,6 @@
 	enum { Type = UserType + 1000 };
 	
 	protected:
-	/**
-		Hold orientations for the element :
-			* allowed orientations
-			* current orientation
-			* default orientation
-		@see OrientationSet
-	*/
-	OrientationSet ori;
 	
 	private:
 	QSize   dimensions;
@@ -107,6 +98,7 @@
 	// methods related to internal connections
 	bool internalConnections();
 	void setInternalConnections(bool);
+	virtual void rotateBy(const qreal &);
 	
 	// methods related to XML import/export
 	static bool valideXml(QDomElement &);
@@ -114,8 +106,7 @@
 	virtual QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
 	
 	// orientation-related methods
-	bool setOrientation(QET::Orientation o);
-	const OrientationSet &orientation() const;
+	int orientation() const;
 	
 	protected:
 	void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
@@ -148,10 +139,14 @@
 
 /**
 	Indicate the current orientation of this element
+	O = 0°
+	1 = 90°
+	2 = 180°
+	3 = 270°
 	@return the current orientation of this element
 */
-inline const OrientationSet & Element::orientation() const {
-	return(ori);
+inline int Element::orientation() const {
+	return(QET::correctAngle(rotation())/90);
 }
 
 #endif

Modified: branches/devel/sources/qetgraphicsitem/ghostelement.cpp
===================================================================
--- branches/devel/sources/qetgraphicsitem/ghostelement.cpp	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/qetgraphicsitem/ghostelement.cpp	2013-11-08 14:56:38 UTC (rev 2600)
@@ -86,11 +86,11 @@
 	// orientation
 	bool conv_ok;
 	int read_ori = e.attribute("orientation").toInt(&conv_ok);
-	if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = ori.defaultOrientation();
+	if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0;
 	if (handle_inputs_rotation) {
-		RotateElementsCommand::rotateElement(this, (QET::Orientation)read_ori);
+		rotateBy(90*read_ori);
 	} else {
-		setOrientation((QET::Orientation)read_ori);
+		applyRotation(90*read_ori);
 	}
 	return(true);
 }

Modified: branches/devel/sources/qetgraphicsitem/qetgraphicsitem.cpp
===================================================================
--- branches/devel/sources/qetgraphicsitem/qetgraphicsitem.cpp	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/qetgraphicsitem/qetgraphicsitem.cpp	2013-11-08 14:56:38 UTC (rev 2600)
@@ -69,24 +69,13 @@
 }
 
 /**
-	Permet de tourner l'item a un angle donne de maniere absolue.
-	Un angle de 0 degres correspond a un image horizontal non retourne.
-	@param rotation Nouvel angle de rotation de ce image
-	@see applyRotation
-*/
-void QetGraphicsItem::setRotationAngle(const qreal &rotation_angle) {
-	qreal applied_rotation = QET::correctAngle(rotation_angle);
-	applyRotation(applied_rotation - rotation());
-}
-
-/**
 	Permet de tourner l'item de maniere relative.
 	L'angle added_rotation est ajoute a l'orientation actuelle du image.
 	@param added_rotation Angle a ajouter a la rotation actuelle
 	@see applyRotation
 */
 void QetGraphicsItem::rotateBy(const qreal &added_rotation) {
-	qreal applied_added_rotation = QET::correctAngle(added_rotation);
+	qreal applied_added_rotation = QET::correctAngle(added_rotation + rotation());
 	applyRotation(applied_added_rotation);
 }
 
@@ -96,7 +85,7 @@
 	@param angle Angle de la rotation a effectuer
 */
 void QetGraphicsItem::applyRotation(const qreal &angle) {
-	setRotation(QET::correctAngle(rotation() + angle));
+	setRotation(QET::correctAngle(angle));
 }
 
 /**

Modified: branches/devel/sources/qetgraphicsitem/qetgraphicsitem.h
===================================================================
--- branches/devel/sources/qetgraphicsitem/qetgraphicsitem.h	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/qetgraphicsitem/qetgraphicsitem.h	2013-11-08 14:56:38 UTC (rev 2600)
@@ -35,8 +35,8 @@
 	Diagram* diagram() const;
 	virtual void setPos(const QPointF &p);
 	virtual void setPos(qreal x, qreal y);
-	void setRotationAngle(const qreal &);
-	void rotateBy(const qreal &);
+	virtual void rotateBy(const qreal &);
+	virtual void applyRotation(const qreal &);
 
 	signals:
 
@@ -44,7 +44,6 @@
 
 	//protected method
 	protected:
-	void applyRotation(const qreal &);
 	virtual void mousePressEvent(QGraphicsSceneMouseEvent *e);
 	virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e);
 	virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *e);

Modified: branches/devel/sources/terminal.cpp
===================================================================
--- branches/devel/sources/terminal.cpp	2013-11-07 14:24:02 UTC (rev 2599)
+++ branches/devel/sources/terminal.cpp	2013-11-08 14:56:38 UTC (rev 2600)
@@ -114,13 +114,12 @@
 QET::Orientation Terminal::orientation() const {
 	if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
 		// orientations actuelle et par defaut de l'element
-		QET::Orientation ori_cur = elt -> orientation().current();
-		QET::Orientation ori_def = elt -> orientation().defaultOrientation();
-		if (ori_cur == ori_def) return(ori_);
+		int ori_cur = elt -> orientation();
+		if (ori_cur == 0) return(ori_);
 		else {
 			// calcul l'angle de rotation implique par l'orientation de l'element parent
 			// angle de rotation de la borne sur la scene, divise par 90
-			int angle = ori_cur - ori_def + ori_;
+			int angle = ori_cur + ori_;
 			while (angle >= 4) angle -= 4;
 			return((QET::Orientation)angle);
 		}
@@ -187,9 +186,8 @@
 			qreal applied_rotation = 0.0;
 			if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
 				// orientations actuelle et par defaut de l'element
-				QET::Orientation ori_cur = elt -> orientation().current();
-				QET::Orientation ori_def = elt -> orientation().defaultOrientation();
-				applied_rotation = QET::correctAngle(90.0 * (ori_cur - ori_def));
+				int ori_cur = elt -> orientation();
+				applied_rotation = QET::correctAngle(90.0 * ori_cur);
 			}
 			if (applied_rotation == 90.0) p -> translate(1.0, -1.0);
 			else if (applied_rotation == 180.0) p -> translate(-1.0, -1.0);


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