Skip to content
Permalink
Browse files

Read optional legend parameters from GetLegendGraphic request (extens…

…ion to WMS)
  • Loading branch information
mhugent committed Jan 14, 2012
1 parent 5618608 commit e800caa9c8344e419205ab2e96253687c976ff75
Showing with 88 additions and 13 deletions.
  1. +84 −13 src/mapserver/qgswmsserver.cpp
  2. +4 −0 src/mapserver/qgswmsserver.h
@@ -309,23 +309,16 @@ QImage* QgsWMSServer::getLegendGraphics()
return 0;
}
double mmToPixelFactor = theImage->dotsPerMeterX() / 1000;

//get icon size, spaces between legend items and font from config parser
double boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight;
boxSpace = mConfigParser->legendBoxSpace() * mmToPixelFactor;
layerSpace = mConfigParser->legendLayerSpace() * mmToPixelFactor;
symbolSpace = mConfigParser->legendSymbolSpace() * mmToPixelFactor;
iconLabelSpace = mConfigParser->legendIconLabelSpace() * mmToPixelFactor;
symbolWidth = mConfigParser->legendSymbolWidth() * mmToPixelFactor;
symbolHeight = mConfigParser->legendSymbolHeight() * mmToPixelFactor;
double maxTextWidth = 0;
double maxSymbolWidth = 0;
double currentY = 0;
double fontOversamplingFactor = 10.0;
QFont layerFont = mConfigParser->legendLayerFont();
layerFont.setPixelSize( layerFont.pointSizeF() * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
QFont itemFont = mConfigParser->legendItemFont();
itemFont.setPixelSize( itemFont.pointSizeF() * 0.3528 * mmToPixelFactor * fontOversamplingFactor );

//get icon size, spaces between legend items and font from config parser
double boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight;
QFont layerFont, itemFont;
legendParameters( mmToPixelFactor, fontOversamplingFactor, boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight,
layerFont, itemFont );

//first find out image dimensions without painting
QStandardItem* rootItem = legendModel.invisibleRootItem();
@@ -376,6 +369,84 @@ QImage* QgsWMSServer::getLegendGraphics()
return paintImage;
}

