QgsSymbolV2* QgsSingleSymbolRendererV2::symbolForFeature( QgsFeature& feature, QgsRenderContext &context ) { context.expressionContext().setFeature( feature ); if ( !mRotation.data() && !mSizeScale.data() ) return mSymbol.data(); const double rotation = mRotation.data() ? mRotation->evaluate( &context.expressionContext() ).toDouble() : 0; const double sizeScale = mSizeScale.data() ? mSizeScale->evaluate( &context.expressionContext() ).toDouble() : 1.; if ( mTempSymbol->type() == QgsSymbolV2::Marker ) { QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( mTempSymbol.data() ); if ( mRotation.data() ) markerSymbol->setAngle( rotation ); markerSymbol->setSize( sizeScale * mOrigSize ); markerSymbol->setScaleMethod( mScaleMethod ); } else if ( mTempSymbol->type() == QgsSymbolV2::Line ) { QgsLineSymbolV2* lineSymbol = static_cast<QgsLineSymbolV2*>( mTempSymbol.data() ); lineSymbol->setWidth( sizeScale * mOrigSize ); } else if ( mTempSymbol->type() == QgsSymbolV2::Fill ) { QgsFillSymbolV2* fillSymbol = static_cast<QgsFillSymbolV2*>( mTempSymbol.data() ); if ( mRotation.data() ) fillSymbol->setAngle( rotation ); } return mTempSymbol.data(); }
QgsSymbolV2* QgsSingleSymbolRendererV2::symbolForFeature( QgsFeature& feature ) { if ( mRotationFieldIdx == -1 && mSizeScaleFieldIdx == -1 ) return mSymbol; double rotation = 0; double sizeScale = 1; if ( mRotationFieldIdx != -1 ) { rotation = feature.attributeMap()[mRotationFieldIdx].toDouble(); } if ( mSizeScaleFieldIdx != -1 ) { sizeScale = feature.attributeMap()[mSizeScaleFieldIdx].toDouble(); } if ( mTempSymbol->type() == QgsSymbolV2::Marker ) { QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( mTempSymbol ); if ( mRotationFieldIdx != -1 ) markerSymbol->setAngle( rotation ); if ( mSizeScaleFieldIdx != -1 ) markerSymbol->setSize( sizeScale * mOrigSize ); markerSymbol->setScaleMethod( mScaleMethod ); } else if ( mTempSymbol->type() == QgsSymbolV2::Line ) { QgsLineSymbolV2* lineSymbol = static_cast<QgsLineSymbolV2*>( mTempSymbol ); if ( mSizeScaleFieldIdx != -1 ) lineSymbol->setWidth( sizeScale * mOrigSize ); } else if ( mTempSymbol->type() == QgsSymbolV2::Fill ) { QgsFillSymbolV2* fillSymbol = static_cast<QgsFillSymbolV2*>( mTempSymbol ); if ( mRotationFieldIdx != -1 ) fillSymbol->setAngle( rotation ); } return mTempSymbol; }