Skip to content

Commit

Permalink
Fixes for PAL labels to work with 8a347eb
Browse files Browse the repository at this point in the history
- Point/centroid label offset functions now work with independent data defined rotation
- Rotate label tool now works with independent data defined rotation (always with Center/Half rotation point)
  • Loading branch information
dakcarto committed Sep 16, 2012
1 parent 0bd9bfb commit d83b618
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/app/qgsmaptoollabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ bool QgsMapToolLabel::rotationPoint( QgsPoint& pos, bool ignoreUpsideDown )
QString haliString, valiString;
currentAlignment( haliString, valiString );

if ( !mCurrentLabelPos.isPinned )
{
haliString = "Center";
valiString = "Half";
}

QFont labelFont = labelFontCurrentFeature();
QFontMetricsF labelFontMetrics( labelFont );

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolrotatelabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void QgsMapToolRotateLabel::canvasPressEvent( QMouseEvent *e )


bool hasRotationValue;
if ( dataDefinedRotation( vlayer, mCurrentLabelPos.featureId, mCurrentRotation, hasRotationValue ) )
if ( dataDefinedRotation( vlayer, mCurrentLabelPos.featureId, mCurrentRotation, hasRotationValue, true ) )
{
if ( !hasRotationValue )
{
Expand Down
16 changes: 9 additions & 7 deletions src/core/qgspallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
}
}

if( dataDefinedRotation )
if ( dataDefinedRotation )
{
//adjust xdiff and ydiff because the hali/vali point needs to be the rotation center
double xd = xdiff * cos( angle ) - ydiff * sin( angle );
Expand All @@ -831,7 +831,7 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
// does not flag label as pinned or rotateable
// always set rotation center as if Center/Half were set for data defined
bool overPointCentroid = false;
if ( !dataDefinedPosition
if ( !labelIsPinned
&& placement == QgsPalLayerSettings::OverPoint
&& geom->type() == QGis::Point )
{
Expand All @@ -854,11 +854,14 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
double descentRatio = labelFontMetrics.descent() / labelFontMetrics.height();
ydiff -= labelY * 0.5 * ( 1 - descentRatio );

if ( angleOffset != 0 )
if ( !dataDefinedRotation && angleOffset != 0 )
{
dataDefinedRotation = true;
angle = angleOffset * M_PI / 180; // convert to radians
}

dataDefinedRotation = true;
if ( dataDefinedRotation )
{
//adjust xdiff and ydiff for Center/Half
double xd = xdiff * cos( angle ) - ydiff * sin( angle );
double yd = xdiff * sin( angle ) + ydiff * cos( angle );
Expand Down Expand Up @@ -924,12 +927,11 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
double labelW = labelX;
double labelH = labelY;

if ( angleOffset != 0 )
if ( dataDefinedRotation )
{
// use LabelPosition construction to calculate new rotated label dimensions
pal::FeaturePart* fpart = new FeaturePart( feat, geom->asGeos() );
pal::LabelPosition* lp = new LabelPosition( 1, xPos, yPos, labelX, labelY,
( angleOffset * M_PI / 180 ), 0.0, fpart );
pal::LabelPosition* lp = new LabelPosition( 1, xPos, yPos, labelX, labelY, angle, 0.0, fpart );

// lp->getWidth or lp->getHeight doesn't account for rotation, get bbox instead
double amin[2], amax[2];
Expand Down

0 comments on commit d83b618

Please sign in to comment.