Skip to content

Commit

Permalink
WMS server GetLegendGraphics: differentiate between layer space and l…
Browse files Browse the repository at this point in the history
…ayer title space
  • Loading branch information
mhugent committed Nov 2, 2012
1 parent c11df1a commit 70fc8ca
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/mapserver/qgsconfigparser.cpp
Expand Up @@ -69,6 +69,7 @@ void QgsConfigParser::setDefaultLegendSettings()
{
mLegendBoxSpace = 2;
mLegendLayerSpace = 3;
mLegendLayerTitleSpace = 3;
mLegendSymbolSpace = 2;
mLegendIconLabelSpace = 2;
mLegendSymbolWidth = 7;
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgsconfigparser.h
Expand Up @@ -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; }
Expand Down Expand Up @@ -174,6 +175,7 @@ class QgsConfigParser
//various parameters used for GetLegendGraphics
double mLegendBoxSpace;
double mLegendLayerSpace;
double mLegendLayerTitleSpace;
double mLegendSymbolSpace;
double mLegendIconLabelSpace;
double mLegendSymbolWidth;
Expand Down
35 changes: 25 additions & 10 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -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();
Expand All @@ -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 );
}
}
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -1542,7 +1554,10 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p,
}

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

Expand Down
6 changes: 3 additions & 3 deletions src/mapserver/qgswmsserver.h
Expand Up @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit 70fc8ca

Please sign in to comment.