mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -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->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.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 );
|
||||
}
|
||||
p->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
|
||||
|
||||
//generate polygon to draw
|
||||
QList<QPolygonF> rings; //empty list
|
||||
@ -196,7 +193,7 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
|
||||
{
|
||||
//create an ellipse
|
||||
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 );
|
||||
shapePolygon = ti.map( ellipsePoly );
|
||||
break;
|
||||
@ -207,22 +204,22 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
|
||||
if ( mCornerRadius > 0 )
|
||||
{
|
||||
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 );
|
||||
shapePolygon = ti.map( roundedPoly );
|
||||
}
|
||||
else
|
||||
{
|
||||
shapePolygon = QPolygonF( QRectF( 0, 0, rect().width(), rect().height() ) );
|
||||
shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Triangle:
|
||||
{
|
||||
shapePolygon << QPointF( 0, rect().height() );
|
||||
shapePolygon << QPointF( rect().width() , rect().height() );
|
||||
shapePolygon << QPointF( rect().width() / 2.0, 0 );
|
||||
shapePolygon << QPointF( 0, rect().height() );
|
||||
shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
|
||||
shapePolygon << QPointF( rect().width() * dotsPerMM, rect().height() * dotsPerMM );
|
||||
shapePolygon << QPointF( rect().width() / 2.0 * dotsPerMM, 0 );
|
||||
shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -154,19 +154,15 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
|
||||
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.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();
|
||||
|
||||
@ -187,11 +183,14 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
|
||||
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 );
|
||||
mComposition->pageStyleSymbol()->startRender( context );
|
||||
|
||||
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
|
||||
|
||||
//need to render using atlas feature properties?
|
||||
|
Loading…
x
Reference in New Issue
Block a user