Skip to content
Permalink
Browse files

Fixes for PAL labels to work with 8a347eb

- 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 d83b618f1e3396a38d107fa40930f0332ba7ebc8
Showing with 16 additions and 8 deletions.
  1. +6 −0 src/app/qgsmaptoollabel.cpp
  2. +1 −1 src/app/qgsmaptoolrotatelabel.cpp
  3. +9 −7 src/core/qgspallabeling.cpp
@@ -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 );

@@ -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 )
{
@@ -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 );
@@ -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 )
{
@@ -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 );
@@ -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];

0 comments on commit d83b618

Please sign in to comment.
You can’t perform that action at this time.