void QgsWMSServer::legendParameters( double mmToPixelFactor, double fontOversamplingFactor, double& boxSpace, double& layerSpace, double& symbolSpace, double& iconLabelSpace, double& symbolWidth, double& symbolHeight,
QFont& layerFont, QFont& itemFont )
{
//spaces between legend elements
QMap<QString, QString>::const_iterator boxSpaceIt = mParameterMap.find( "BOXSPACE" );
boxSpace = ( boxSpaceIt == mParameterMap.constEnd() ) ? mConfigParser->legendBoxSpace() * mmToPixelFactor :
boxSpaceIt.value().toDouble() * mmToPixelFactor;
QMap<QString, QString>::const_iterator layerSpaceIt = mParameterMap.find( "LAYERSPACE" );
layerSpace = ( layerSpaceIt == mParameterMap.constEnd() ) ? mConfigParser->legendLayerSpace() * mmToPixelFactor :
layerSpaceIt.value().toDouble() * mmToPixelFactor;
QMap<QString, QString>::const_iterator symbolSpaceIt = mParameterMap.find( "SYMBOLSPACE" );
symbolSpace = ( symbolSpaceIt == mParameterMap.constEnd() ) ? mConfigParser->legendSymbolSpace() * mmToPixelFactor :
symbolSpaceIt.value().toDouble() * mmToPixelFactor;
QMap<QString, QString>::const_iterator iconLabelSpaceIt = mParameterMap.find( "ICONLABELSPACE" );
iconLabelSpace = ( iconLabelSpaceIt == mParameterMap.constEnd() ) ? mConfigParser->legendIconLabelSpace() * mmToPixelFactor :
iconLabelSpaceIt.value().toDouble() * mmToPixelFactor;
QMap<QString, QString>::const_iterator symbolWidthIt = mParameterMap.find( "SYMBOLWIDTH" );
symbolWidth = ( symbolWidthIt == mParameterMap.constEnd() ) ? mConfigParser->legendSymbolWidth() * mmToPixelFactor :
symbolWidthIt.value().toDouble() * mmToPixelFactor;
QMap<QString, QString>::const_iterator symbolHeightIt = mParameterMap.find( "SYMBOLHEIGHT" );
symbolHeight = ( symbolHeightIt == mParameterMap.constEnd() ) ? mConfigParser->legendSymbolHeight() * mmToPixelFactor :
symbolHeightIt.value().toDouble() * mmToPixelFactor;

//font properties
layerFont = mConfigParser->legendLayerFont();
QMap<QString, QString>::const_iterator layerFontFamilyIt = mParameterMap.find( "LAYERFONTFAMILY" );
if ( layerFontFamilyIt != mParameterMap.constEnd() )
{
layerFont.setFamily( layerFontFamilyIt.value() );
}
QMap<QString, QString>::const_iterator layerFontBoldIt = mParameterMap.find( "LAYERFONTBOLD" );
if ( layerFontBoldIt != mParameterMap.constEnd() )
{
layerFont.setBold( layerFontBoldIt.value().compare( "TRUE" , Qt::CaseInsensitive ) == 0 );
}
QMap<QString, QString>::const_iterator layerFontItalicIt = mParameterMap.find( "LAYERFONTITALIC" );
if ( layerFontItalicIt != mParameterMap.constEnd() )
{
layerFont.setItalic( layerFontItalicIt.value().compare( "TRUE", Qt::CaseInsensitive ) == 0 );
}
QMap<QString, QString>::const_iterator layerFontSizeIt = mParameterMap.find( "LAYERFONTSIZE" );
if ( layerFontSizeIt != mParameterMap.constEnd() )
{
layerFont.setPixelSize( layerFontSizeIt.value().toDouble() * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
}
else
{
layerFont.setPixelSize( layerFont.pointSizeF() * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
}


itemFont = mConfigParser->legendItemFont();
QMap<QString, QString>::const_iterator itemFontFamilyIt = mParameterMap.find( "ITEMFONTFAMILY" );
if ( itemFontFamilyIt != mParameterMap.constEnd() )
{
itemFont.setFamily( itemFontFamilyIt.value() );
}
QMap<QString, QString>::const_iterator itemFontBoldIt = mParameterMap.find( "ITEMFONTBOLD" );
if ( itemFontBoldIt != mParameterMap.constEnd() )
{
itemFont.setBold( itemFontBoldIt.value().compare( "TRUE" , Qt::CaseInsensitive ) == 0 );
}
QMap<QString, QString>::const_iterator itemFontItalicIt = mParameterMap.find( "ITEMFONTITALIC" );
if ( itemFontItalicIt != mParameterMap.constEnd() )
{
itemFont.setItalic( itemFontItalicIt.value().compare( "TRUE", Qt::CaseInsensitive ) == 0 );
}
QMap<QString, QString>::const_iterator itemFontSizeIt = mParameterMap.find( "ITEMFONTSIZE" );
if ( itemFontSizeIt != mParameterMap.constEnd() )
{
itemFont.setPixelSize( itemFontSizeIt.value().toDouble() * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
}
else
{
itemFont.setPixelSize( itemFont.pointSizeF() * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
}
}

QDomDocument QgsWMSServer::getStyle()
{
QDomDocument doc;
@@ -138,6 +138,10 @@ class QgsWMSServer
void drawLegendSymbolV2( QgsComposerLegendItem* item, QPainter* p, double boxSpace, double currentY, double& symbolWidth, double& symbolHeight, double dpi, double yDownShift ) const;
void drawRasterSymbol( QgsComposerLegendItem* item, QPainter* p, double boxSpace, double currentY, double symbolWidth, double symbolHeight, double yDownShift ) const;

/**Read legend parameter from the request or from the first print composer in the project*/
void legendParameters( double mmToPixelFactor, double fontOversamplingFactor, double& boxSpace, double& layerSpace, double& symbolSpace, double& iconLabelSpace, double& symbolWidth, double& symbolHeight,
QFont& layerFont, QFont& itemFont );

QImage* printCompositionToImage( QgsComposition* c ) const;

/**Apply filter (subset) strings from the request to the layers. Example: '&FILTER=<layer1>:"AND property > 100",<layer2>:"AND bla = 'hallo!'" '

0 comments on commit e800caa

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