From d9a0b03e23a165a1cf447e3cc8a312e57b0ed95a Mon Sep 17 00:00:00 2001 From: joshua Date: Fri, 15 Jul 2022 20:48:06 +0200 Subject: [PATCH] Minor : add QGIUtility namespace --- sources/qetgraphicsitem/crossrefitem.cpp | 4 ++-- sources/qetgraphicsitem/elementtextitemgroup.cpp | 2 +- sources/qetgraphicsitem/qgraphicsitemutility.cpp | 16 +++++++++++----- sources/qetgraphicsitem/qgraphicsitemutility.h | 9 +++++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/sources/qetgraphicsitem/crossrefitem.cpp b/sources/qetgraphicsitem/crossrefitem.cpp index 49700af99..3ebe3400a 100644 --- a/sources/qetgraphicsitem/crossrefitem.cpp +++ b/sources/qetgraphicsitem/crossrefitem.cpp @@ -253,13 +253,13 @@ void CrossRefItem::autoPos() { //We calcul the position according to the snapTo of the xrefproperties if (m_properties.snapTo() == XRefProperties::Bottom) - centerToBottomDiagram(this, + QGIUtility::centerToBottomDiagram(this, m_element, m_properties.offset() <= 40 ? 5 : m_properties.offset()); else - centerToParentBottom(this); + QGIUtility::centerToParentBottom(this); } /** diff --git a/sources/qetgraphicsitem/elementtextitemgroup.cpp b/sources/qetgraphicsitem/elementtextitemgroup.cpp index c36b5be74..d4a20bdd0 100644 --- a/sources/qetgraphicsitem/elementtextitemgroup.cpp +++ b/sources/qetgraphicsitem/elementtextitemgroup.cpp @@ -861,7 +861,7 @@ void ElementTextItemGroup::autoPos() } } qreal r = rotation(); - centerToBottomDiagram(this, m_parent_element, offset); + QGIUtility::centerToBottomDiagram(this, m_parent_element, offset); //centerToBottomDiagram change the rotation of this group if needed, //but setRotation is not a virtual function of QGraphicsItem, and the function centerToBottomDiagram //work with a QGraphicsItem. So we emit the signal if rotation changed diff --git a/sources/qetgraphicsitem/qgraphicsitemutility.cpp b/sources/qetgraphicsitem/qgraphicsitemutility.cpp index d314997c2..765980f77 100644 --- a/sources/qetgraphicsitem/qgraphicsitemutility.cpp +++ b/sources/qetgraphicsitem/qgraphicsitemutility.cpp @@ -23,6 +23,9 @@ #include #include +namespace QGIUtility +{ + /** @brief centerToParentBottom Center the item at the bottom of is parent. @@ -51,10 +54,10 @@ bool centerToParentBottom(QGraphicsItem *item) { @param offset @return true if element is centered else false (element_to_follow have not diagram) */ -#include "elementtextitemgroup.h" -#include "crossrefitem.h" -bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset) { - if (! element_to_follow -> diagram()) { +bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset) +{ + if (! element_to_follow -> diagram()) + { qDebug() << "qgraphicsitemutility centerAtBottomDiagram : Element_to_follow have not diagram"; return false; } @@ -81,8 +84,11 @@ bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_f rot += parent->rotation(); parent = parent->parentItem(); } - if(rot != 0) + if(rot != 0) { item_to_center->setRotation(item_to_center->rotation() - rot); + } return true; } +} + diff --git a/sources/qetgraphicsitem/qgraphicsitemutility.h b/sources/qetgraphicsitem/qgraphicsitemutility.h index 453849d46..2bb660696 100644 --- a/sources/qetgraphicsitem/qgraphicsitemutility.h +++ b/sources/qetgraphicsitem/qgraphicsitemutility.h @@ -17,11 +17,16 @@ */ #ifndef QGRAPHICSITEMUTILITY_H #define QGRAPHICSITEMUTILITY_H + #include + class QGraphicsItem; class Element; -bool centerToParentBottom (QGraphicsItem *item); -bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset = 0 ); +namespace QGIUtility +{ + bool centerToParentBottom (QGraphicsItem *item); + bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, qreal offset = 0 ); +} #endif // QGRAPHICSITEMUTILITY_H