Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 86d447b
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/server/qgswmsprojectparser.cpp
Expand Up @@ -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"
Expand All @@ -38,6 +39,7 @@
#include "qgscomposerscalebar.h"
#include "qgscomposershape.h"
#include "qgslayertreegroup.h"
#include "qgslayertreelayer.h"

#include <QFileInfo>
#include <QTextDocument>
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 86d447b

Please sign in to comment.