@@ -103,9 +103,10 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
103
103
drawText ( painter, mBoxSpace , currentYCoordinate, mTitle , mTitleFont );
104
104
}
105
105
106
- double currentMaxXCoord;
106
+
107
107
maxXCoord = 2 * mBoxSpace + textWidthMillimeters ( mTitleFont , mTitle );
108
108
109
+ double currentItemMaxX = 0 ; // maximum x-coordinate for current item
109
110
for ( int i = 0 ; i < numLayerItems; ++i )
110
111
{
111
112
currentLayerItem = rootItem->child ( i );
@@ -115,13 +116,13 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
115
116
QgsComposerLegendItem::ItemType type = currentLegendItem->itemType ();
116
117
if ( type == QgsComposerLegendItem::GroupItem )
117
118
{
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 );
120
121
}
121
122
else if ( type == QgsComposerLegendItem::LayerItem )
122
123
{
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 );
125
126
}
126
127
}
127
128
}
@@ -168,6 +169,8 @@ void QgsComposerLegend::drawGroupItem( QPainter* p, QgsComposerGroupItem* groupI
168
169
169
170
p->setPen ( QColor ( 0 , 0 , 0 ) );
170
171
drawText ( p, mBoxSpace , currentYCoord, groupItem->text (), mGroupFont );
172
+
173
+ // maximum x-coordinate of current item
171
174
double currentMaxXCoord = 2 * mBoxSpace + textWidthMillimeters ( mGroupFont , groupItem->text () );
172
175
maxXCoord = qMax ( currentMaxXCoord, maxXCoord );
173
176
@@ -188,7 +191,7 @@ void QgsComposerLegend::drawGroupItem( QPainter* p, QgsComposerGroupItem* groupI
188
191
else if ( type == QgsComposerLegendItem::LayerItem )
189
192
{
190
193
drawLayerItem ( p, dynamic_cast <QgsComposerLayerItem*>( currentLegendItem ), currentYCoord, currentMaxXCoord );
191
- qMax ( currentMaxXCoord, maxXCoord );
194
+ maxXCoord = qMax ( currentMaxXCoord, maxXCoord );
192
195
}
193
196
}
194
197
}
0 commit comments