Skip to content

Commit e2c5fe7

Browse files
author
marco
committedAug 8, 2011
Center small marker symbols in composer legend
1 parent 6e889aa commit e2c5fe7

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed
 

‎src/core/composer/qgscomposerlegend.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ void QgsComposerLegend::drawSymbolV2( QPainter* p, QgsSymbolV2* s, double curren
408408
double height = mSymbolHeight;
409409
double width = mSymbolWidth;
410410
double size = 0;
411+
//Center small marker symbols
412+
double widthOffset = 0;
413+
double heightOffset = 0;
411414

412415
if ( markerSymbol )
413416
{
@@ -420,10 +423,18 @@ void QgsComposerLegend::drawSymbolV2( QPainter* p, QgsSymbolV2* s, double curren
420423
width *= mmPerMapUnit;
421424
markerSymbol->setSize( width );
422425
}
426+
if ( width < mSymbolWidth )
427+
{
428+
widthOffset = ( mSymbolWidth - width ) / 2.0;
429+
}
430+
if ( height < mSymbolHeight )
431+
{
432+
heightOffset = ( mSymbolHeight - height ) / 2.0;
433+
}
423434
}
424435

425436
p->save();
426-
p->translate( currentXPosition, currentYCoord );
437+
p->translate( currentXPosition + widthOffset, currentYCoord + heightOffset );
427438
p->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
428439

429440
if ( markerSymbol && sizeInMapUnits )
@@ -440,7 +451,8 @@ void QgsComposerLegend::drawSymbolV2( QPainter* p, QgsSymbolV2* s, double curren
440451

441452
p->restore();
442453
currentXPosition += width;
443-
symbolHeight = height;
454+
currentXPosition += 2 * widthOffset;
455+
symbolHeight = height + 2 * heightOffset;
444456
}
445457

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

0 commit comments

Comments
 (0)
Please sign in to comment.