Skip to content
Permalink
Browse files

Remove invisible layers from legend

Do not show invisible layers in composer legend.
Useful for raster layers as QgsMapHitTest only take care of vector layers.
Related with #14194
Related with #11641
  • Loading branch information
arnaud-morvan authored and rldhont committed May 10, 2017
1 parent 514d036 commit cf3054d60d39bb259d88ad5bc011e751a78506dd
Showing with 13 additions and 10 deletions.
  1. +13 −10 src/core/layertree/qgslayertreemodel.cpp
@@ -1150,21 +1150,24 @@ QList<QgsLayerTreeModelLegendNode*> QgsLayerTreeModel::filterLegendNodes( const
}
else if ( mLegendFilterMapSettings )
{
Q_FOREACH ( QgsLayerTreeModelLegendNode* node, nodes )
if ( !nodes.isEmpty() && mLegendFilterMapSettings->layers().contains( nodes.at( 0 )->layerNode()->layerId() ) )
{
QgsSymbolV2* ruleKey = reinterpret_cast< QgsSymbolV2* >( node->data( QgsSymbolV2LegendNode::SymbolV2LegacyRuleKeyRole ).value<void*>() );
bool checked = mLegendFilterUsesExtent || node->data( Qt::CheckStateRole ).toInt() == Qt::Checked;
if ( ruleKey && checked )
Q_FOREACH ( QgsLayerTreeModelLegendNode* node, nodes )
{
QString ruleKey = node->data( QgsSymbolV2LegendNode::RuleKeyRole ).toString();
if ( QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( node->layerNode()->layer() ) )
QgsSymbolV2* ruleKey = reinterpret_cast< QgsSymbolV2* >( node->data( QgsSymbolV2LegendNode::SymbolV2LegacyRuleKeyRole ).value<void*>() );
bool checked = mLegendFilterUsesExtent || node->data( Qt::CheckStateRole ).toInt() == Qt::Checked;
if ( ruleKey && checked )
{
if ( mLegendFilterHitTest->legendKeyVisible( ruleKey, vl ) )
filtered << node;
QString ruleKey = node->data( QgsSymbolV2LegendNode::RuleKeyRole ).toString();
if ( QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( node->layerNode()->layer() ) )
{
if ( mLegendFilterHitTest->legendKeyVisible( ruleKey, vl ) )
filtered << node;
}
}
else // unknown node type or unchecked
filtered << node;
}
else // unknown node type or unchecked
filtered << node;
}
}
else

0 comments on commit cf3054d

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