[QGIS-Server][BUGFIX] GetLegendGraphics set layername

To have title instead of name in server getlegendgraphic response, the commit
 bb95a0f43a53602bd7ad1ea6783d251755c66019 update getlegendgraphic to set the
 tree layer name. This update set the layer name with layer title.

To fix it, I just store the layers name and reset them at the end of
 GetLegendGraphic request.
This commit is contained in:
rldhont 2015-01-02 14:49:35 +01:00
parent 49d864f4fc
commit 2f75c3c884

View File

@ -672,11 +672,20 @@ QImage* QgsWMSServer::getLegendGraphics()
}
}
// Create the layer tree root
QgsLayerTreeGroup rootGroup;
// Store layers' name to reset them
QMap<QString, QString> layerNameMap;
// Create tree layer node for each layer
foreach ( QString layerId, layerIds )
{
// get layer
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
// create tree layer node
QgsLayerTreeLayer *layer = rootGroup.addLayer( ml );
// store the layer's name
layerNameMap.insert( layerId, ml->name() );
// set layer name with layer's title to have it in legend
if ( !ml->title().isEmpty() )
layer->setLayerName( ml->title() );
}
@ -808,6 +817,13 @@ QImage* QgsWMSServer::getLegendGraphics()
p.end();
// reset layers' name
foreach ( QString layerId, layerIds )
{
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
ml->setLayerName( layerNameMap[ layerId ] );
}
// clear map layer registry
QgsMapLayerRegistry::instance()->removeAllMapLayers();
return paintImage;
}