Skip to content

Commit

Permalink
[Bugfix][Server] Display composer legend with auto update like the De…
Browse files Browse the repository at this point in the history
…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 259290a
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/server/qgswmsprojectparser.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
}

Expand Down

0 comments on commit 259290a

Please sign in to comment.