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)
This commit is contained in:
Larry Shaffer 2012-09-16 11:07:33 -06:00
parent 0bd9bfbb18
commit d83b618f1e
3 changed files with 17 additions and 9 deletions

View File

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

View File

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

View File

@ -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 )
{
angle = angleOffset * M_PI / 180; // convert to radians
dataDefinedRotation = true;
angle = angleOffset * M_PI / 180; // convert to radians
}
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];