mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
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:
@@ -147,7 +147,7 @@ bool DiagramEventAddElement::keyPressEvent(QKeyEvent *event)
|
|||||||
{
|
{
|
||||||
if (m_element && event->key() == Qt::Key_Space)
|
if (m_element && event->key() == Qt::Key_Space)
|
||||||
{
|
{
|
||||||
m_element->rotateBy(90);
|
m_element->setRotation(m_element->rotation() + 90);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ bool DiagramEventAddImage::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
|
|
||||||
if (m_image && event -> button() == Qt::RightButton)
|
if (m_image && event -> button() == Qt::RightButton)
|
||||||
{
|
{
|
||||||
m_image -> rotateBy(90);
|
m_image->setRotation(m_image->rotation() + 90);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ bool DiagramImageItem::fromXml(const QDomElement &e) {
|
|||||||
setPixmap(pixmap);
|
setPixmap(pixmap);
|
||||||
|
|
||||||
setScale(e.attribute("size").toDouble());
|
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
|
//We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
|
||||||
QGraphicsObject::setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
QGraphicsObject::setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
||||||
is_movable_ = (e.attribute("is_movable").toInt());
|
is_movable_ = (e.attribute("is_movable").toInt());
|
||||||
@@ -159,7 +159,7 @@ QDomElement DiagramImageItem::toXml(QDomDocument &document) const {
|
|||||||
//write some attribute
|
//write some attribute
|
||||||
result.setAttribute("x", QString("%1").arg(pos().x()));
|
result.setAttribute("x", QString("%1").arg(pos().x()));
|
||||||
result.setAttribute("y", QString("%1").arg(pos().y()));
|
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("size", QString("%1").arg(scale()));
|
||||||
result.setAttribute("is_movable", bool(is_movable_));
|
result.setAttribute("is_movable", bool(is_movable_));
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,14 @@ Element::Element(QGraphicsItem *parent) :
|
|||||||
setZValue(10);
|
setZValue(10);
|
||||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
setAcceptHoverEvents(true);
|
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);
|
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 ***/
|
/*** 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);
|
int read_ori = e.attribute("orientation").toInt(&conv_ok);
|
||||||
if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0;
|
if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0;
|
||||||
if (handle_inputs_rotation) {
|
if (handle_inputs_rotation) {
|
||||||
rotateBy(90*read_ori);
|
setRotation(rotation() + (90*read_ori));
|
||||||
} else {
|
} else {
|
||||||
applyRotation(90*read_ori);
|
setRotation(90*read_ori);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Befor load the dynamic text field,
|
//Befor load the dynamic text field,
|
||||||
|
|||||||
@@ -176,7 +176,6 @@ class Element : public QetGraphicsItem
|
|||||||
void select();
|
void select();
|
||||||
void deselect();
|
void deselect();
|
||||||
|
|
||||||
void rotateBy(const qreal &) override;
|
|
||||||
void editProperty() override;
|
void editProperty() override;
|
||||||
|
|
||||||
// methods related to XML import/export
|
// methods related to XML import/export
|
||||||
|
|||||||
@@ -82,9 +82,9 @@ bool GhostElement::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr,
|
|||||||
int read_ori = e.attribute("orientation").toInt(&conv_ok);
|
int read_ori = e.attribute("orientation").toInt(&conv_ok);
|
||||||
if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0;
|
if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0;
|
||||||
if (handle_inputs_rotation) {
|
if (handle_inputs_rotation) {
|
||||||
rotateBy(90*read_ori);
|
setRotation(rotation() + (90*read_ori));
|
||||||
} else {
|
} else {
|
||||||
applyRotation(90*read_ori);
|
setRotation(90*read_ori);
|
||||||
}
|
}
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,26 +64,6 @@ void QetGraphicsItem::setPos(qreal x, qreal y) {
|
|||||||
setPos(QPointF(x, 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
|
* @brief QetGraphicsItem::mousePressEvent
|
||||||
*handle the mouse click
|
*handle the mouse click
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ class QetGraphicsItem : public QGraphicsObject
|
|||||||
Diagram *diagram () const;
|
Diagram *diagram () const;
|
||||||
virtual void setPos (const QPointF &p);
|
virtual void setPos (const QPointF &p);
|
||||||
virtual void setPos (qreal x, qreal y);
|
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 bool isMovable () const {return is_movable_;}
|
||||||
virtual void setMovable (bool movable) { is_movable_ = movable;}
|
virtual void setMovable (bool movable) { is_movable_ = movable;}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ void RotateSelectionCommand::undo()
|
|||||||
|
|
||||||
for(QPointer<Element> elmt : m_element)
|
for(QPointer<Element> elmt : m_element)
|
||||||
if(elmt)
|
if(elmt)
|
||||||
elmt.data()->rotateBy(-m_angle);
|
elmt.data()->setRotation(elmt.data()->rotation() - m_angle);
|
||||||
for(QPointer<DiagramTextItem> text : m_text)
|
for(QPointer<DiagramTextItem> text : m_text)
|
||||||
{
|
{
|
||||||
if(text)
|
if(text)
|
||||||
@@ -98,7 +98,7 @@ void RotateSelectionCommand::undo()
|
|||||||
}
|
}
|
||||||
for(QPointer<DiagramImageItem> image : m_image)
|
for(QPointer<DiagramImageItem> image : m_image)
|
||||||
if(image)
|
if(image)
|
||||||
image.data()->rotateBy(-m_angle);
|
image.data()->setRotation(image.data()->rotation() - m_angle);
|
||||||
for(QPointer<ElementTextItemGroup> group : m_group)
|
for(QPointer<ElementTextItemGroup> group : m_group)
|
||||||
if(group)
|
if(group)
|
||||||
group.data()->setRotation(group.data()->rotation() - m_angle);
|
group.data()->setRotation(group.data()->rotation() - m_angle);
|
||||||
@@ -113,7 +113,7 @@ void RotateSelectionCommand::redo()
|
|||||||
|
|
||||||
for(QPointer<Element> elmt : m_element)
|
for(QPointer<Element> elmt : m_element)
|
||||||
if(elmt)
|
if(elmt)
|
||||||
elmt.data()->rotateBy(m_angle);
|
elmt.data()->setRotation(elmt.data()->rotation() + m_angle);
|
||||||
for(QPointer<DiagramTextItem> text : m_text)
|
for(QPointer<DiagramTextItem> text : m_text)
|
||||||
{
|
{
|
||||||
if(text)
|
if(text)
|
||||||
@@ -129,7 +129,7 @@ void RotateSelectionCommand::redo()
|
|||||||
}
|
}
|
||||||
for(QPointer<DiagramImageItem> image : m_image)
|
for(QPointer<DiagramImageItem> image : m_image)
|
||||||
if(image)
|
if(image)
|
||||||
image.data()->rotateBy(m_angle);
|
image.data()->setRotation(image.data()->rotation() + m_angle);
|
||||||
for(QPointer<ElementTextItemGroup> group : m_group)
|
for(QPointer<ElementTextItemGroup> group : m_group)
|
||||||
if(group)
|
if(group)
|
||||||
group.data()->setRotation(group.data()->rotation() + m_angle);
|
group.data()->setRotation(group.data()->rotation() + m_angle);
|
||||||
|
|||||||
Reference in New Issue
Block a user