@@ -343,7 +343,6 @@ QImage* QgsWMSServer::getLegendGraphics()
343343 double mmToPixelFactor = theImage->dotsPerMeterX () / 1000.0 ;
344344 double maxTextWidth = 0 ;
345345 double maxSymbolWidth = 0 ;
346- double currentY = 0 ;
347346 double fontOversamplingFactor = 10.0 ;
348347
349348 // get icon size, spaces between legend items and font from config parser
@@ -360,29 +359,9 @@ QImage* QgsWMSServer::getLegendGraphics()
360359 return 0 ;
361360 }
362361
363- int numLayerItems = rootItem->rowCount ();
364- if ( numLayerItems < 1 )
365- {
366- return 0 ;
367- }
368-
369- currentY = boxSpace;
370- for ( int i = 0 ; i < numLayerItems; ++i )
371- {
372- QgsComposerLayerItem* layerItem = dynamic_cast <QgsComposerLayerItem*>( rootItem->child ( i ) );
373- if ( layerItem )
374- {
375- if ( i > 0 )
376- {
377- currentY += layerSpace;
378- }
379- drawLegendLayerItem ( layerItem, 0 , maxTextWidth, maxSymbolWidth, currentY, layerFont, layerFontColor, itemFont, itemFontColor,
380- boxSpace, layerSpace, layerTitleSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight, fontOversamplingFactor,
381- theImage->dotsPerMeterX () * 0.0254 );
382- }
383- currentY += layerSpace;
384- }
385- currentY += boxSpace;
362+ double currentY = drawLegendGraphics ( 0 , fontOversamplingFactor, rootItem, boxSpace, layerSpace, layerTitleSpace, symbolSpace,
363+ iconLabelSpace, symbolWidth, symbolHeight, layerFont, itemFont, layerFontColor, itemFontColor, maxTextWidth,
364+ maxSymbolWidth, theImage->dotsPerMeterX () * 0.0254 );
386365
387366 // create second image with the right dimensions
388367 QImage* paintImage = createImage ( maxTextWidth + maxSymbolWidth, ceil ( currentY ) );
@@ -391,7 +370,32 @@ QImage* QgsWMSServer::getLegendGraphics()
391370 QPainter p ( paintImage );
392371 p.setRenderHint ( QPainter::Antialiasing, true );
393372
394- currentY = boxSpace;
373+ drawLegendGraphics ( &p, fontOversamplingFactor, rootItem, boxSpace, layerSpace, layerTitleSpace, symbolSpace,
374+ iconLabelSpace, symbolWidth, symbolHeight, layerFont, itemFont, layerFontColor, itemFontColor, maxTextWidth,
375+ maxSymbolWidth, theImage->dotsPerMeterX () * 0.0254 );
376+
377+ QgsMapLayerRegistry::instance ()->removeAllMapLayers ();
378+ delete theImage;
379+ return paintImage;
380+ }
381+
382+ double QgsWMSServer::drawLegendGraphics ( QPainter* p, double fontOversamplingFactor, QStandardItem* rootItem, double boxSpace,
383+ double layerSpace, double layerTitleSpace, double symbolSpace, double iconLabelSpace,
384+ double symbolWidth, double symbolHeight, const QFont& layerFont, const QFont& itemFont,
385+ const QColor& layerFontColor, const QColor& itemFontColor, double & maxTextWidth, double & maxSymbolWidth, double dpi )
386+ {
387+ if ( !rootItem )
388+ {
389+ return 0 ;
390+ }
391+
392+ int numLayerItems = rootItem->rowCount ();
393+ if ( numLayerItems < 1 )
394+ {
395+ return 0 ;
396+ }
397+
398+ double currentY = boxSpace;
395399 for ( int i = 0 ; i < numLayerItems; ++i )
396400 {
397401 QgsComposerLayerItem* layerItem = dynamic_cast <QgsComposerLayerItem*>( rootItem->child ( i ) );
@@ -401,16 +405,13 @@ QImage* QgsWMSServer::getLegendGraphics()
401405 {
402406 currentY += layerSpace;
403407 }
404- drawLegendLayerItem ( layerItem, & p, maxTextWidth, maxSymbolWidth, currentY, layerFont, layerFontColor, itemFont, itemFontColor, boxSpace ,
405- layerSpace, layerTitleSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight, fontOversamplingFactor,
406- theImage-> dotsPerMeterX () * 0.0254 );
408+ drawLegendLayerItem ( layerItem, p, maxTextWidth, maxSymbolWidth, currentY, layerFont, layerFontColor, itemFont, itemFontColor,
409+ boxSpace, layerSpace, layerTitleSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight, fontOversamplingFactor,
410+ dpi );
407411 }
408- currentY += layerSpace;
409412 }
410-
411- QgsMapLayerRegistry::instance ()->removeAllMapLayers ();
412- delete theImage;
413- return paintImage;
413+ currentY += boxSpace;
414+ return currentY;
414415}
415416
416417void QgsWMSServer::legendParameters ( double mmToPixelFactor, double fontOversamplingFactor, double & boxSpace, double & layerSpace, double & layerTitleSpace,
0 commit comments