Skip to content
Permalink
Browse files

More legend cleanup

  • Loading branch information
Marco Hugentobler authored and mhugent committed Jul 2, 2011
1 parent 4215d51 commit 9a1f1351791c7a71ad46e6c42457c152b2f46936
Showing with 9 additions and 6 deletions.
  1. +9 −6 src/core/composer/qgscomposerlegend.cpp
@@ -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 );
@@ -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 );
}
}
}
@@ -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 );

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

0 comments on commit 9a1f135

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