Skip to content

Commit e5e4a81

Browse files
author
marco
committedAug 8, 2011
Center small marker symbols in composer legend
1 parent cb529d0 commit e5e4a81

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed
 

‎src/core/composer/qgscomposerlegend.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ void QgsComposerLegend::drawSymbolV2( QPainter* p, QgsSymbolV2* s, double curren
404404
double height = mSymbolHeight;
405405
double width = mSymbolWidth;
406406
double size = 0;
407+
//Center small marker symbols
408+
double widthOffset = 0;
409+
double heightOffset = 0;
407410

408411
if ( markerSymbol )
409412
{
@@ -416,10 +419,18 @@ void QgsComposerLegend::drawSymbolV2( QPainter* p, QgsSymbolV2* s, double curren
416419
width *= mmPerMapUnit;
417420
markerSymbol->setSize( width );
418421
}
422+
if ( width < mSymbolWidth )
423+
{
424+
widthOffset = ( mSymbolWidth - width ) / 2.0;
425+
}
426+
if ( height < mSymbolHeight )
427+
{
428+
heightOffset = ( mSymbolHeight - height ) / 2.0;
429+
}
419430
}
420431

421432
p->save();
422-
p->translate( currentXPosition, currentYCoord );
433+
p->translate( currentXPosition + widthOffset, currentYCoord + heightOffset );
423434
p->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
424435

425436
if ( markerSymbol && sizeInMapUnits )
@@ -436,7 +447,8 @@ void QgsComposerLegend::drawSymbolV2( QPainter* p, QgsSymbolV2* s, double curren
436447

437448
p->restore();
438449
currentXPosition += width;
439-
symbolHeight = height;
450+
currentXPosition += 2 * widthOffset;
451+
symbolHeight = height + 2 * heightOffset;
440452
}
441453

442454
void QgsComposerLegend::drawPointSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int opacity ) const

0 commit comments

Comments
 (0)