@@ -1780,6 +1780,17 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
1780
1780
clonedGeometry.reset ( geom );
1781
1781
}
1782
1782
1783
+ // Rotate the geometry if needed, before clipping
1784
+ const QgsMapToPixel& m2p = context.mapToPixel ();
1785
+ if ( m2p.mapRotation () )
1786
+ {
1787
+ if ( geom->rotate ( m2p.mapRotation (), context.extent ().center () ) )
1788
+ {
1789
+ QgsDebugMsg ( QString (" Error rotating geometry" ).arg ( geom->exportToWkt () ) );
1790
+ return ; // really ?
1791
+ }
1792
+ }
1793
+
1783
1794
// CLIP the geometry if it is bigger than the extent
1784
1795
// don't clip if centroid is requested for whole feature
1785
1796
bool do_clip = false ;
@@ -1967,6 +1978,9 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
1967
1978
if ( ok )
1968
1979
{
1969
1980
dataDefinedRotation = true ;
1981
+ // TODO: add setting to disable having data defined rotation follow
1982
+ // map rotation ?
1983
+ rotD -= m2p.mapRotation ();
1970
1984
angle = rotD * M_PI / 180.0 ;
1971
1985
}
1972
1986
}
@@ -2070,6 +2084,18 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
2070
2084
}
2071
2085
}
2072
2086
2087
+ // rotate position with map if data-defined
2088
+ if ( dataDefinedPosition && m2p.mapRotation () )
2089
+ {
2090
+ const QgsPoint& center = context.extent ().center ();
2091
+ QTransform t = QTransform::fromTranslate ( center.x (), center.y () );
2092
+ t.rotate ( -m2p.mapRotation () );
2093
+ t.translate ( -center.x (), -center.y () );
2094
+ double xPosR, yPosR;
2095
+ t.map ( xPos, yPos, &xPosR, &yPosR );
2096
+ xPos = xPosR; yPos = yPosR;
2097
+ }
2098
+
2073
2099
xPos += xdiff;
2074
2100
yPos += ydiff;
2075
2101
}
@@ -3876,7 +3902,16 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
3876
3902
if ( context.renderingStopped () )
3877
3903
return ; // it has been cancelled
3878
3904
3905
+ #if 1 // XXX strk
3906
+ // features are pre-rotated but not scaled/translated,
3907
+ // so we only disable rotation here. Ideally, they'd be
3908
+ // also pre-scaled/translated, as suggested here:
3909
+ // http://hub.qgis.org/issues/11856
3910
+ QgsMapToPixel xform = mMapSettings ->mapToPixel ();
3911
+ xform.setMapRotation (0 ,0 ,0 );
3912
+ #else
3879
3913
const QgsMapToPixel& xform = mMapSettings->mapToPixel();
3914
+ #endif
3880
3915
3881
3916
// draw rectangles with all candidates
3882
3917
// this is done before actual solution of the problem
@@ -4124,7 +4159,7 @@ void QgsPalLabeling::drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* p
4124
4159
4125
4160
painter->save ();
4126
4161
4127
- #if 1 // TODO: generalize some of this
4162
+ #if 0 // TODO: generalize some of this
4128
4163
double w = lp->getWidth();
4129
4164
double h = lp->getHeight();
4130
4165
double cx = lp->getX() + w / 2.0;
@@ -4172,12 +4207,21 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QgsRenderContext& con
4172
4207
{
4173
4208
// NOTE: this is repeatedly called for multi-part labels
4174
4209
QPainter* painter = context.painter ();
4175
- const QgsMapToPixel* xform = &context.mapToPixel ();
4210
+ #if 1 // XXX strk
4211
+ // features are pre-rotated but not scaled/translated,
4212
+ // so we only disable rotation here. Ideally, they'd be
4213
+ // also pre-scaled/translated, as suggested here:
4214
+ // http://hub.qgis.org/issues/11856
4215
+ QgsMapToPixel xform = context.mapToPixel ();
4216
+ xform.setMapRotation (0 ,0 ,0 );
4217
+ #else
4218
+ const QgsMapToPixel& xform = context.mapToPixel();
4219
+ #endif
4176
4220
4177
4221
QgsLabelComponent component;
4178
4222
component.setDpiRatio ( dpiRatio );
4179
4223
4180
- QgsPoint outPt = xform-> transform ( label->getX (), label->getY () );
4224
+ QgsPoint outPt = xform. transform ( label->getX (), label->getY () );
4181
4225
// QgsPoint outPt2 = xform->transform( label->getX() + label->getWidth(), label->getY() + label->getHeight() );
4182
4226
// QRectF labelRect( 0, 0, outPt2.x() - outPt.x(), outPt2.y() - outPt.y() );
4183
4227
@@ -4188,8 +4232,8 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QgsRenderContext& con
4188
4232
{
4189
4233
// get rotated label's center point
4190
4234
QgsPoint centerPt ( outPt );
4191
- QgsPoint outPt2 = xform-> transform ( label->getX () + label->getWidth () / 2 ,
4192
- label->getY () + label->getHeight () / 2 );
4235
+ QgsPoint outPt2 = xform. transform ( label->getX () + label->getWidth () / 2 ,
4236
+ label->getY () + label->getHeight () / 2 );
4193
4237
4194
4238
double xc = outPt2.x () - outPt.x ();
4195
4239
double yc = outPt2.y () - outPt.y ();
@@ -4290,7 +4334,7 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QgsRenderContext& con
4290
4334
for ( int i = 0 ; i < lines; ++i )
4291
4335
{
4292
4336
painter->save ();
4293
- #if 1 // TODO: generalize some of this
4337
+ #if 0 // TODO: generalize some of this
4294
4338
LabelPosition* lp = label;
4295
4339
double w = lp->getWidth();
4296
4340
double h = lp->getHeight();
0 commit comments