Skip to content

Commit 5397d6b

Browse files
author
Sandro Santilli
committed
Add map rotation to symbol rotation
Only affects point marker symbols with data-defined rotation. Fix #12152
1 parent 335a167 commit 5397d6b

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

+43-1
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,27 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
541541
{
542542
angle = mAngleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
543543
}
544+
545+
bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || mAngleExpression;
546+
if ( hasDataDefinedRotation )
547+
{
548+
// For non-point markers, "dataDefinedRotation" means following the
549+
// shape (shape-data defined). For them, "field-data defined" does
550+
// not work at all. TODO: if "field-data defined" ever gets implemented
551+
// we'll need a way to distinguish here between the two, possibly
552+
// using another flag in renderHints()
553+
const QgsFeature* f = context.feature();
554+
if ( f )
555+
{
556+
QgsGeometry *g = f->geometry();
557+
if ( g && g->type() == QGis::Point )
558+
{
559+
const QgsMapToPixel& m2p = context.renderContext().mapToPixel();
560+
angle += m2p.mapRotation();
561+
}
562+
}
563+
}
564+
544565
if ( angle )
545566
off = _rotatedOffset( off, angle );
546567

@@ -558,6 +579,7 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
558579

559580
if ( mUsingCache )
560581
{
582+
//QgsDebugMsg( QString("XXX using cache") );
561583
// we will use cached image
562584
QImage &img = context.selected() ? mSelCache : mCache;
563585
double s = img.width() / context.renderContext().rasterScaleFactor();
@@ -580,7 +602,6 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
580602
transform.scale( half, half );
581603
}
582604

583-
bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || mAngleExpression;
584605
if ( angle != 0 && ( hasDataDefinedRotation || createdNewPath ) )
585606
transform.rotate( angle );
586607

@@ -1318,6 +1339,27 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
13181339
{
13191340
angle = angleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
13201341
}
1342+
1343+
bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || angleExpression;
1344+
if ( hasDataDefinedRotation )
1345+
{
1346+
// For non-point markers, "dataDefinedRotation" means following the
1347+
// shape (shape-data defined). For them, "field-data defined" does
1348+
// not work at all. TODO: if "field-data defined" ever gets implemented
1349+
// we'll need a way to distinguish here between the two, possibly
1350+
// using another flag in renderHints()
1351+
const QgsFeature* f = context.feature();
1352+
if ( f )
1353+
{
1354+
QgsGeometry *g = f->geometry();
1355+
if ( g && g->type() == QGis::Point )
1356+
{
1357+
const QgsMapToPixel& m2p = context.renderContext().mapToPixel();
1358+
angle += m2p.mapRotation();
1359+
}
1360+
}
1361+
}
1362+
13211363
if ( angle )
13221364
outputOffset = _rotatedOffset( outputOffset, angle );
13231365
p->translate( point + outputOffset );

0 commit comments

Comments
 (0)