Skip to content
Permalink
Browse files
Merge pull request #1377 from luca76/master
WMS GetLegendGrapics: obtain legend graphics with no labels
  • Loading branch information
mhugent committed May 21, 2014
2 parents af7af6c + b87049e commit 541763928572f9a7a4eb465ced88ba6388c272b4
Showing with 57 additions and 19 deletions.
  1. +53 −19 src/mapserver/qgswmsserver.cpp
  2. +4 −0 src/mapserver/qgswmsserver.h
@@ -758,6 +758,15 @@ void QgsWMSServer::legendParameters( double mmToPixelFactor, double fontOversamp
{
layerFontColor = QColor( 0, 0, 0 );
}
QMap<QString, QString>::const_iterator layerTitleIt = mParameters.find( "LAYERTITLE" );
if ( layerTitleIt != mParameters.constEnd() )
{
mDrawLegendLayerLabel = layerTitleIt.value().compare( "TRUE", Qt::CaseInsensitive );
}
else
{
mDrawLegendLayerLabel = true;
}


itemFont = mConfigParser->legendItemFont();
@@ -794,6 +803,15 @@ void QgsWMSServer::legendParameters( double mmToPixelFactor, double fontOversamp
{
itemFontColor = QColor( 0, 0, 0 );
}
QMap<QString, QString>::const_iterator itemLabelIt = mParameters.find( "RULELABEL" );
if ( itemLabelIt != mParameters.constEnd() )
{
mDrawLegendItemLabel = itemLabelIt.value().compare( "TRUE", Qt::CaseInsensitive );
}
else
{
mDrawLegendItemLabel = true;
}
}

QDomDocument QgsWMSServer::getStyle()
@@ -1955,28 +1973,36 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p,
}

QFontMetricsF layerFontMetrics( layerFont );
currentY += layerFontMetrics.ascent() / fontOversamplingFactor;
if (mDrawLegendLayerLabel == true) {
currentY += layerFontMetrics.ascent() / fontOversamplingFactor;
}

//draw layer title first
if ( p )
{
p->save();
p->scale( 1.0 / fontOversamplingFactor, 1.0 / fontOversamplingFactor );
p->setPen( layerFontColor );
p->setFont( layerFont );
p->drawText( boxSpace * fontOversamplingFactor, currentY * fontOversamplingFactor, item->text() );
p->restore();
if (mDrawLegendLayerLabel == true) {
p->save();
p->scale( 1.0 / fontOversamplingFactor, 1.0 / fontOversamplingFactor );
p->setPen( layerFontColor );
p->setFont( layerFont );
p->drawText( boxSpace * fontOversamplingFactor, currentY * fontOversamplingFactor, item->text() );
p->restore();
}
}
else
{
double layerItemWidth = layerFontMetrics.width( item->text() ) / fontOversamplingFactor + boxSpace;
if ( layerItemWidth > maxTextWidth )
{
maxTextWidth = layerItemWidth;
if ( mDrawLegendLayerLabel == true) {
maxTextWidth = layerItemWidth;
}
}
}

currentY += layerTitleSpace;
if (mDrawLegendLayerLabel == true) {
currentY += layerTitleSpace;
}

//then draw all the children
QFontMetricsF itemFontMetrics( itemFont );
@@ -2023,25 +2049,33 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p,
break;
}

//finally draw text
currentTextWidth = itemFontMetrics.width( currentComposerItem->text() ) / fontOversamplingFactor;
if ( mDrawLegendItemLabel == true ) {
//finally draw text
currentTextWidth = itemFontMetrics.width( currentComposerItem->text() ) / fontOversamplingFactor;
} else {
currentTextWidth = 0;
}
double symbolItemHeight = qMax( itemFontMetrics.ascent() / fontOversamplingFactor, currentSymbolHeight );

if ( p )
{
p->save();
p->scale( 1.0 / fontOversamplingFactor, 1.0 / fontOversamplingFactor );
p->setPen( itemFontColor );
p->setFont( itemFont );
p->drawText( maxSymbolWidth * fontOversamplingFactor,
( currentY + symbolItemHeight / 2.0 ) * fontOversamplingFactor + itemFontMetrics.ascent() / 2.0, currentComposerItem->text() );
p->restore();
if ( mDrawLegendItemLabel == true ) {
p->save();
p->scale( 1.0 / fontOversamplingFactor, 1.0 / fontOversamplingFactor );
p->setPen( itemFontColor );
p->setFont( itemFont );
p->drawText( maxSymbolWidth * fontOversamplingFactor,
( currentY + symbolItemHeight / 2.0 ) * fontOversamplingFactor + itemFontMetrics.ascent() / 2.0, currentComposerItem->text() );
p->restore();
}
}
else
{
if ( currentTextWidth > maxTextWidth )
{
maxTextWidth = currentTextWidth;
if ( mDrawLegendItemLabel == true ) {
maxTextWidth = currentTextWidth;
}
}
double symbolWidth = boxSpace + currentSymbolWidth + iconLabelSpace;
if ( symbolWidth > maxSymbolWidth )
@@ -239,6 +239,10 @@ class QgsWMSServer: public QgsOWSServer

bool mOwnsConfigParser; //delete config parser after request (e.g. sent SLD)

// speficy if layer or rule item labels should be drawn in the legend graphic with GetLegendGraphics
bool mDrawLegendLayerLabel;
bool mDrawLegendItemLabel;

QDomElement createFeatureGML(
QgsFeature* feat,
QgsVectorLayer* layer,

0 comments on commit 5417639

Please sign in to comment.