Skip to content

Commit 59545f1

Browse files
committedNov 1, 2011
Handle different vector field types
1 parent cc91d14 commit 59545f1

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed
 

‎python/core/symbology-ng-core.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ public:
711711
//! delete layer at specified index and set a new one
712712
bool changeSymbolLayer(int index, QgsSymbolLayerV2* layer /Transfer/);
713713

714-
void startRender( QgsRenderContext& context, const QgsVectorLayer* layer );
714+
void startRender( QgsRenderContext& context, const QgsVectorLayer* layer = 0 );
715715
void stopRender(QgsRenderContext& context);
716716

717717
void setColor(const QColor& color);

‎src/core/symbology-ng/qgsvectorfieldsymbollayer.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ void QgsVectorFieldSymbolLayer::renderPoint( const QPointF& point, QgsSymbolV2Re
105105
xComponent = context.outputLineWidth( xVal );
106106
yComponent = context.outputLineWidth( yVal );
107107
break;
108+
case Polar:
109+
convertPolarToCartesian( xVal, yVal, xComponent, yComponent );
110+
xComponent = context.outputLineWidth( xComponent );
111+
yComponent = context.outputLineWidth( yComponent );
112+
case Height:
113+
xComponent = 0;
114+
yComponent = context.outputLineWidth( yVal );
108115
default:
109116
break;
110117
}
@@ -189,3 +196,27 @@ QSet<QString> QgsVectorFieldSymbolLayer::usedAttributes() const
189196
}
190197
return attributes;
191198
}
199+
200+
void QgsVectorFieldSymbolLayer::convertPolarToCartesian( double length, double angle, double& x, double& y ) const
201+
{
202+
//convert angle to degree and to north orientation
203+
if ( mAngleOrientation == CounterclockwiseFromEast )
204+
{
205+
if ( angle <= 90 )
206+
{
207+
angle = 90 - angle;
208+
}
209+
else
210+
{
211+
angle = 360 - angle + 90;
212+
}
213+
}
214+
215+
if ( mAngleUnits == Degrees )
216+
{
217+
angle = angle * M_PI / 180.0;
218+
}
219+
220+
x = length * sin( angle );
221+
y = length * cos( angle );
222+
}

‎src/core/symbology-ng/qgsvectorfieldsymbollayer.h

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class CORE_EXPORT QgsVectorFieldSymbolLayer: public QgsMarkerSymbolLayerV2
9191
//Attribute indices are resolved in startRender method
9292
int mXIndex;
9393
int mYIndex;
94+
95+
//Converts length/angle to cartesian x/y
96+
void convertPolarToCartesian( double length, double angle, double& x, double& y ) const;
9497
};
9598

9699
#endif // QGSVECTORFIELDSYMBOLLAYER_H

0 commit comments

Comments
 (0)
Please sign in to comment.