From 06e8c6734d797229bc728fcaf0e34b6fdeefe5e7 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Thu, 3 Nov 2016 10:37:59 -0400 Subject: [PATCH] Fix scaled QGIViewSymbol boundingRect --- src/Mod/TechDraw/Gui/QGCustomSvg.cpp | 30 +++++++++++++++----------- src/Mod/TechDraw/Gui/QGIViewSymbol.cpp | 4 ++-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Mod/TechDraw/Gui/QGCustomSvg.cpp b/src/Mod/TechDraw/Gui/QGCustomSvg.cpp index 0469e68b4..aad1a8f63 100644 --- a/src/Mod/TechDraw/Gui/QGCustomSvg.cpp +++ b/src/Mod/TechDraw/Gui/QGCustomSvg.cpp @@ -51,22 +51,26 @@ QGCustomSvg::~QGCustomSvg() void QGCustomSvg::centerAt(QPointF centerPos) { - QRectF box = boundingRect(); - double width = box.width(); - double height = box.height(); - double newX = centerPos.x() - width/2.; - double newY = centerPos.y() - height/2.; - setPos(newX,newY); + if (group()) { + QRectF box = group()->boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = centerPos.x() - width/2.; + double newY = centerPos.y() - height/2.; + setPos(newX,newY); + } } void QGCustomSvg::centerAt(double cX, double cY) { - QRectF box = boundingRect(); - double width = box.width(); - double height = box.height(); - double newX = cX - width/2.; - double newY = cY - height/2.; - setPos(newX,newY); + if (group()) { + QRectF box = group()->boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = cX - width/2.; + double newY = cY - height/2.; + setPos(newX,newY); + } } bool QGCustomSvg::load(QByteArray *svgBytes) @@ -82,7 +86,7 @@ QRectF QGCustomSvg::boundingRect() const QRectF box = m_svgRender->viewBoxF(); double w = box.width(); double h = box.height(); - QRectF newRect(0,0,w*scale(),h*scale()); + QRectF newRect(0,0,w,h); return newRect.adjusted(-1.,-1.,1.,1.); } diff --git a/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp b/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp index 41698244e..7c7511bea 100644 --- a/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp @@ -59,7 +59,7 @@ QGIViewSymbol::QGIViewSymbol() m_svgItem = new QGCustomSvg(); addToGroup(m_svgItem); - m_svgItem->setPos(0.,0.); + m_svgItem->centerAt(0.,0.); } QGIViewSymbol::~QGIViewSymbol() @@ -137,5 +137,5 @@ void QGIViewSymbol::symbolToSvg(QByteArray qba) if (!m_svgItem->load(&qba)) { Base::Console().Error("Error - Could not load Symbol into SVG renderer for %s\n", getViewObject()->getNameInDocument()); } - m_svgItem->setPos(0.,0.); + m_svgItem->centerAt(0.,0.); }