Skip to content

Commit

Permalink
Add map rotation to symbol rotation
Browse files Browse the repository at this point in the history
Only affects point marker symbols with data-defined rotation.
Fix #12152
  • Loading branch information
Sandro Santilli committed Feb 11, 2015
1 parent 335a167 commit 5397d6b
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -541,6 +541,27 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
{
angle = mAngleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
}

bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || mAngleExpression;
if ( hasDataDefinedRotation )
{
// For non-point markers, "dataDefinedRotation" means following the
// shape (shape-data defined). For them, "field-data defined" does
// not work at all. TODO: if "field-data defined" ever gets implemented
// we'll need a way to distinguish here between the two, possibly
// using another flag in renderHints()
const QgsFeature* f = context.feature();
if ( f )
{
QgsGeometry *g = f->geometry();
if ( g && g->type() == QGis::Point )
{
const QgsMapToPixel& m2p = context.renderContext().mapToPixel();
angle += m2p.mapRotation();
}
}
}

if ( angle )
off = _rotatedOffset( off, angle );

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

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

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

Expand Down Expand Up @@ -1318,6 +1339,27 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
{
angle = angleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
}

bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || angleExpression;
if ( hasDataDefinedRotation )
{
// For non-point markers, "dataDefinedRotation" means following the
// shape (shape-data defined). For them, "field-data defined" does
// not work at all. TODO: if "field-data defined" ever gets implemented
// we'll need a way to distinguish here between the two, possibly
// using another flag in renderHints()
const QgsFeature* f = context.feature();
if ( f )
{
QgsGeometry *g = f->geometry();
if ( g && g->type() == QGis::Point )
{
const QgsMapToPixel& m2p = context.renderContext().mapToPixel();
angle += m2p.mapRotation();
}
}
}

if ( angle )
outputOffset = _rotatedOffset( outputOffset, angle );
p->translate( point + outputOffset );
Expand Down

0 comments on commit 5397d6b

Please sign in to comment.