Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved placement for diagrams for line layers
Previously the diagrams would often be displaced from the line
(depending on the line orientation).
  • Loading branch information
nyalldawson committed Apr 22, 2015
1 parent b2ca7fa commit deba02f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/core/qgspallabeling.cpp
Expand Up @@ -3608,7 +3608,7 @@ void QgsPalLabeling::registerDiagramFeature( const QString& layerID, QgsFeature&

try
{
if ( !layerIt.value().palLayer->registerFeature( lbl->strId(), lbl, diagramWidth, diagramHeight, "", ddPosX, ddPosY, ddPos, 0.0, false, 0, 0, 0, 0, alwaysShow ) )
if ( !layerIt.value().palLayer->registerFeature( lbl->strId(), lbl, diagramWidth, diagramHeight, "", ddPosX, ddPosY, ddPos, 0.0, true, 0, 0, 0, 0, alwaysShow ) )
{
return;
}
Expand Down Expand Up @@ -4112,8 +4112,23 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
{
feature.setFields( &dit.value().fields );
palGeometry->feature( feature );
QgsPoint outPt = xform.transform(( *it )->getX(), ( *it )->getY() );
dit.value().renderer->renderDiagram( feature, context, outPt.toQPointF() );

//calculate top-left point for diagram
//first, calculate the centroid of the label (accounts for PAL creating
//rotated labels when we do not want to draw the diagrams rotated)
double centerX = 0;
double centerY = 0;
for ( int i = 0; i < 4; ++i )
{
centerX += ( *it )->getX( i );
centerY += ( *it )->getY( i );
}
QgsPoint outPt( centerX / 4.0, centerY / 4.0 );
//then, calculate the top left point for the diagram with this center position
QgsPoint centerPt = xform.transform( outPt.x() - ( *it )->getWidth() / 2,
outPt.y() - ( *it )->getHeight() / 2 );

dit.value().renderer->renderDiagram( feature, context, centerPt.toQPointF() );
}
}

Expand Down

0 comments on commit deba02f

Please sign in to comment.