[legend] Fix alignment and chopped off text of collapsed data-defined size legend symbol (#9228)

This commit is contained in:
Mathieu Pellerin 2019-02-22 15:18:06 +07:00 committed by GitHub
parent fcdb4c025c
commit 78e8c34200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 3 deletions

View File

@ -178,16 +178,18 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q
if ( w > maxTextWidth )
maxTextWidth = w;
}
// add extra width needed to handle varying rendering of font weight
maxTextWidth += 1;
// find out size of the largest symbol
double largestSize = classes.at( 0 ).size;
double outputLargestSize = context.convertToPainterUnits( largestSize, s->sizeUnit(), s->sizeMapUnitScale() );
int outputLargestSize = std::round( context.convertToPainterUnits( largestSize, s->sizeUnit(), s->sizeMapUnitScale() ) );
// find out top Y coordinate for individual symbol sizes
QList<int> symbolTopY;
Q_FOREACH ( const SizeClass &c, classes )
{
double outputSymbolSize = context.convertToPainterUnits( c.size, s->sizeUnit(), s->sizeMapUnitScale() );
int outputSymbolSize = std::round( context.convertToPainterUnits( c.size, s->sizeUnit(), s->sizeMapUnitScale() ) );
switch ( mVAlign )
{
case AlignCenter:
@ -243,7 +245,7 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q
{
s->setSize( c.size );
double outputSymbolSize = context.convertToPainterUnits( c.size, s->sizeUnit(), s->sizeMapUnitScale() );
int outputSymbolSize = std::round( context.convertToPainterUnits( c.size, s->sizeUnit(), s->sizeMapUnitScale() ) );
double tx = ( outputLargestSize - outputSymbolSize ) / 2;
p->save();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB