QetGraphicsItem, remove the function applyRotation and rotateBy, and use instead the native function of QGraphicsItem : setRotation

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5281 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2018-03-27 19:04:43 +00:00
parent da186f2efb
commit 819c6c6f86
9 changed files with 20 additions and 52 deletions

View File

@@ -147,7 +147,7 @@ bool DiagramEventAddElement::keyPressEvent(QKeyEvent *event)
{
if (m_element && event->key() == Qt::Key_Space)
{
m_element->rotateBy(90);
m_element->setRotation(m_element->rotation() + 90);
return true;
}

View File

@@ -74,7 +74,7 @@ bool DiagramEventAddImage::mousePressEvent(QGraphicsSceneMouseEvent *event)
if (m_image && event -> button() == Qt::RightButton)
{
m_image -> rotateBy(90);
m_image->setRotation(m_image->rotation() + 90);
return true;
}

View File

@@ -142,7 +142,7 @@ bool DiagramImageItem::fromXml(const QDomElement &e) {
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 @@ QDomElement DiagramImageItem::toXml(QDomDocument &document) const {
//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_));

View File

@@ -73,6 +73,14 @@ Element::Element(QGraphicsItem *parent) :
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 @@ QPixmap Element::pixmap() {
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 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
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,

View File

@@ -176,7 +176,6 @@ class Element : public QetGraphicsItem
void select();
void deselect();
void rotateBy(const qreal &) override;
void editProperty() override;
// methods related to XML import/export

View File

@@ -82,9 +82,9 @@ bool GhostElement::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr,
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);
}

View File

@@ -64,26 +64,6 @@ void QetGraphicsItem::setPos(qreal x, qreal y) {
setPos(QPointF(x, y));
}
/**
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

View File

@@ -35,8 +35,6 @@ class QetGraphicsItem : public QGraphicsObject
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;}

View File

@@ -78,7 +78,7 @@ void RotateSelectionCommand::undo()
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 @@ void RotateSelectionCommand::undo()
}
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 @@ void RotateSelectionCommand::redo()
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 @@ void RotateSelectionCommand::redo()
}
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);