Skip to content
Permalink
Browse files

[BUGFIX][Server] In GetPrint, legend as to be fixed when it is not au…

…to update or filter by map

In release-2_14, a legend is fixed when it is not linked to a map. In
release-2_18, a legend as to be fixed when it is not auto update or filter
by map.

Actually a legend with no auto update and a layer missing in the request, the
missing layer is repalced by `(?)`

It's fixed a regression in some.

To fix this regression, layers needed in legen composer has to be loaded
before the composer items has been parsed.
  • Loading branch information
rldhont committed Jun 13, 2018
1 parent 514d036 commit e9913804745a9419e4c3528e9ff4e9668ef5c568
Showing with 27 additions and 2 deletions.
  1. +27 −2 src/server/qgswmsprojectparser.cpp
@@ -491,6 +491,30 @@ QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTem
return nullptr;
}

// load layers for legends before loaded legends
const QHash< QString, QDomElement > &projectLayerElements = mProjectParser->projectLayerElementsById();
QDomNodeList treeLayerNodeList = compositionElem.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 );
}
}

composition->addItemsFromXML( compositionElem, *( mProjectParser->xmlDocument() ) );

labelList.clear();
@@ -527,11 +551,12 @@ QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTem
if ( legend->autoUpdateModel() )
{
model->setRootGroup( projectLayerTreeGroup() );
legend->synchronizeWithModel();
}
// if the legend has no map
// we will load all layers
const QgsComposerMap* map = legend->composerMap();
if ( !map )
if ( !map || ( !legend->autoUpdateModel() && !legend->legendFilterByMapEnabled() ) )
{
QgsLayerTreeGroup* root = model->rootGroup();
QStringList layerIds = root->findLayerIds();
@@ -553,7 +578,6 @@ QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTem
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() )
{
@@ -2387,6 +2411,7 @@ QgsLayerTreeGroup* QgsWMSProjectParser::projectLayerTreeGroup() const
QgsLayerTreeUtils::readOldLegend( rootGroup, mProjectParser->legendElem() );
return rootGroup;
}

return QgsLayerTreeGroup::readXML( layerTreeElem );
}

0 comments on commit e991380

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