[qet] qet/qet: [5281] QetGraphicsItem, remove the function applyRotation and rotateBy, and use instead the native function of QGraphicsItem : setRotation

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


Revision: 5281
Author:   blacksun
Date:     2018-03-27 21:04:43 +0200 (Tue, 27 Mar 2018)
Log Message:
-----------
QetGraphicsItem, remove the function applyRotation and rotateBy, and use instead the native function of QGraphicsItem : setRotation

Modified Paths:
--------------
    trunk/sources/diagramevent/diagrameventaddelement.cpp
    trunk/sources/diagramevent/diagrameventaddimage.cpp
    trunk/sources/qetgraphicsitem/diagramimageitem.cpp
    trunk/sources/qetgraphicsitem/element.cpp
    trunk/sources/qetgraphicsitem/element.h
    trunk/sources/qetgraphicsitem/ghostelement.cpp
    trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp
    trunk/sources/qetgraphicsitem/qetgraphicsitem.h
    trunk/sources/undocommand/rotateselectioncommand.cpp

Modified: trunk/sources/diagramevent/diagrameventaddelement.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.cpp	2018-03-25 18:56:16 UTC (rev 5280)
+++ trunk/sources/diagramevent/diagrameventaddelement.cpp	2018-03-27 19:04:43 UTC (rev 5281)
@@ -147,7 +147,7 @@
 {
 	if (m_element && event->key() == Qt::Key_Space)
 	{
-		m_element->rotateBy(90);
+		m_element->setRotation(m_element->rotation() + 90);
 		return true;
 	}
 

Modified: trunk/sources/diagramevent/diagrameventaddimage.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddimage.cpp	2018-03-25 18:56:16 UTC (rev 5280)
+++ trunk/sources/diagramevent/diagrameventaddimage.cpp	2018-03-27 19:04:43 UTC (rev 5281)
@@ -74,7 +74,7 @@
 
     if (m_image && event -> button() == Qt::RightButton)
     {
-            m_image -> rotateBy(90);
+			m_image->setRotation(m_image->rotation() + 90);
             return true;
     }
 

Modified: trunk/sources/qetgraphicsitem/diagramimageitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/diagramimageitem.cpp	2018-03-25 18:56:16 UTC (rev 5280)
+++ trunk/sources/qetgraphicsitem/diagramimageitem.cpp	2018-03-27 19:04:43 UTC (rev 5281)
@@ -142,7 +142,7 @@
 	setPixmap(pixmap);
 
 	setScale(e.attribute("size").toDouble());
-	applyRotation(e.attribute("rotation").toDouble());
+	setRotation(e.attribute("rotation").toDouble());
 		//We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
 	QGraphicsObject::setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
 	is_movable_ = (e.attribute("is_movable").toInt());
@@ -159,7 +159,7 @@
 	//write some attribute
 	result.setAttribute("x", QString("%1").arg(pos().x()));
 	result.setAttribute("y", QString("%1").arg(pos().y()));
-	result.setAttribute("rotation", QString("%1").arg(rotation()));
+	result.setAttribute("rotation", QString("%1").arg(QET::correctAngle(rotation())));
 	result.setAttribute("size", QString("%1").arg(scale()));
 	result.setAttribute("is_movable", bool(is_movable_));
 

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2018-03-25 18:56:16 UTC (rev 5280)
+++ trunk/sources/qetgraphicsitem/element.cpp	2018-03-27 19:04:43 UTC (rev 5281)
@@ -73,6 +73,14 @@
 	setZValue(10);
 	setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
 	setAcceptHoverEvents(true);
+	
+	connect(this, &Element::rotationChanged, [this]() {
+		for(QGraphicsItem *qgi : childItems())
+		{
+			if (Terminal *t = qgraphicsitem_cast<Terminal *>(qgi))
+				t->updateConductor();
+		}
+	});
 }
 
 /**
@@ -221,23 +229,6 @@
 	return(preview);
 }
 
-/**
- * @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();
-		}
-	}
-}
-
 /*** Methodes protegees ***/
 
 /**
@@ -443,9 +434,9 @@
 	int read_ori = e.attribute("orientation").toInt(&conv_ok);
 	if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0;
 	if (handle_inputs_rotation) {
-		rotateBy(90*read_ori);
+		setRotation(rotation() + (90*read_ori));
 	} else {
-		applyRotation(90*read_ori);
+		setRotation(90*read_ori);
 	}
 	
 		//Befor load the dynamic text field,

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2018-03-25 18:56:16 UTC (rev 5280)
+++ trunk/sources/qetgraphicsitem/element.h	2018-03-27 19:04:43 UTC (rev 5281)
@@ -176,7 +176,6 @@
         void select();
         void deselect();
         
-        void rotateBy(const qreal &) override;
         void editProperty() override;
         
             // methods related to XML import/export

Modified: trunk/sources/qetgraphicsitem/ghostelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/ghostelement.cpp	2018-03-25 18:56:16 UTC (rev 5280)
+++ trunk/sources/qetgraphicsitem/ghostelement.cpp	2018-03-27 19:04:43 UTC (rev 5281)
@@ -82,9 +82,9 @@
 	int read_ori = e.attribute("orientation").toInt(&conv_ok);
 	if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0;
 	if (handle_inputs_rotation) {
-		rotateBy(90*read_ori);
+		setRotation(rotation() + (90*read_ori));
 	} else {
-		applyRotation(90*read_ori);
+		setRotation(90*read_ori);
 	}
 	return(true);
 }

Modified: trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp	2018-03-25 18:56:16 UTC (rev 5280)
+++ trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp	2018-03-27 19:04:43 UTC (rev 5281)
@@ -65,26 +65,6 @@
 }
 
 /**
-	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 + rotation());
-	applyRotation(applied_added_rotation);
-}
-
-/**
-	Effectue la rotation de l'item en lui même
-	Cette methode peut toutefois etre redefinie dans des classes filles
-	@param angle Angle de la rotation a effectuer
-*/
-void QetGraphicsItem::applyRotation(const qreal &angle) {
-	setRotation(QET::correctAngle(angle));
-}
-
-/**
  * @brief QetGraphicsItem::mousePressEvent
  *handle the mouse click
  * @param e

Modified: trunk/sources/qetgraphicsitem/qetgraphicsitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetgraphicsitem.h	2018-03-25 18:56:16 UTC (rev 5280)
+++ trunk/sources/qetgraphicsitem/qetgraphicsitem.h	2018-03-27 19:04:43 UTC (rev 5281)
@@ -35,8 +35,6 @@
 		Diagram *diagram       () const;
 		virtual void     setPos        (const QPointF &p);
 		virtual void     setPos        (qreal x, qreal y);
-		virtual void     rotateBy      (const qreal &);
-		virtual void     applyRotation (const qreal &);
 
 		virtual bool isMovable () const {return is_movable_;}
 		virtual void setMovable (bool movable) { is_movable_ = movable;}

Modified: trunk/sources/undocommand/rotateselectioncommand.cpp
===================================================================
--- trunk/sources/undocommand/rotateselectioncommand.cpp	2018-03-25 18:56:16 UTC (rev 5280)
+++ trunk/sources/undocommand/rotateselectioncommand.cpp	2018-03-27 19:04:43 UTC (rev 5281)
@@ -78,7 +78,7 @@
 	
 	for(QPointer<Element> elmt : m_element)
 		if(elmt)
-			elmt.data()->rotateBy(-m_angle);
+			elmt.data()->setRotation(elmt.data()->rotation() - m_angle);
 	for(QPointer<DiagramTextItem> text : m_text)
 	{
 		if(text)
@@ -98,7 +98,7 @@
 	}
 	for(QPointer<DiagramImageItem> image : m_image)
 		if(image)
-			image.data()->rotateBy(-m_angle);
+			image.data()->setRotation(image.data()->rotation() - m_angle);
 	for(QPointer<ElementTextItemGroup> group : m_group)
 		if(group)
 			group.data()->setRotation(group.data()->rotation() - m_angle);
@@ -113,7 +113,7 @@
 	
 	for(QPointer<Element> elmt : m_element)
 		if(elmt)
-			elmt.data()->rotateBy(m_angle);
+			elmt.data()->setRotation(elmt.data()->rotation() + m_angle);
 	for(QPointer<DiagramTextItem> text : m_text)
 	{
 		if(text)
@@ -129,7 +129,7 @@
 	}
 	for(QPointer<DiagramImageItem> image : m_image)
 		if(image)
-			image.data()->rotateBy(m_angle);
+			image.data()->setRotation(image.data()->rotation() + m_angle);
 	for(QPointer<ElementTextItemGroup> group : m_group)
 		if(group)
 			group.data()->setRotation(group.data()->rotation() + m_angle);


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