Skip to content
Permalink
Browse files

[BUGFIX][QGIS-Server] Add all layers for fixed legend in GetPrint

If a legend is not linked to a map, it's a fixed legend and does not depend on
 layers parameter. This bugfix loads all layers needed by legend and update it.
  • Loading branch information
rldhont committed Jun 19, 2015
1 parent 2372351 commit 86d447b9740a4ffda591fb323d5300d2cc5ccf52
Showing with 39 additions and 2 deletions.
  1. +39 −2 src/server/qgswmsprojectparser.cpp
@@ -20,6 +20,7 @@
#include "qgsconfigparserutils.h"
#include "qgslogger.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerstylemanager.h"
#include "qgsmapserviceexception.h"
#include "qgspallabeling.h"
@@ -38,6 +39,7 @@
#include "qgscomposerscalebar.h"
#include "qgscomposershape.h"
#include "qgslayertreegroup.h"
#include "qgslayertreelayer.h"

#include <QFileInfo>
#include <QTextDocument>
@@ -442,17 +444,52 @@ QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTem
QgsComposerLegend* legend = dynamic_cast< QgsComposerLegend *>( *itemIt );
if ( legend )
{
#if 0
QgsLegendModelV2* model = legend->modelV2();
#if 0
QgsLayerTreeGroup* root = model->rootGroup();
QStringList layerIds = root->findLayerIds();
throw QgsMapServiceException( "Error", "Composer legend layerIds " + layerIds.join( " ," ) );
#endif
if ( legend->autoUpdateModel() )
{
QgsLegendModelV2* model = legend->modelV2();
model->setRootGroup( projectLayerTreeGroup() );
}
// if the legend has no map
// we will load all layers
const QgsComposerMap* map = legend->composerMap();
if ( !map )
{
QgsLayerTreeGroup* root = model->rootGroup();
QStringList layerIds = root->findLayerIds();
// foreach layer find in the layer tree
// load it if the layer id is not QgsMapLayerRegistry
foreach ( QString layerId, layerIds )
{
QgsMapLayer * layer = QgsMapLayerRegistry::instance()->mapLayer( layerId );
if ( layer )
{
continue;
}

QgsLayerTreeLayer* nodeLayer = root->findLayer( layerId );
if ( !nodeLayer )
{
continue;
}
layer = nodeLayer->layer();
if ( !layer )
{
const QHash< QString, QDomElement > &projectLayerElements = mProjectParser->projectLayerElementsById();
QHash< QString, QDomElement >::const_iterator layerElemIt = projectLayerElements.find( layerId );
if ( layerElemIt != projectLayerElements.constEnd() )
{
layer = mProjectParser->createLayerFromElement( layerElemIt.value(), true );
}
}
QgsMapLayerRegistry::instance()->addMapLayer( layer );
}
legend->updateLegend();
}
legendList.push_back( legend );
continue;
}

0 comments on commit 86d447b

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