Fix scaled QGIViewSymbol boundingRect

This commit is contained in:
WandererFan 2016-11-03 10:37:59 -04:00
parent a812ad2d5e
commit 06e8c6734d
2 changed files with 19 additions and 15 deletions

View File

@ -51,23 +51,27 @@ QGCustomSvg::~QGCustomSvg()
void QGCustomSvg::centerAt(QPointF centerPos) void QGCustomSvg::centerAt(QPointF centerPos)
{ {
QRectF box = boundingRect(); if (group()) {
QRectF box = group()->boundingRect();
double width = box.width(); double width = box.width();
double height = box.height(); double height = box.height();
double newX = centerPos.x() - width/2.; double newX = centerPos.x() - width/2.;
double newY = centerPos.y() - height/2.; double newY = centerPos.y() - height/2.;
setPos(newX,newY); setPos(newX,newY);
} }
}
void QGCustomSvg::centerAt(double cX, double cY) void QGCustomSvg::centerAt(double cX, double cY)
{ {
QRectF box = boundingRect(); if (group()) {
QRectF box = group()->boundingRect();
double width = box.width(); double width = box.width();
double height = box.height(); double height = box.height();
double newX = cX - width/2.; double newX = cX - width/2.;
double newY = cY - height/2.; double newY = cY - height/2.;
setPos(newX,newY); setPos(newX,newY);
} }
}
bool QGCustomSvg::load(QByteArray *svgBytes) bool QGCustomSvg::load(QByteArray *svgBytes)
{ {
@ -82,7 +86,7 @@ QRectF QGCustomSvg::boundingRect() const
QRectF box = m_svgRender->viewBoxF(); QRectF box = m_svgRender->viewBoxF();
double w = box.width(); double w = box.width();
double h = box.height(); 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.); return newRect.adjusted(-1.,-1.,1.,1.);
} }

View File

@ -59,7 +59,7 @@ QGIViewSymbol::QGIViewSymbol()
m_svgItem = new QGCustomSvg(); m_svgItem = new QGCustomSvg();
addToGroup(m_svgItem); addToGroup(m_svgItem);
m_svgItem->setPos(0.,0.); m_svgItem->centerAt(0.,0.);
} }
QGIViewSymbol::~QGIViewSymbol() QGIViewSymbol::~QGIViewSymbol()
@ -137,5 +137,5 @@ void QGIViewSymbol::symbolToSvg(QByteArray qba)
if (!m_svgItem->load(&qba)) { if (!m_svgItem->load(&qba)) {
Base::Console().Error("Error - Could not load Symbol into SVG renderer for %s\n", getViewObject()->getNameInDocument()); 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.);
} }