Handle different vector field types

This commit is contained in:
Marco Hugentobler 2011-11-01 14:35:34 +01:00
parent cc91d142d6
commit 59545f1c65
3 changed files with 35 additions and 1 deletions

View File

@ -711,7 +711,7 @@ public:
//! delete layer at specified index and set a new one //! delete layer at specified index and set a new one
bool changeSymbolLayer(int index, QgsSymbolLayerV2* layer /Transfer/); bool changeSymbolLayer(int index, QgsSymbolLayerV2* layer /Transfer/);
void startRender( QgsRenderContext& context, const QgsVectorLayer* layer ); void startRender( QgsRenderContext& context, const QgsVectorLayer* layer = 0 );
void stopRender(QgsRenderContext& context); void stopRender(QgsRenderContext& context);
void setColor(const QColor& color); void setColor(const QColor& color);

View File

@ -105,6 +105,13 @@ void QgsVectorFieldSymbolLayer::renderPoint( const QPointF& point, QgsSymbolV2Re
xComponent = context.outputLineWidth( xVal ); xComponent = context.outputLineWidth( xVal );
yComponent = context.outputLineWidth( yVal ); yComponent = context.outputLineWidth( yVal );
break; break;
case Polar:
convertPolarToCartesian( xVal, yVal, xComponent, yComponent );
xComponent = context.outputLineWidth( xComponent );
yComponent = context.outputLineWidth( yComponent );
case Height:
xComponent = 0;
yComponent = context.outputLineWidth( yVal );
default: default:
break; break;
} }
@ -189,3 +196,27 @@ QSet<QString> QgsVectorFieldSymbolLayer::usedAttributes() const
} }
return attributes; return attributes;
} }
void QgsVectorFieldSymbolLayer::convertPolarToCartesian( double length, double angle, double& x, double& y ) const
{
//convert angle to degree and to north orientation
if ( mAngleOrientation == CounterclockwiseFromEast )
{
if ( angle <= 90 )
{
angle = 90 - angle;
}
else
{
angle = 360 - angle + 90;
}
}
if ( mAngleUnits == Degrees )
{
angle = angle * M_PI / 180.0;
}
x = length * sin( angle );
y = length * cos( angle );
}

View File

@ -91,6 +91,9 @@ class CORE_EXPORT QgsVectorFieldSymbolLayer: public QgsMarkerSymbolLayerV2
//Attribute indices are resolved in startRender method //Attribute indices are resolved in startRender method
int mXIndex; int mXIndex;
int mYIndex; int mYIndex;
//Converts length/angle to cartesian x/y
void convertPolarToCartesian( double length, double angle, double& x, double& y ) const;
}; };
#endif // QGSVECTORFIELDSYMBOLLAYER_H #endif // QGSVECTORFIELDSYMBOLLAYER_H