Skip to content

Commit

Permalink
Add suport whe legend is not based on rule
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Apr 9, 2019
1 parent ba14e14 commit 3925246
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/server/services/wms/qgswmsgetlegendgraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* *
***************************************************************************/
#include "qgslayertree.h"
#include "qgslegendrenderer.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerfeaturecounter.h"

Expand Down Expand Up @@ -154,6 +155,40 @@ namespace QgsWms
// TODO
}

// if legend is not based on rendering rules
if ( parameters.rule().isEmpty() )
{
QList<QgsLayerTreeNode *> children = tree.children();
for ( QgsLayerTreeNode *node : children )
{
if ( ! QgsLayerTree::isLayer( node ) )
continue;

QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );

// layer titles - hidden or not
QgsLegendRenderer::setNodeLegendStyle( nodeLayer, parameters.layerTitleAsBool() ? QgsLegendStyle::Subgroup : QgsLegendStyle::Hidden );

// rule item titles
if ( !parameters.ruleLabelAsBool() )
{
for ( QgsLayerTreeModelLegendNode *legendNode : model->layerLegendNodes( nodeLayer ) )
{
// empty string = no override, so let's use one space
legendNode->setUserLabel( QStringLiteral( " " ) );
}
}
else if ( !parameters.layerTitleAsBool() )
{
for ( QgsLayerTreeModelLegendNode *legendNode : model->layerLegendNodes( nodeLayer ) )
{
if ( legendNode->isEmbeddedInParent() )
legendNode->setEmbeddedInParent( false );
}
}
}
}

return model.release();
}

Expand Down

0 comments on commit 3925246

Please sign in to comment.