Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More legend cleanup
  • Loading branch information
Marco Hugentobler authored and mhugent committed Jul 2, 2011
1 parent 4215d51 commit 9a1f135
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/core/composer/qgscomposerlegend.cpp
Expand Up @@ -101,9 +101,10 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
drawText( painter, mBoxSpace, currentYCoordinate, mTitle, mTitleFont );
}

double currentMaxXCoord;

maxXCoord = 2 * mBoxSpace + textWidthMillimeters( mTitleFont, mTitle );

double currentItemMaxX = 0; //maximum x-coordinate for current item
for ( int i = 0; i < numLayerItems; ++i )
{
currentLayerItem = rootItem->child( i );
Expand All @@ -113,13 +114,13 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
QgsComposerLegendItem::ItemType type = currentLegendItem->itemType();
if ( type == QgsComposerLegendItem::GroupItem )
{
drawGroupItem( painter, dynamic_cast<QgsComposerGroupItem*>( currentLegendItem ), currentYCoordinate, currentMaxXCoord );
maxXCoord = qMax( maxXCoord, currentMaxXCoord );
drawGroupItem( painter, dynamic_cast<QgsComposerGroupItem*>( currentLegendItem ), currentYCoordinate, currentItemMaxX );
maxXCoord = qMax( maxXCoord, currentItemMaxX );
}
else if ( type == QgsComposerLegendItem::LayerItem )
{
drawLayerItem( painter, dynamic_cast<QgsComposerLayerItem*>( currentLegendItem ), currentYCoordinate, currentMaxXCoord );
maxXCoord = qMax( maxXCoord, currentMaxXCoord );
drawLayerItem( painter, dynamic_cast<QgsComposerLayerItem*>( currentLegendItem ), currentYCoordinate, currentItemMaxX );
maxXCoord = qMax( maxXCoord, currentItemMaxX );
}
}
}
Expand Down Expand Up @@ -166,6 +167,8 @@ void QgsComposerLegend::drawGroupItem( QPainter* p, QgsComposerGroupItem* groupI

p->setPen( QColor( 0, 0, 0 ) );
drawText( p, mBoxSpace, currentYCoord, groupItem->text(), mGroupFont );

//maximum x-coordinate of current item
double currentMaxXCoord = 2 * mBoxSpace + textWidthMillimeters( mGroupFont, groupItem->text() );
maxXCoord = qMax( currentMaxXCoord, maxXCoord );

Expand All @@ -186,7 +189,7 @@ void QgsComposerLegend::drawGroupItem( QPainter* p, QgsComposerGroupItem* groupI
else if ( type == QgsComposerLegendItem::LayerItem )
{
drawLayerItem( p, dynamic_cast<QgsComposerLayerItem*>( currentLegendItem ), currentYCoord, currentMaxXCoord );
qMax( currentMaxXCoord, maxXCoord );
maxXCoord = qMax( currentMaxXCoord, maxXCoord );
}
}
}
Expand Down

0 comments on commit 9a1f135

Please sign in to comment.