Skip to content

Commit

Permalink
[composer] Fix scaling of symbology within composer shapes and pages (f…
Browse files Browse the repository at this point in the history
…ix #10609)
  • Loading branch information
nyalldawson committed Jun 18, 2014
1 parent 5dc75d4 commit 60d93b3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
35 changes: 16 additions & 19 deletions src/core/composer/qgscomposershape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
}
Expand Down
25 changes: 12 additions & 13 deletions src/core/composer/qgspaperitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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?
Expand Down

0 comments on commit 60d93b3

Please sign in to comment.