@@ -309,23 +309,16 @@ QImage* QgsWMSServer::getLegendGraphics()
309309 return 0 ;
310310 }
311311 double mmToPixelFactor = theImage->dotsPerMeterX () / 1000 ;
312-
313- // get icon size, spaces between legend items and font from config parser
314- double boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight;
315- boxSpace = mConfigParser ->legendBoxSpace () * mmToPixelFactor;
316- layerSpace = mConfigParser ->legendLayerSpace () * mmToPixelFactor;
317- symbolSpace = mConfigParser ->legendSymbolSpace () * mmToPixelFactor;
318- iconLabelSpace = mConfigParser ->legendIconLabelSpace () * mmToPixelFactor;
319- symbolWidth = mConfigParser ->legendSymbolWidth () * mmToPixelFactor;
320- symbolHeight = mConfigParser ->legendSymbolHeight () * mmToPixelFactor;
321312 double maxTextWidth = 0 ;
322313 double maxSymbolWidth = 0 ;
323314 double currentY = 0 ;
324315 double fontOversamplingFactor = 10.0 ;
325- QFont layerFont = mConfigParser ->legendLayerFont ();
326- layerFont.setPixelSize ( layerFont.pointSizeF () * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
327- QFont itemFont = mConfigParser ->legendItemFont ();
328- itemFont.setPixelSize ( itemFont.pointSizeF () * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
316+
317+ // get icon size, spaces between legend items and font from config parser
318+ double boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight;
319+ QFont layerFont, itemFont;
320+ legendParameters ( mmToPixelFactor, fontOversamplingFactor, boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight,
321+ layerFont, itemFont );
329322
330323 // first find out image dimensions without painting
331324 QStandardItem* rootItem = legendModel.invisibleRootItem ();
@@ -376,6 +369,84 @@ QImage* QgsWMSServer::getLegendGraphics()
376369 return paintImage;
377370}
378371
372+ void QgsWMSServer::legendParameters ( double mmToPixelFactor, double fontOversamplingFactor, double & boxSpace, double & layerSpace, double & symbolSpace, double & iconLabelSpace, double & symbolWidth, double & symbolHeight,
373+ QFont& layerFont, QFont& itemFont )
374+ {
375+ // spaces between legend elements
376+ QMap<QString, QString>::const_iterator boxSpaceIt = mParameterMap .find ( " BOXSPACE" );
377+ boxSpace = ( boxSpaceIt == mParameterMap .constEnd () ) ? mConfigParser ->legendBoxSpace () * mmToPixelFactor :
378+ boxSpaceIt.value ().toDouble () * mmToPixelFactor;
379+ QMap<QString, QString>::const_iterator layerSpaceIt = mParameterMap .find ( " LAYERSPACE" );
380+ layerSpace = ( layerSpaceIt == mParameterMap .constEnd () ) ? mConfigParser ->legendLayerSpace () * mmToPixelFactor :
381+ layerSpaceIt.value ().toDouble () * mmToPixelFactor;
382+ QMap<QString, QString>::const_iterator symbolSpaceIt = mParameterMap .find ( " SYMBOLSPACE" );
383+ symbolSpace = ( symbolSpaceIt == mParameterMap .constEnd () ) ? mConfigParser ->legendSymbolSpace () * mmToPixelFactor :
384+ symbolSpaceIt.value ().toDouble () * mmToPixelFactor;
385+ QMap<QString, QString>::const_iterator iconLabelSpaceIt = mParameterMap .find ( " ICONLABELSPACE" );
386+ iconLabelSpace = ( iconLabelSpaceIt == mParameterMap .constEnd () ) ? mConfigParser ->legendIconLabelSpace () * mmToPixelFactor :
387+ iconLabelSpaceIt.value ().toDouble () * mmToPixelFactor;
388+ QMap<QString, QString>::const_iterator symbolWidthIt = mParameterMap .find ( " SYMBOLWIDTH" );
389+ symbolWidth = ( symbolWidthIt == mParameterMap .constEnd () ) ? mConfigParser ->legendSymbolWidth () * mmToPixelFactor :
390+ symbolWidthIt.value ().toDouble () * mmToPixelFactor;
391+ QMap<QString, QString>::const_iterator symbolHeightIt = mParameterMap .find ( " SYMBOLHEIGHT" );
392+ symbolHeight = ( symbolHeightIt == mParameterMap .constEnd () ) ? mConfigParser ->legendSymbolHeight () * mmToPixelFactor :
393+ symbolHeightIt.value ().toDouble () * mmToPixelFactor;
394+
395+ // font properties
396+ layerFont = mConfigParser ->legendLayerFont ();
397+ QMap<QString, QString>::const_iterator layerFontFamilyIt = mParameterMap .find ( " LAYERFONTFAMILY" );
398+ if ( layerFontFamilyIt != mParameterMap .constEnd () )
399+ {
400+ layerFont.setFamily ( layerFontFamilyIt.value () );
401+ }
402+ QMap<QString, QString>::const_iterator layerFontBoldIt = mParameterMap .find ( " LAYERFONTBOLD" );
403+ if ( layerFontBoldIt != mParameterMap .constEnd () )
404+ {
405+ layerFont.setBold ( layerFontBoldIt.value ().compare ( " TRUE" , Qt::CaseInsensitive ) == 0 );
406+ }
407+ QMap<QString, QString>::const_iterator layerFontItalicIt = mParameterMap .find ( " LAYERFONTITALIC" );
408+ if ( layerFontItalicIt != mParameterMap .constEnd () )
409+ {
410+ layerFont.setItalic ( layerFontItalicIt.value ().compare ( " TRUE" , Qt::CaseInsensitive ) == 0 );
411+ }
412+ QMap<QString, QString>::const_iterator layerFontSizeIt = mParameterMap .find ( " LAYERFONTSIZE" );
413+ if ( layerFontSizeIt != mParameterMap .constEnd () )
414+ {
415+ layerFont.setPixelSize ( layerFontSizeIt.value ().toDouble () * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
416+ }
417+ else
418+ {
419+ layerFont.setPixelSize ( layerFont.pointSizeF () * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
420+ }
421+
422+
423+ itemFont = mConfigParser ->legendItemFont ();
424+ QMap<QString, QString>::const_iterator itemFontFamilyIt = mParameterMap .find ( " ITEMFONTFAMILY" );
425+ if ( itemFontFamilyIt != mParameterMap .constEnd () )
426+ {
427+ itemFont.setFamily ( itemFontFamilyIt.value () );
428+ }
429+ QMap<QString, QString>::const_iterator itemFontBoldIt = mParameterMap .find ( " ITEMFONTBOLD" );
430+ if ( itemFontBoldIt != mParameterMap .constEnd () )
431+ {
432+ itemFont.setBold ( itemFontBoldIt.value ().compare ( " TRUE" , Qt::CaseInsensitive ) == 0 );
433+ }
434+ QMap<QString, QString>::const_iterator itemFontItalicIt = mParameterMap .find ( " ITEMFONTITALIC" );
435+ if ( itemFontItalicIt != mParameterMap .constEnd () )
436+ {
437+ itemFont.setItalic ( itemFontItalicIt.value ().compare ( " TRUE" , Qt::CaseInsensitive ) == 0 );
438+ }
439+ QMap<QString, QString>::const_iterator itemFontSizeIt = mParameterMap .find ( " ITEMFONTSIZE" );
440+ if ( itemFontSizeIt != mParameterMap .constEnd () )
441+ {
442+ itemFont.setPixelSize ( itemFontSizeIt.value ().toDouble () * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
443+ }
444+ else
445+ {
446+ itemFont.setPixelSize ( itemFont.pointSizeF () * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
447+ }
448+ }
449+
379450QDomDocument QgsWMSServer::getStyle ()
380451{
381452 QDomDocument doc;
0 commit comments