Skip to content

Commit 60d93b3

Browse files
committed
[composer] Fix scaling of symbology within composer shapes and pages (fix #10609)
1 parent 5dc75d4 commit 60d93b3

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

src/core/composer/qgscomposershape.cpp

+16-19
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,16 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
166166
p->save();
167167
p->setRenderHint( QPainter::Antialiasing );
168168

169-
QgsRenderContext context;
169+
//setup painter scaling to dots so that raster symbology is drawn to scale
170+
double dotsPerMM = p->device()->logicalDpiX() / 25.4;
171+
172+
//setup render context
173+
QgsMapSettings ms = mComposition->mapSettings();
174+
//context units should be in dots
175+
ms.setOutputDpi( p->device()->logicalDpiX() );
176+
QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
170177
context.setPainter( p );
171-
context.setScaleFactor( 1.0 );
172-
if ( mComposition->plotStyle() == QgsComposition::Preview )
173-
{
174-
//Limit resolution of symbol fill if composition is not being exported
175-
//otherwise zooming into composition slows down renders
176-
context.setRasterScaleFactor( qMin( horizontalViewScaleFactor(), 3.0 ) );
177-
}
178-
else
179-
{
180-
context.setRasterScaleFactor( mComposition->printResolution() / 25.4 );
181-
}
178+
p->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
182179

183180
//generate polygon to draw
184181
QList<QPolygonF> rings; //empty list
@@ -196,7 +193,7 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
196193
{
197194
//create an ellipse
198195
QPainterPath ellipsePath;
199-
ellipsePath.addEllipse( QRectF( 0, 0 , rect().width(), rect().height() ) );
196+
ellipsePath.addEllipse( QRectF( 0, 0 , rect().width() * dotsPerMM, rect().height() * dotsPerMM ) );
200197
QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
201198
shapePolygon = ti.map( ellipsePoly );
202199
break;
@@ -207,22 +204,22 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
207204
if ( mCornerRadius > 0 )
208205
{
209206
QPainterPath roundedRectPath;
210-
roundedRectPath.addRoundedRect( QRectF( 0, 0 , rect().width(), rect().height() ), mCornerRadius, mCornerRadius );
207+
roundedRectPath.addRoundedRect( QRectF( 0, 0 , rect().width() * dotsPerMM, rect().height() * dotsPerMM ), mCornerRadius * dotsPerMM, mCornerRadius * dotsPerMM );
211208
QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t );
212209
shapePolygon = ti.map( roundedPoly );
213210
}
214211
else
215212
{
216-
shapePolygon = QPolygonF( QRectF( 0, 0, rect().width(), rect().height() ) );
213+
shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ) );
217214
}
218215
break;
219216
}
220217
case Triangle:
221218
{
222-
shapePolygon << QPointF( 0, rect().height() );
223-
shapePolygon << QPointF( rect().width() , rect().height() );
224-
shapePolygon << QPointF( rect().width() / 2.0, 0 );
225-
shapePolygon << QPointF( 0, rect().height() );
219+
shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
220+
shapePolygon << QPointF( rect().width() * dotsPerMM, rect().height() * dotsPerMM );
221+
shapePolygon << QPointF( rect().width() / 2.0 * dotsPerMM, 0 );
222+
shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
226223
break;
227224
}
228225
}

src/core/composer/qgspaperitem.cpp

+12-13
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,15 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
154154
return;
155155
}
156156

157-
QgsRenderContext context;
157+
//setup painter scaling to dots so that raster symbology is drawn to scale
158+
double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
159+
160+
//setup render context
161+
QgsMapSettings ms = mComposition->mapSettings();
162+
//context units should be in dots
163+
ms.setOutputDpi( painter->device()->logicalDpiX() );
164+
QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
158165
context.setPainter( painter );
159-
context.setScaleFactor( 1.0 );
160-
if ( mComposition->plotStyle() == QgsComposition::Preview )
161-
{
162-
//Limit resolution of symbol fill if composition is not being exported
163-
//otherwise zooming into composition slows down renders
164-
context.setRasterScaleFactor( qMin( horizontalViewScaleFactor(), 3.0 ) );
165-
}
166-
else
167-
{
168-
context.setRasterScaleFactor( mComposition->printResolution() / 25.4 );
169-
}
170166

171167
painter->save();
172168

@@ -187,11 +183,14 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
187183
painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
188184
}
189185

186+
painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
187+
190188
painter->setRenderHint( QPainter::Antialiasing );
191189
mComposition->pageStyleSymbol()->startRender( context );
192190

193191
calculatePageMargin();
194-
QPolygonF pagePolygon = QPolygonF( QRectF( mPageMargin, mPageMargin, rect().width() - 2 * mPageMargin, rect().height() - 2 * mPageMargin ) );
192+
QPolygonF pagePolygon = QPolygonF( QRectF( mPageMargin * dotsPerMM, mPageMargin * dotsPerMM,
193+
( rect().width() - 2 * mPageMargin ) * dotsPerMM, ( rect().height() - 2 * mPageMargin ) * dotsPerMM ) );
195194
QList<QPolygonF> rings; //empty list
196195

197196
//need to render using atlas feature properties?

0 commit comments

Comments
 (0)