Skip to content
Permalink
Browse files

WMS server GetLegendGraphics: differentiate between layer space and l…

…ayer title space
  • Loading branch information
mhugent committed Nov 2, 2012
1 parent c11df1a commit 70fc8ca9b251cfea4f8918b419f24dbe3b2b1120
@@ -69,6 +69,7 @@ void QgsConfigParser::setDefaultLegendSettings()
{
mLegendBoxSpace = 2;
mLegendLayerSpace = 3;
mLegendLayerTitleSpace = 3;
mLegendSymbolSpace = 2;
mLegendIconLabelSpace = 2;
mLegendSymbolWidth = 7;
@@ -88,6 +88,7 @@ class QgsConfigParser

double legendBoxSpace() const { return mLegendBoxSpace; }
double legendLayerSpace() const { return mLegendLayerSpace; }
double legendLayerTitleSpace() const { return mLegendLayerTitleSpace; }
double legendSymbolSpace() const { return mLegendSymbolSpace; }
double legendIconLabelSpace() const { return mLegendIconLabelSpace; }
double legendSymbolWidth() const { return mLegendSymbolWidth; }
@@ -174,6 +175,7 @@ class QgsConfigParser
//various parameters used for GetLegendGraphics
double mLegendBoxSpace;
double mLegendLayerSpace;
double mLegendLayerTitleSpace;
double mLegendSymbolSpace;
double mLegendIconLabelSpace;
double mLegendSymbolWidth;
@@ -306,11 +306,11 @@ QImage* QgsWMSServer::getLegendGraphics()
double fontOversamplingFactor = 10.0;

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

//first find out image dimensions without painting
QStandardItem* rootItem = legendModel.invisibleRootItem();
@@ -331,9 +331,12 @@ QImage* QgsWMSServer::getLegendGraphics()
QgsComposerLayerItem* layerItem = dynamic_cast<QgsComposerLayerItem*>( rootItem->child( i ) );
if ( layerItem )
{

if ( i > 0 )
{
currentY += layerSpace;
}
drawLegendLayerItem( layerItem, 0, maxTextWidth, maxSymbolWidth, currentY, layerFont, layerFontColor, itemFont, itemFontColor,
boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight, fontOversamplingFactor,
boxSpace, layerSpace, layerTitleSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight, fontOversamplingFactor,
theImage->dotsPerMeterX() * 0.0254 );
}
}
@@ -352,18 +355,24 @@ QImage* QgsWMSServer::getLegendGraphics()
QgsComposerLayerItem* layerItem = dynamic_cast<QgsComposerLayerItem*>( rootItem->child( i ) );
if ( layerItem )
{
if ( i > 0 )
{
currentY += layerSpace;
}
drawLegendLayerItem( layerItem, &p, maxTextWidth, maxSymbolWidth, currentY, layerFont, layerFontColor, itemFont, itemFontColor, boxSpace,
layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight, fontOversamplingFactor,
layerSpace, layerTitleSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight, fontOversamplingFactor,
theImage->dotsPerMeterX() * 0.0254 );
}
currentY += layerSpace;
}

QgsMapLayerRegistry::instance()->mapLayers().clear();
delete theImage;
return paintImage;
}

void QgsWMSServer::legendParameters( double mmToPixelFactor, double fontOversamplingFactor, double& boxSpace, double& layerSpace, double& symbolSpace, double& iconLabelSpace, double& symbolWidth, double& symbolHeight,
void QgsWMSServer::legendParameters( double mmToPixelFactor, double fontOversamplingFactor, double& boxSpace, double& layerSpace, double& layerTitleSpace,
double& symbolSpace, double& iconLabelSpace, double& symbolWidth, double& symbolHeight,
QFont& layerFont, QFont& itemFont, QColor& layerFontColor, QColor& itemFontColor )
{
//spaces between legend elements
@@ -373,6 +382,9 @@ void QgsWMSServer::legendParameters( double mmToPixelFactor, double fontOversamp
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 layerTitleSpaceIt = mParameterMap.find( "LAYERTITLESPACE" );
layerTitleSpace = ( layerTitleSpaceIt == mParameterMap.constEnd() ) ? mConfigParser->legendLayerTitleSpace() * mmToPixelFactor :
layerTitleSpaceIt.value().toDouble() * mmToPixelFactor;
QMap<QString, QString>::const_iterator symbolSpaceIt = mParameterMap.find( "SYMBOLSPACE" );
symbolSpace = ( symbolSpaceIt == mParameterMap.constEnd() ) ? mConfigParser->legendSymbolSpace() * mmToPixelFactor :
symbolSpaceIt.value().toDouble() * mmToPixelFactor;
@@ -1430,7 +1442,7 @@ QStringList QgsWMSServer::layerSet( const QStringList &layersList,

void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p, double& maxTextWidth, double& maxSymbolWidth, double& currentY, const QFont& layerFont,
const QColor& layerFontColor, const QFont& itemFont, const QColor& itemFontColor, double boxSpace, double layerSpace,
double symbolSpace, double iconLabelSpace, double symbolWidth, double symbolHeight, double fontOversamplingFactor,
double layerTitleSpace, double symbolSpace, double iconLabelSpace, double symbolWidth, double symbolHeight, double fontOversamplingFactor,
double dpi ) const
{
if ( !item )
@@ -1460,7 +1472,7 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p,
}
}

currentY += layerSpace;
currentY += layerTitleSpace;

int opacity = 0;
QgsMapLayer* layerInstance = QgsMapLayerRegistry::instance()->mapLayer( item->layerID() );
@@ -1542,7 +1554,10 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p,
}

currentY += symbolItemHeight;
currentY += symbolSpace;
if ( i < ( nChildItems - 1 ) )
{
currentY += symbolSpace;
}
}
}

@@ -133,7 +133,7 @@ class QgsWMSServer
*/
void drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p, double& maxTextWidth, double& maxSymbolWidth, double& currentY, const QFont& layerFont,
const QColor& layerFontColor, const QFont& itemFont, const QColor& itemFontColor, double boxSpace, double layerSpace,
double symbolSpace, double iconLabelSpace, double symbolWidth, double symbolHeight, double fontOversamplingFactor, double dpi ) const;
double layerTitleSpace, double symbolSpace, double iconLabelSpace, double symbolWidth, double symbolHeight, double fontOversamplingFactor, double dpi ) const;
/**Draws a (old generation) symbol. Optionally, maxHeight is adapted (e.g. for large point markers) */
void drawLegendSymbol( QgsComposerLegendItem* item, QPainter* p, double boxSpace, double currentY, double& symbolWidth, double& symbolHeight,
double layerOpacity, double dpi, double yDownShift ) const;
@@ -144,8 +144,8 @@ class QgsWMSServer
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, QColor& layerFontColor, QColor& itemFontColor );
void legendParameters( double mmToPixelFactor, double fontOversamplingFactor, double& boxSpace, double& layerSpace, double& layerTitleSpace,
double& symbolSpace, double& iconLabelSpace, double& symbolWidth, double& symbolHeight, QFont& layerFont, QFont& itemFont, QColor& layerFontColor, QColor& itemFontColor );

QImage* printCompositionToImage( QgsComposition* c ) const;

0 comments on commit 70fc8ca

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