Skip to content
Permalink
Browse files

fixups (to be rebased)

- removed the setParent since the parent is already set here
- moved the legendNode->invalidateMapBasedData() after size setting
  (removed dupplicate call)
- moved max icon size computation in the loop over layers
  • Loading branch information
vmora committed Aug 13, 2015
1 parent 8776449 commit 0a93f94bbea5cbf5b104ef54aa67d7fa8ebcf174
Showing with 11 additions and 12 deletions.
  1. +11 −12 src/core/layertree/qgslayertreemodel.cpp
@@ -1311,34 +1311,33 @@ void QgsLayerTreeModel::legendInvalidateMapBasedData()
// we do that here because for symbols with size defined in map units
// the symbol sizes changes depends on the zoom level

QList<QgsSymbolV2LegendNode*> symbolNodes;
QMap<QString, int> widthMax;
foreach ( const LayerLegendData& data, mLegend )
{
QList<QgsSymbolV2LegendNode*> symbolNodes;
QMap<QString, int> widthMax;
foreach ( QgsLayerTreeModelLegendNode* legendNode, data.originalNodes )
{
legendNode->invalidateMapBasedData();
QgsSymbolV2LegendNode* n = dynamic_cast<QgsSymbolV2LegendNode*>( legendNode );
if ( n )
{
n->setParent( this ); // map scale are in the model, so the parent needs to be set
const QSize sz( n->minimumIconSize() );
const QString parentKey( n->data( QgsLayerTreeModelLegendNode::ParentRuleKeyRole ).toString() );
widthMax[parentKey] = qMax( sz.width(), widthMax.contains( parentKey ) ? widthMax[parentKey] : 0 );
n->setIconSize( sz );
symbolNodes.append( n );
}
}
foreach ( QgsSymbolV2LegendNode* n, symbolNodes )
{
const QString parentKey( n->data( QgsLayerTreeModelLegendNode::ParentRuleKeyRole ).toString() );
Q_ASSERT( widthMax[parentKey] > 0 );
const int twiceMarginWidth = 2; // a one pixel margin avoids hugly rendering of icon
n->setIconSize( QSize( widthMax[parentKey] + twiceMarginWidth, n->iconSize().rheight() + twiceMarginWidth ) );
}
foreach ( QgsLayerTreeModelLegendNode* legendNode, data.originalNodes )
legendNode->invalidateMapBasedData();
}

foreach ( QgsSymbolV2LegendNode* n, symbolNodes )
{
const QString parentKey( n->data( QgsLayerTreeModelLegendNode::ParentRuleKeyRole ).toString() );
Q_ASSERT( widthMax[parentKey] > 0 );
const int twiceMarginWidth = 2; // a one pixel margin avoids hugly rendering of icon
n->setIconSize( QSize( widthMax[parentKey] + twiceMarginWidth, n->iconSize().rheight() + twiceMarginWidth ) );
n->invalidateMapBasedData();
}
}

// Legend nodes routines - end

0 comments on commit 0a93f94

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