Skip to content
Permalink
Browse files

Parameter for font color in GetLegendGraphic

  • Loading branch information
mhugent committed Jan 16, 2012
1 parent d8bdcb2 commit 0b951c659dc97833a3d3c3ec1487bd9b85e66799
Showing with 36 additions and 15 deletions.
  1. +32 −12 src/mapserver/qgswmsserver.cpp
  2. +4 −3 src/mapserver/qgswmsserver.h
@@ -317,8 +317,9 @@ QImage* QgsWMSServer::getLegendGraphics()
//get icon size, spaces between legend items and font from config parser
double boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight;
QFont layerFont, itemFont;
QColor layerFontColor, itemFontColor;
legendParameters( mmToPixelFactor, fontOversamplingFactor, boxSpace, layerSpace, symbolSpace, iconLabelSpace, symbolWidth, symbolHeight,
layerFont, itemFont );
layerFont, itemFont, layerFontColor, itemFontColor );

//first find out image dimensions without painting
QStandardItem* rootItem = legendModel.invisibleRootItem();
@@ -340,8 +341,9 @@ QImage* QgsWMSServer::getLegendGraphics()
if ( layerItem )
{

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

@@ -370,7 +373,7 @@ QImage* QgsWMSServer::getLegendGraphics()
}

void QgsWMSServer::legendParameters( double mmToPixelFactor, double fontOversamplingFactor, double& boxSpace, double& layerSpace, double& symbolSpace, double& iconLabelSpace, double& symbolWidth, double& symbolHeight,
QFont& layerFont, QFont& itemFont )
QFont& layerFont, QFont& itemFont, QColor& layerFontColor, QColor& itemFontColor )
{
//spaces between legend elements
QMap<QString, QString>::const_iterator boxSpaceIt = mParameterMap.find( "BOXSPACE" );
@@ -418,6 +421,15 @@ void QgsWMSServer::legendParameters( double mmToPixelFactor, double fontOversamp
{
layerFont.setPixelSize( layerFont.pointSizeF() * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
}
QMap<QString, QString>::const_iterator layerFontColorIt = mParameterMap.find( "LAYERFONTCOLOR" );
if ( layerFontColorIt != mParameterMap.constEnd() )
{
layerFontColor.setNamedColor( layerFontColorIt.value() );
}
else
{
layerFontColor = QColor( 0, 0, 0 );
}


itemFont = mConfigParser->legendItemFont();
@@ -445,6 +457,15 @@ void QgsWMSServer::legendParameters( double mmToPixelFactor, double fontOversamp
{
itemFont.setPixelSize( itemFont.pointSizeF() * 0.3528 * mmToPixelFactor * fontOversamplingFactor );
}
QMap<QString, QString>::const_iterator itemFontColorIt = mParameterMap.find( "ITEMFONTCOLOR" );
if ( itemFontColorIt != mParameterMap.constEnd() )
{
itemFontColor.setNamedColor( itemFontColorIt.value() );
}
else
{
itemFontColor = QColor( 0, 0, 0 );
}
}

QDomDocument QgsWMSServer::getStyle()
@@ -1395,8 +1416,8 @@ QStringList QgsWMSServer::layerSet( const QStringList &layersList,
}

void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p, double& maxTextWidth, double& maxSymbolWidth, double& currentY, const QFont& layerFont,
const QFont& itemFont, double boxSpace, double layerSpace, double symbolSpace,
double iconLabelSpace, double symbolWidth, double symbolHeight, double fontOversamplingFactor,
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
{
if ( !item )
@@ -1412,6 +1433,7 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* 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();
@@ -1435,10 +1457,6 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p,
}

//then draw all the children
if ( p )
{
p->setFont( itemFont );
}
QFontMetricsF itemFontMetrics( itemFont );

int nChildItems = item->rowCount();
@@ -1491,6 +1509,8 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* 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();
@@ -35,6 +35,7 @@ class QgsRasterLayer;
class QgsRectangle;
class QgsVectorLayer;
class QgsSymbol;
class QColor;
class QFile;
class QFont;
class QImage;
@@ -127,8 +128,8 @@ class QgsWMSServer
@param maxSymbolWidth Includes boxSpace and iconLabelSpace. If p==0: maximum Symbol width is calculated, if p: maxSymbolWidth is input parameter
*/
void drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p, double& maxTextWidth, double& maxSymbolWidth, double& currentY, const QFont& layerFont,
const QFont& itemFont, double boxSpace, double layerSpace, double symbolSpace, double iconLabelSpace,
double symbolWidth, double symbolHeight, double fontOversamplingFactor, double dpi ) const;
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;
/**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;
@@ -140,7 +141,7 @@ class QgsWMSServer

/**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 );
QFont& layerFont, QFont& itemFont, QColor& layerFontColor, QColor& itemFontColor );

QImage* printCompositionToImage( QgsComposition* c ) const;

0 comments on commit 0b951c6

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