mirror of
https://github.com/qgis/QGIS.git
synced 2025-05-02 00:05:04 -04:00
[composer] Fix scaling of symbology within composer shapes and pages (fix #10609)
This commit is contained in:
parent
5dc75d424e
commit
60d93b35cd
@ -166,19 +166,16 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
|
|||||||
p->save();
|
p->save();
|
||||||
p->setRenderHint( QPainter::Antialiasing );
|
p->setRenderHint( QPainter::Antialiasing );
|
||||||
|
|
||||||
QgsRenderContext context;
|
//setup painter scaling to dots so that raster symbology is drawn to scale
|
||||||
|
double dotsPerMM = p->device()->logicalDpiX() / 25.4;
|
||||||
|
|
||||||
|
//setup render context
|
||||||
|
QgsMapSettings ms = mComposition->mapSettings();
|
||||||
|
//context units should be in dots
|
||||||
|
ms.setOutputDpi( p->device()->logicalDpiX() );
|
||||||
|
QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
|
||||||
context.setPainter( p );
|
context.setPainter( p );
|
||||||
context.setScaleFactor( 1.0 );
|
p->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
|
||||||
if ( mComposition->plotStyle() == QgsComposition::Preview )
|
|
||||||
{
|
|
||||||
//Limit resolution of symbol fill if composition is not being exported
|
|
||||||
//otherwise zooming into composition slows down renders
|
|
||||||
context.setRasterScaleFactor( qMin( horizontalViewScaleFactor(), 3.0 ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.setRasterScaleFactor( mComposition->printResolution() / 25.4 );
|
|
||||||
}
|
|
||||||
|
|
||||||
//generate polygon to draw
|
//generate polygon to draw
|
||||||
QList<QPolygonF> rings; //empty list
|
QList<QPolygonF> rings; //empty list
|
||||||
@ -196,7 +193,7 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
|
|||||||
{
|
{
|
||||||
//create an ellipse
|
//create an ellipse
|
||||||
QPainterPath ellipsePath;
|
QPainterPath ellipsePath;
|
||||||
ellipsePath.addEllipse( QRectF( 0, 0 , rect().width(), rect().height() ) );
|
ellipsePath.addEllipse( QRectF( 0, 0 , rect().width() * dotsPerMM, rect().height() * dotsPerMM ) );
|
||||||
QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
|
QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
|
||||||
shapePolygon = ti.map( ellipsePoly );
|
shapePolygon = ti.map( ellipsePoly );
|
||||||
break;
|
break;
|
||||||
@ -207,22 +204,22 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
|
|||||||
if ( mCornerRadius > 0 )
|
if ( mCornerRadius > 0 )
|
||||||
{
|
{
|
||||||
QPainterPath roundedRectPath;
|
QPainterPath roundedRectPath;
|
||||||
roundedRectPath.addRoundedRect( QRectF( 0, 0 , rect().width(), rect().height() ), mCornerRadius, mCornerRadius );
|
roundedRectPath.addRoundedRect( QRectF( 0, 0 , rect().width() * dotsPerMM, rect().height() * dotsPerMM ), mCornerRadius * dotsPerMM, mCornerRadius * dotsPerMM );
|
||||||
QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t );
|
QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t );
|
||||||
shapePolygon = ti.map( roundedPoly );
|
shapePolygon = ti.map( roundedPoly );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shapePolygon = QPolygonF( QRectF( 0, 0, rect().width(), rect().height() ) );
|
shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ) );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Triangle:
|
case Triangle:
|
||||||
{
|
{
|
||||||
shapePolygon << QPointF( 0, rect().height() );
|
shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
|
||||||
shapePolygon << QPointF( rect().width() , rect().height() );
|
shapePolygon << QPointF( rect().width() * dotsPerMM, rect().height() * dotsPerMM );
|
||||||
shapePolygon << QPointF( rect().width() / 2.0, 0 );
|
shapePolygon << QPointF( rect().width() / 2.0 * dotsPerMM, 0 );
|
||||||
shapePolygon << QPointF( 0, rect().height() );
|
shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,19 +154,15 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsRenderContext context;
|
//setup painter scaling to dots so that raster symbology is drawn to scale
|
||||||
|
double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
|
||||||
|
|
||||||
|
//setup render context
|
||||||
|
QgsMapSettings ms = mComposition->mapSettings();
|
||||||
|
//context units should be in dots
|
||||||
|
ms.setOutputDpi( painter->device()->logicalDpiX() );
|
||||||
|
QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
|
||||||
context.setPainter( painter );
|
context.setPainter( painter );
|
||||||
context.setScaleFactor( 1.0 );
|
|
||||||
if ( mComposition->plotStyle() == QgsComposition::Preview )
|
|
||||||
{
|
|
||||||
//Limit resolution of symbol fill if composition is not being exported
|
|
||||||
//otherwise zooming into composition slows down renders
|
|
||||||
context.setRasterScaleFactor( qMin( horizontalViewScaleFactor(), 3.0 ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.setRasterScaleFactor( mComposition->printResolution() / 25.4 );
|
|
||||||
}
|
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
@ -187,11 +183,14 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
|
|||||||
painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
|
painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
|
||||||
|
|
||||||
painter->setRenderHint( QPainter::Antialiasing );
|
painter->setRenderHint( QPainter::Antialiasing );
|
||||||
mComposition->pageStyleSymbol()->startRender( context );
|
mComposition->pageStyleSymbol()->startRender( context );
|
||||||
|
|
||||||
calculatePageMargin();
|
calculatePageMargin();
|
||||||
QPolygonF pagePolygon = QPolygonF( QRectF( mPageMargin, mPageMargin, rect().width() - 2 * mPageMargin, rect().height() - 2 * mPageMargin ) );
|
QPolygonF pagePolygon = QPolygonF( QRectF( mPageMargin * dotsPerMM, mPageMargin * dotsPerMM,
|
||||||
|
( rect().width() - 2 * mPageMargin ) * dotsPerMM, ( rect().height() - 2 * mPageMargin ) * dotsPerMM ) );
|
||||||
QList<QPolygonF> rings; //empty list
|
QList<QPolygonF> rings; //empty list
|
||||||
|
|
||||||
//need to render using atlas feature properties?
|
//need to render using atlas feature properties?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user