Skip to content
Permalink
Browse files

Add suport whe legend is not based on rule

  • Loading branch information
pblottiere committed Apr 9, 2019
1 parent ba14e14 commit 392524646a36edb157449f43b4686e0b3cbbd0c1
Showing with 35 additions and 0 deletions.
  1. +35 −0 src/server/services/wms/qgswmsgetlegendgraphics.cpp
@@ -19,6 +19,7 @@
* *
***************************************************************************/
#include "qgslayertree.h"
#include "qgslegendrenderer.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerfeaturecounter.h"

@@ -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();
}

0 comments on commit 3925246

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