Skip to content
Permalink
Browse files

Fix huge legend item size when symbol uses map unit sizes (fix #13979)

Add unit test
  • Loading branch information
nyalldawson committed Apr 11, 2016
1 parent e21de03 commit 0c5fa81126cec652d9e9932861f031c1ab3700db
@@ -362,15 +362,15 @@ QSizeF QgsSymbolV2LegendNode::drawSymbol( const QgsLegendSettings& settings, Ite
//Consider symbol size for point markers
double height = settings.symbolSize().height();
double width = settings.symbolSize().width();
double size = 0;

//Center small marker symbols
double widthOffset = 0;
double heightOffset = 0;

if ( QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( s ) )
{
// allow marker symbol to occupy bigger area if necessary
size = QgsSymbolLayerV2Utils::convertToPainterUnits( context, markerSymbol->size(), s->outputUnit(), s->mapUnitScale() ) / context.scaleFactor();
double size = QgsSymbolLayerV2Utils::convertToPainterUnits( context, markerSymbol->size(), markerSymbol->sizeUnit(), markerSymbol->sizeMapUnitScale() ) / context.scaleFactor();
height = size;
width = size;
if ( width < settings.symbolSize().width() )
@@ -110,6 +110,7 @@ class TestQgsLegendRenderer : public QObject

void testBasic();
void testBigMarker();
void testMapUnits();
void testLongSymbolText();
void testThreeColumns();
void testFilterByMap();
@@ -290,6 +291,42 @@ void TestQgsLegendRenderer::testBigMarker()
QVERIFY( _verifyImage( testName, mReport ) );
}

void TestQgsLegendRenderer::testMapUnits()
{
QString testName = "legend_mapunits";

QgsMarkerSymbolV2* sym = new QgsMarkerSymbolV2();
sym->setColor( Qt::red );
sym->setSize( 100 );
sym->setSizeUnit( QgsSymbolV2::MapUnit );
QgsCategorizedSymbolRendererV2* catRenderer = dynamic_cast<QgsCategorizedSymbolRendererV2*>( mVL3->rendererV2() );
QVERIFY( catRenderer );
catRenderer->updateCategorySymbol( 0, sym );

sym = new QgsMarkerSymbolV2();
sym->setColor( Qt::green );
sym->setSize( 300 );
sym->setSizeUnit( QgsSymbolV2::MapUnit );
catRenderer->updateCategorySymbol( 1, sym );

sym = new QgsMarkerSymbolV2();
sym->setColor( Qt::blue );
sym->setSize( 5 );
sym->setSizeUnit( QgsSymbolV2::MM );
catRenderer->updateCategorySymbol( 2, sym );

QgsLayerTreeGroup* root = new QgsLayerTreeGroup();
root->addLayer( mVL3 );
QgsLayerTreeModel legendModel( root );

QgsLegendSettings settings;
_setStandardTestFont( settings );
settings.setMmPerMapUnit( 0.1 );
settings.setMapScale( 1000 );
_renderLegend( testName, &legendModel, settings );
QVERIFY( _verifyImage( testName, mReport ) );
}

void TestQgsLegendRenderer::testLongSymbolText()
{
QString testName = "legend_long_symbol_text";
Binary file not shown.
Binary file not shown.

0 comments on commit 0c5fa81

Please sign in to comment.
You can’t perform that action at this time.