[QGIS Commit] r14914 - trunk/qgis/src/core/symbology-ng
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Dec 14 17:47:50 EST 2010
Author: wonder
Date: 2010-12-14 14:47:50 -0800 (Tue, 14 Dec 2010)
New Revision: 14914
Modified:
trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Log:
Rotate also marker's offset, not just the marker itself (fixes #3334)
Modified: trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp 2010-12-14 22:09:39 UTC (rev 14913)
+++ trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp 2010-12-14 22:47:50 UTC (rev 14914)
@@ -22,6 +22,15 @@
#define DEG2RAD(x) ((x)*M_PI/180)
+static QPointF _rotatedOffset( const QPointF& offset, double angle )
+{
+ angle = DEG2RAD( angle );
+ double c = cos( angle ), s = sin( angle );
+ return QPointF( offset.x() * c - offset.y() * s, offset.x() * s + offset.y() * c );
+}
+
+//////
+
QgsSimpleMarkerSymbolLayerV2::QgsSimpleMarkerSymbolLayerV2( QString name, QColor color, QColor borderColor, double size, double angle )
{
mName = name;
@@ -342,13 +351,17 @@
return;
}
+ QPointF off( context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) );
+ if ( mAngle )
+ off = _rotatedOffset( off, mAngle );
+
if ( mUsingCache )
{
// we will use cached image
QImage &img = context.selected() ? mSelCache : mCache;
double s = img.width() / context.renderContext().rasterScaleFactor();
- p->drawImage( QRectF( point.x() - s / 2.0 + context.outputLineWidth( mOffset.x() ),
- point.y() - s / 2.0 + context.outputLineWidth( mOffset.y() ),
+ p->drawImage( QRectF( point.x() - s / 2.0 + off.x(),
+ point.y() - s / 2.0 + off.y(),
s, s ), img );
}
else
@@ -359,8 +372,7 @@
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale;
// move to the desired position
- transform.translate( point.x() + context.outputLineWidth( mOffset.x() ),
- point.y() + context.outputLineWidth( mOffset.y() ) );
+ transform.translate( point.x() + off.x(), point.y() + off.y() );
// resize if necessary
if ( hasDataDefinedSize )
@@ -499,6 +511,8 @@
p->save();
QPointF outputOffset = QPointF( context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) );
+ if ( mAngle )
+ outputOffset = _rotatedOffset( outputOffset, mAngle );
p->translate( point + outputOffset );
if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
@@ -700,6 +714,8 @@
p->save();
QPointF outputOffset = QPointF( context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) );
+ if ( mAngle )
+ outputOffset = _rotatedOffset( outputOffset, mAngle );
p->translate( point + outputOffset );
if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
More information about the QGIS-commit
mailing list