Skip to content

Commit

Permalink
Merge branch 'master' of github.com:qgis/Quantum-GIS
Browse files Browse the repository at this point in the history
  • Loading branch information
homann committed Sep 16, 2012
2 parents cc63a1e + d83b618 commit e2ae059
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/app/qgsmaptoollabel.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ bool QgsMapToolLabel::rotationPoint( QgsPoint& pos, bool ignoreUpsideDown )
QString haliString, valiString; QString haliString, valiString;
currentAlignment( haliString, valiString ); currentAlignment( haliString, valiString );


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

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


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




bool hasRotationValue; bool hasRotationValue;
if ( dataDefinedRotation( vlayer, mCurrentLabelPos.featureId, mCurrentRotation, hasRotationValue ) ) if ( dataDefinedRotation( vlayer, mCurrentLabelPos.featureId, mCurrentRotation, hasRotationValue, true ) )
{ {
if ( !hasRotationValue ) if ( !hasRotationValue )
{ {
Expand Down
21 changes: 12 additions & 9 deletions src/core/qgspallabeling.cpp
Original file line number Original file line 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 //adjust xdiff and ydiff because the hali/vali point needs to be the rotation center
double xd = xdiff * cos( angle ) - ydiff * sin( angle ); 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 // does not flag label as pinned or rotateable
// always set rotation center as if Center/Half were set for data defined // always set rotation center as if Center/Half were set for data defined
bool overPointCentroid = false; bool overPointCentroid = false;
if ( !dataDefinedPosition if ( !labelIsPinned
&& placement == QgsPalLayerSettings::OverPoint && placement == QgsPalLayerSettings::OverPoint
&& geom->type() == QGis::Point ) && geom->type() == QGis::Point )
{ {
Expand All @@ -854,11 +854,14 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
double descentRatio = labelFontMetrics.descent() / labelFontMetrics.height(); double descentRatio = labelFontMetrics.descent() / labelFontMetrics.height();
ydiff -= labelY * 0.5 * ( 1 - descentRatio ); ydiff -= labelY * 0.5 * ( 1 - descentRatio );


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


dataDefinedRotation = true; if ( dataDefinedRotation )
{
//adjust xdiff and ydiff for Center/Half //adjust xdiff and ydiff for Center/Half
double xd = xdiff * cos( angle ) - ydiff * sin( angle ); double xd = xdiff * cos( angle ) - ydiff * sin( angle );
double yd = xdiff * sin( angle ) + ydiff * cos( 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 labelW = labelX;
double labelH = labelY; double labelH = labelY;


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


// lp->getWidth or lp->getHeight doesn't account for rotation, get bbox instead // lp->getWidth or lp->getHeight doesn't account for rotation, get bbox instead
double amin[2], amax[2]; double amin[2], amax[2];
Expand Down Expand Up @@ -1726,8 +1728,9 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, co
painter->scale( 1.0 / lyr.rasterCompressFactor, 1.0 / lyr.rasterCompressFactor ); painter->scale( 1.0 / lyr.rasterCompressFactor, 1.0 / lyr.rasterCompressFactor );


double yMultiLineOffset = ( multiLineList.size() - 1 - i ) * lyr.fontMetrics->height(); double yMultiLineOffset = ( multiLineList.size() - 1 - i ) * lyr.fontMetrics->height();
// yMultiLineOffset += lyr.fontMetrics->descent(); double ascentOffset = 0.0;
painter->translate( QPointF( 0, -yMultiLineOffset ) ); ascentOffset = lyr.fontMetrics->height() * 0.25 * lyr.fontMetrics->ascent() / lyr.fontMetrics->height();
painter->translate( QPointF( 0, - ascentOffset - yMultiLineOffset ) );


if ( drawBuffer ) if ( drawBuffer )
{ {
Expand Down

0 comments on commit e2ae059

Please sign in to comment.