Skip to content

Commit 45d4793

Browse files
committed
Followup fix for #11006 (spotted by Nyall - thanks)
1 parent d994e0a commit 45d4793

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/core/composer/qgscomposerlegend.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,28 @@ void QgsComposerLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem
6363
Q_UNUSED( itemStyle );
6464
Q_UNUSED( pWidget );
6565

66+
if ( !painter )
67+
return;
68+
69+
int dpi = painter->device()->logicalDpiX();
70+
double dotsPerMM = dpi / 25.4;
6671

6772
if ( mComposition )
6873
{
6974
mSettings.setUseAdvancedEffects( mComposition->useAdvancedEffects() );
70-
mSettings.setMapScale( mComposition->mapSettings().scale() );
71-
mSettings.setDpi( painter->device()->logicalDpiX() );
75+
mSettings.setDpi( dpi );
7276
}
7377
if ( mComposerMap )
78+
{
7479
mSettings.setMmPerMapUnit( mComposerMap->mapUnitsToMM() );
7580

76-
if ( !painter )
77-
return;
81+
// use a temporary QgsMapSettings to find out real map scale
82+
QgsMapSettings ms = mComposerMap->composition()->mapSettings();
83+
ms.setOutputSize( QSizeF( mComposerMap->rect().width() * dotsPerMM, mComposerMap->rect().height() * dotsPerMM ).toSize() );
84+
ms.setExtent( *mComposerMap->currentMapExtent() );
85+
ms.setOutputDpi( dpi );
86+
mSettings.setMapScale( ms.scale() );
87+
}
7888

7989
drawBackground( painter );
8090
painter->save();

0 commit comments

Comments
 (0)