Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 0a93f94
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/core/layertree/qgslayertreemodel.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 0a93f94

Please sign in to comment.