@@ -103,9 +103,10 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
103103 drawText ( painter, mBoxSpace , currentYCoordinate, mTitle , mTitleFont );
104104 }
105105
106- double currentMaxXCoord;
106+
107107 maxXCoord = 2 * mBoxSpace + textWidthMillimeters ( mTitleFont , mTitle );
108108
109+ double currentItemMaxX = 0 ; // maximum x-coordinate for current item
109110 for ( int i = 0 ; i < numLayerItems; ++i )
110111 {
111112 currentLayerItem = rootItem->child ( i );
@@ -115,13 +116,13 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
115116 QgsComposerLegendItem::ItemType type = currentLegendItem->itemType ();
116117 if ( type == QgsComposerLegendItem::GroupItem )
117118 {
118- drawGroupItem ( painter, dynamic_cast <QgsComposerGroupItem*>( currentLegendItem ), currentYCoordinate, currentMaxXCoord );
119- maxXCoord = qMax ( maxXCoord, currentMaxXCoord );
119+ drawGroupItem ( painter, dynamic_cast <QgsComposerGroupItem*>( currentLegendItem ), currentYCoordinate, currentItemMaxX );
120+ maxXCoord = qMax ( maxXCoord, currentItemMaxX );
120121 }
121122 else if ( type == QgsComposerLegendItem::LayerItem )
122123 {
123- drawLayerItem ( painter, dynamic_cast <QgsComposerLayerItem*>( currentLegendItem ), currentYCoordinate, currentMaxXCoord );
124- maxXCoord = qMax ( maxXCoord, currentMaxXCoord );
124+ drawLayerItem ( painter, dynamic_cast <QgsComposerLayerItem*>( currentLegendItem ), currentYCoordinate, currentItemMaxX );
125+ maxXCoord = qMax ( maxXCoord, currentItemMaxX );
125126 }
126127 }
127128 }
@@ -168,6 +169,8 @@ void QgsComposerLegend::drawGroupItem( QPainter* p, QgsComposerGroupItem* groupI
168169
169170 p->setPen ( QColor ( 0 , 0 , 0 ) );
170171 drawText ( p, mBoxSpace , currentYCoord, groupItem->text (), mGroupFont );
172+
173+ // maximum x-coordinate of current item
171174 double currentMaxXCoord = 2 * mBoxSpace + textWidthMillimeters ( mGroupFont , groupItem->text () );
172175 maxXCoord = qMax ( currentMaxXCoord, maxXCoord );
173176
@@ -188,7 +191,7 @@ void QgsComposerLegend::drawGroupItem( QPainter* p, QgsComposerGroupItem* groupI
188191 else if ( type == QgsComposerLegendItem::LayerItem )
189192 {
190193 drawLayerItem ( p, dynamic_cast <QgsComposerLayerItem*>( currentLegendItem ), currentYCoord, currentMaxXCoord );
191- qMax ( currentMaxXCoord, maxXCoord );
194+ maxXCoord = qMax ( currentMaxXCoord, maxXCoord );
192195 }
193196 }
194197}
0 commit comments