Skip to content
Permalink
Browse files

[Bugfix][Server] Display composer legend with auto update like the De…

…sktop

QGIS Server was not able to display auto update legend in composer since
2.18.x. To fix it we need to deactivate *auto update* and to provide the
the project layer tree.
  • Loading branch information
rldhont committed Jun 22, 2018
1 parent 9f01039 commit 259290ab327abf5c57056ceda5db89c0e1a65c52
Showing with 37 additions and 1 deletion.
  1. +37 −1 src/server/qgswmsprojectparser.cpp
@@ -599,8 +599,9 @@ QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTem
#endif
if ( legend->autoUpdateModel() )
{
legend->setAutoUpdateModel( false );
model->setRootGroup( projectLayerTreeGroup() );
legend->synchronizeWithModel();
legend->updateLegend();
}
// if the legend has no map
// we will load all layers
@@ -2461,6 +2462,41 @@ QgsLayerTreeGroup* QgsWMSProjectParser::projectLayerTreeGroup() const
return rootGroup;
}

/*const QDomDocument* projectDoc = mProjectParser->xmlDocument();
if ( projectDoc )
{
QDomElement qgisElem = projectDoc->documentElement();
if ( qgisElem.isNull() )
{
QDomElement layerTreeElem = qgisElem.firstChildElement( "layer-tree-group" );*/
if ( layerTreeElem.isNull() )
{
const QHash< QString, QDomElement > &projectLayerElements = mProjectParser->projectLayerElementsById();
QDomNodeList treeLayerNodeList = layerTreeElem.elementsByTagName( "layer-tree-layer" );
for ( int i = 0; i < treeLayerNodeList.size(); ++i )
{
QDomElement treeLayerElem = treeLayerNodeList.at( i ).toElement();
QString layerId = treeLayerElem.attribute( "id" );
QgsMapLayer * layer = QgsMapLayerRegistry::instance()->mapLayer( layerId );
if ( layer )
{
continue;
}

QHash< QString, QDomElement >::const_iterator layerElemIt = projectLayerElements.find( layerId );
if ( layerElemIt != projectLayerElements.constEnd() )
{
layer = mProjectParser->createLayerFromElement( layerElemIt.value(), true );
}
if ( layer )
{
QgsMapLayerRegistry::instance()->addMapLayer( layer );
}
}
}
/*}
}*/

return QgsLayerTreeGroup::readXML( layerTreeElem );
}

0 comments on commit 259290a

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