@@ -187,9 +187,9 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
187
187
font.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
188
188
189
189
190
- QFontMetrics titleMetrics ( titleFont );
191
- QFontMetrics sectionMetrics ( sectionFont );
192
- QFontMetrics metrics ( font );
190
+ QFontMetricsF titleMetrics ( titleFont );
191
+ QFontMetricsF sectionMetrics ( sectionFont );
192
+ QFontMetricsF metrics ( font );
193
193
194
194
if ( plotStyle () == QgsComposition::Postscript) // do we need seperate PostScript rendering settings?
195
195
{
@@ -209,7 +209,7 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
209
209
font.setPointSizeFloat ( size * FONT_WORKAROUND_SCALE );
210
210
}
211
211
212
- int x, y;
212
+ double x, y;
213
213
214
214
// Legend title -if we do this later, we can center it
215
215
y = mMargin + titleMetrics.height ();
@@ -220,13 +220,13 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
220
220
painter->save (); // Save the painter state so we can undo the scaling later
221
221
painter->scale (1 ./FONT_WORKAROUND_SCALE, 1 ./FONT_WORKAROUND_SCALE); // scale the painter to work around the font bug
222
222
223
- painter->drawText ( 2 * mMargin * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE, mTitle );
223
+ painter->drawText ( QPointF ( 2 * mMargin * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE) , mTitle );
224
224
225
225
painter->restore ();
226
226
227
- // used to keep track of total width and height - probably should be changed to float/double
228
- int width = 4 * mMargin + titleMetrics.width ( mTitle );
229
- int height = mMargin + mSymbolSpace + titleMetrics.height (); // mSymbolSpace?
227
+ // used to keep track of total width and height
228
+ double width = 4 * mMargin + titleMetrics.width ( mTitle );
229
+ double height = mMargin + mSymbolSpace + titleMetrics.height (); // mSymbolSpace?
230
230
231
231
// Layers
232
232
QgsComposerMap *map = mComposition ->map ( mMap ); // Get the map from the composition by ID number
@@ -255,7 +255,7 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
255
255
256
256
// Make list of all layers in the group and count section items
257
257
std::vector<int > groupLayers; // vector of layers
258
- std::vector<int > itemHeights; // maximum item sizes
258
+ std::vector<double > itemHeights; // maximum item sizes
259
259
std::vector<QString> itemLabels; // item labels
260
260
int sectionItemsCount = 0 ;
261
261
QString sectionTitle;
@@ -309,7 +309,7 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
309
309
310
310
QPixmap pic = QPixmap::fromImage (sym->getPointSymbolAsImage (widthScale, false ));
311
311
312
- int h = ( int ) ( scale * pic.height () );
312
+ double h = scale * pic.height ();
313
313
if ( h > itemHeights[icnt] ) {
314
314
itemHeights[icnt] = h;
315
315
}
@@ -337,31 +337,31 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
337
337
{
338
338
height += mSymbolSpace ;
339
339
340
- x = ( int ) ( 2 *mMargin ) ;
341
- y = ( int ) ( height + sectionMetrics.height () );
340
+ x = 2 *mMargin ;
341
+ y = height + sectionMetrics.height ();
342
342
painter->setPen ( mPen );
343
343
painter->setFont ( sectionFont );
344
344
345
345
painter->save (); // Save the painter state so we can undo the scaling later
346
346
painter->scale (1 ./FONT_WORKAROUND_SCALE, 1 ./FONT_WORKAROUND_SCALE); // scale the painter to work around the font bug
347
347
348
- painter->drawText ( x * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE, sectionTitle );
348
+ painter->drawText (QPointF ( x * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE) , sectionTitle );
349
349
painter->restore ();
350
350
351
- int w = 3 *mMargin + sectionMetrics.width ( sectionTitle );
351
+ double w = 3 *mMargin + sectionMetrics.width ( sectionTitle );
352
352
if ( w > width ) width = w;
353
353
height += sectionMetrics.height ();
354
- height += (int ) ( 0.7 *mSymbolSpace );
354
+ height += (1.5 *mSymbolSpace );
355
355
}
356
356
357
357
358
358
// Draw all layers in group
359
- int groupStartHeight = height;
359
+ double groupStartHeight = height;
360
360
for ( int j = groupLayers.size ()-1 ; j >= 0 ; j-- )
361
361
{
362
362
std::cout << " layer = " << groupLayers[j] << std::endl;
363
363
364
- int localHeight = groupStartHeight;
364
+ double localHeight = groupStartHeight;
365
365
366
366
layer = mMapCanvas ->getZpos (groupLayers[j]);
367
367
QgsVectorLayer *vector = dynamic_cast <QgsVectorLayer*> (layer);
@@ -375,13 +375,14 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
375
375
for ( QList<QgsSymbol*>::iterator it = symbols.begin (); it != symbols.end (); ++it ) {
376
376
localHeight += mSymbolSpace ;
377
377
378
- int symbolHeight = itemHeights[icnt];
378
+ double symbolHeight = itemHeights[icnt];
379
379
QgsSymbol* sym = (*it);
380
380
381
381
QPen pen = sym->pen ();
382
382
double widthScale = map->widthScale ();
383
383
384
384
pen.setWidthF ( ( widthScale * pen.widthF () ) );
385
+ pen.setCapStyle (Qt::FlatCap); // make sure that the line doesn't extend past its endpoints
385
386
painter->setPen ( pen );
386
387
painter->setBrush ( sym->brush () );
387
388
@@ -399,13 +400,12 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
399
400
painter->restore ();
400
401
401
402
} else if ( vector->vectorType () == QGis::Line ) {
402
- painter->drawLine ( mMargin , localHeight+mSymbolHeight /2 ,
403
- mMargin +mSymbolWidth , localHeight+mSymbolHeight /2 );
403
+ painter->drawLine (QPointF ( mMargin , localHeight+mSymbolHeight /2 ) ,
404
+ QPointF ( mMargin +mSymbolWidth , localHeight+mSymbolHeight /2 ) );
404
405
} else if ( vector->vectorType () == QGis::Polygon ) {
405
- // pen.setWidth(0); //use a cosmetic pen to outline the fill box
406
406
pen.setCapStyle (Qt::FlatCap);
407
407
painter->setPen ( pen );
408
- painter->drawRect ( mMargin , localHeight, mSymbolWidth , mSymbolHeight );
408
+ painter->drawRect (QRectF ( mMargin , localHeight, mSymbolWidth , mSymbolHeight ) );
409
409
}
410
410
411
411
// Label
@@ -419,15 +419,15 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
419
419
}
420
420
421
421
// drawText (x, y w, h, ...) was cutting last letter (the box was too small)
422
- QRect br = metrics.boundingRect ( lab );
423
- x = ( int ) ( 2 *mMargin + mSymbolWidth ) ;
424
- y = ( int ) ( localHeight + symbolHeight/2 + ( metrics.height ()/2 - metrics.descent ()) );
425
- painter->save (); // Save the painter state so we can undo the scaling later
426
- painter->scale (1 ./FONT_WORKAROUND_SCALE, 1 ./FONT_WORKAROUND_SCALE); // scale the painter to work around the font bug
427
-
428
- painter->drawText ( x * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE, lab );
429
- painter->restore ();
430
- int w = 3 *mMargin + mSymbolWidth + metrics.width (lab);
422
+ QRectF br = metrics.boundingRect ( lab );
423
+ x = 2 *mMargin + mSymbolWidth ;
424
+ y = localHeight + symbolHeight/2 + ( metrics.height ()/2 - metrics.descent ());
425
+ painter->save (); // Save the painter state so we can undo the scaling later
426
+ painter->scale (1 ./FONT_WORKAROUND_SCALE, 1 ./FONT_WORKAROUND_SCALE);// scale the painter to work around the font bug
427
+
428
+ painter->drawText (QPointF ( x * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE) , lab );
429
+ painter->restore ();
430
+ double w = 3 *mMargin + mSymbolWidth + metrics.width (lab);
431
431
if ( w > width ) width = w;
432
432
433
433
localHeight += symbolHeight;
@@ -456,7 +456,7 @@ QRectF QgsComposerVectorLegend::render ( QPainter *p )
456
456
painter->setPen ( pen );
457
457
painter->setBrush ( QBrush ( QColor (255 ,255 ,255 ), Qt::NoBrush));
458
458
painter->setRenderHint (QPainter::Antialiasing, true );// turn on antialiasing
459
- painter->drawRect ( 0 , 0 , width, height );
459
+ painter->drawRect ( QRectF ( 0 , 0 , width, height) );
460
460
}
461
461
462
462
@@ -611,10 +611,10 @@ void QgsComposerVectorLegend::recalculate ( void )
611
611
// Font size in canvas units
612
612
float size = 25.4 * mComposition ->scale () * mFont .pointSizeFloat () / 72 ;
613
613
614
- mMargin = ( int ) ( 0.9 * size ) ;
615
- mSymbolHeight = ( int ) ( 1.3 * size ) ;
616
- mSymbolWidth = ( int ) ( 3.5 * size ) ;
617
- mSymbolSpace = ( int ) ( 0.4 * size ) ;
614
+ mMargin = 0.9 * size;
615
+ mSymbolHeight = 1.3 * size;
616
+ mSymbolWidth = 3.5 * size;
617
+ mSymbolSpace = 0.4 * size;
618
618
619
619
std::cout << " mMargin = " << mMargin << " mSymbolHeight = " << mSymbolHeight
620
620
<< " mSymbolWidth = " << mSymbolWidth << " mSymbolSpace = " << mSymbolSpace << std::endl;
0 commit comments