Skip to content
Permalink
Browse files

fixed bug in rotation & removed xml encode/decode

  • Loading branch information
vmora committed Jan 15, 2014
1 parent e8205c9 commit bf39737c07c580df534a815cfac8ef29a4c41217
@@ -413,28 +413,4 @@ typedef unsigned long long qgssize;
# define QGISEXTERN extern "C"
#endif
#endif

inline
QString qgsXmlEncode( QString str )
{
// string passed as value to avoid internal copy
str.replace( "&", "&" );
str.replace( "\"", """ );
str.replace( "'", "'" );
str.replace( "<", "&lt;" );
str.replace( ">", "&gt;" );
return str;
}

inline
QString qgsXmlDecode( QString str )
{
// string passed as value to avoid internal copy
str.replace( "&amp;", "&" );
str.replace( "&quot;", "\"" );
str.replace( "&apos;", "'" );
str.replace( "&lt;", "<" );
str.replace( "&gt;", ">" );
return str;
}
#endif
@@ -217,7 +217,7 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForFeature( QgsFeature& featu
if ( tempSymbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( tempSymbol );
markerSymbol->setAngle( rotation );
if ( mRotation.data() ) markerSymbol->setAngle( rotation );
markerSymbol->setSize( sizeScale * static_cast<QgsMarkerSymbolV2*>( symbol )->size() );
markerSymbol->setScaleMethod( mScaleMethod );
}
@@ -434,10 +434,10 @@ void QgsCategorizedSymbolRendererV2::toSld( QDomDocument &doc, QDomElement &elem
{
QgsStringMap props;
props[ "attribute" ] = mAttrName;
if ( !mRotation.data() )
props[ "angle" ] = qgsXmlEncode( mRotation->expression() ).append( "\"" ).prepend( "\"" );
if ( !mSizeScale.data() )
props[ "scale" ] = qgsXmlEncode( mSizeScale->expression() ).append( "\"" ).prepend( "\"" );
if ( mRotation.data() )
props[ "angle" ] = QString( mRotation->expression() ).append( "\"" ).prepend( "\"" );
if ( mSizeScale.data() )
props[ "scale" ] = QString( mSizeScale->expression() ).append( "\"" ).prepend( "\"" );

// create a Rule for each range
for ( QgsCategoryList::const_iterator it = mCategories.constBegin(); it != mCategories.constEnd(); ++it )
@@ -516,12 +516,12 @@ QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2::create( QDomElement& eleme

QDomElement rotationElem = element.firstChildElement( "rotation" );
if ( !rotationElem.isNull() )
r->setRotationField( qgsXmlDecode( rotationElem.attribute( "field" ) ) );
r->setRotationField( rotationElem.attribute( "field" ) );

QDomElement sizeScaleElem = element.firstChildElement( "sizescale" );
if ( !sizeScaleElem.isNull() )
{
r->setSizeScaleField( qgsXmlDecode( sizeScaleElem.attribute( "field" ) ) );
r->setSizeScaleField( sizeScaleElem.attribute( "field" ) );
r->setScaleMethod( QgsSymbolLayerV2Utils::decodeScaleMethod( sizeScaleElem.attribute( "scalemethod" ) ) );
}

@@ -582,12 +582,12 @@ QDomElement QgsCategorizedSymbolRendererV2::save( QDomDocument& doc )

QDomElement rotationElem = doc.createElement( "rotation" );
if ( mRotation.data() )
rotationElem.setAttribute( "field", qgsXmlEncode( mRotation->expression() ) );
rotationElem.setAttribute( "field", mRotation->expression() );
rendererElem.appendChild( rotationElem );

QDomElement sizeScaleElem = doc.createElement( "sizescale" );
if ( mSizeScale.data() )
sizeScaleElem.setAttribute( "field", qgsXmlEncode( mSizeScale->expression() ) );
sizeScaleElem.setAttribute( "field", mSizeScale->expression() );
sizeScaleElem.setAttribute( "scalemethod", QgsSymbolLayerV2Utils::encodeScaleMethod( mScaleMethod ) );
rendererElem.appendChild( sizeScaleElem );

@@ -206,7 +206,7 @@ QgsSymbolV2* QgsGraduatedSymbolRendererV2::symbolForFeature( QgsFeature& feature
if ( tempSymbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( tempSymbol );
markerSymbol->setAngle( rotation );
if ( mRotation.data() ) markerSymbol->setAngle( rotation );
markerSymbol->setSize( sizeScale * static_cast<QgsMarkerSymbolV2*>( symbol )->size() );
markerSymbol->setScaleMethod( mScaleMethod );
}
@@ -342,10 +342,10 @@ void QgsGraduatedSymbolRendererV2::toSld( QDomDocument& doc, QDomElement &elemen
{
QgsStringMap props;
props[ "attribute" ] = mAttrName;
if ( !mRotation.data() )
props[ "angle" ] = qgsXmlEncode( mRotation->expression() ).append( "\"" ).prepend( "\"" );
if ( !mSizeScale.data() )
props[ "scale" ] = qgsXmlEncode( mSizeScale->expression() ).append( "\"" ).prepend( "\"" );
if ( mRotation.data() )
props[ "angle" ] = QString( mRotation->expression() ).append( "\"" ).prepend( "\"" );
if ( mSizeScale.data() )
props[ "scale" ] = QString( mSizeScale->expression() ).append( "\"" ).prepend( "\"" );

// create a Rule for each range
for ( QgsRangeList::const_iterator it = mRanges.constBegin(); it != mRanges.constEnd(); ++it )
@@ -1041,12 +1041,12 @@ QDomElement QgsGraduatedSymbolRendererV2::save( QDomDocument& doc )

QDomElement rotationElem = doc.createElement( "rotation" );
if ( mRotation.data() )
rotationElem.setAttribute( "field", qgsXmlEncode( mRotation->expression() ) );
rotationElem.setAttribute( "field", mRotation->expression() );
rendererElem.appendChild( rotationElem );

QDomElement sizeScaleElem = doc.createElement( "sizescale" );
if ( mSizeScale.data() )
sizeScaleElem.setAttribute( "field", qgsXmlEncode( mSizeScale->expression() ) );
sizeScaleElem.setAttribute( "field", mSizeScale->expression() );
sizeScaleElem.setAttribute( "scalemethod", QgsSymbolLayerV2Utils::encodeScaleMethod( mScaleMethod ) );
rendererElem.appendChild( sizeScaleElem );

@@ -77,7 +77,7 @@ QgsSymbolV2* QgsSingleSymbolRendererV2::symbolForFeature( QgsFeature& feature )
if ( mTempSymbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( mTempSymbol.data() );
markerSymbol->setAngle( rotation );
if ( mRotation.data() ) markerSymbol->setAngle( rotation );
markerSymbol->setSize( sizeScale * mOrigSize );
markerSymbol->setScaleMethod( mScaleMethod );
}
@@ -89,7 +89,7 @@ QgsSymbolV2* QgsSingleSymbolRendererV2::symbolForFeature( QgsFeature& feature )
else if ( mTempSymbol->type() == QgsSymbolV2::Fill )
{
QgsFillSymbolV2* fillSymbol = static_cast<QgsFillSymbolV2*>( mTempSymbol.data() );
fillSymbol->setAngle( rotation );
if ( mRotation.data() ) fillSymbol->setAngle( rotation );
}

return mTempSymbol.data();
@@ -189,9 +189,9 @@ void QgsSingleSymbolRendererV2::toSld( QDomDocument& doc, QDomElement &element )
{
QgsStringMap props;
if ( mRotation.data() )
props[ "angle" ] = qgsXmlEncode( mRotation->expression() ).append( "\"" ).prepend( "\"" );
props[ "angle" ] = QString( mRotation->expression() ).append( "\"" ).prepend( "\"" );
if ( mSizeScale.data() )
props[ "scale" ] = qgsXmlEncode( mSizeScale->expression() ).append( "\"" ).prepend( "\"" );
props[ "scale" ] = QString( mSizeScale->expression() ).append( "\"" ).prepend( "\"" );

QDomElement ruleElem = doc.createElement( "se:Rule" );
element.appendChild( ruleElem );
@@ -228,12 +228,12 @@ QgsFeatureRendererV2* QgsSingleSymbolRendererV2::create( QDomElement& element )

QDomElement rotationElem = element.firstChildElement( "rotation" );
if ( !rotationElem.isNull() )
r->setRotationField( qgsXmlDecode( rotationElem.attribute( "field" ) ) );
r->setRotationField( rotationElem.attribute( "field" ) );

QDomElement sizeScaleElem = element.firstChildElement( "sizescale" );
if ( !sizeScaleElem.isNull() )
{
r->setSizeScaleField( qgsXmlDecode( sizeScaleElem.attribute( "field" ) ) );
r->setSizeScaleField( sizeScaleElem.attribute( "field" ) );
r->setScaleMethod( QgsSymbolLayerV2Utils::decodeScaleMethod( sizeScaleElem.attribute( "scalemethod" ) ) );
}

@@ -342,12 +342,12 @@ QDomElement QgsSingleSymbolRendererV2::save( QDomDocument& doc )

QDomElement rotationElem = doc.createElement( "rotation" );
if ( mRotation.data() )
rotationElem.setAttribute( "field", qgsXmlEncode( mRotation->expression() ) );
rotationElem.setAttribute( "field", mRotation->expression() );
rendererElem.appendChild( rotationElem );

QDomElement sizeScaleElem = doc.createElement( "sizescale" );
if ( mSizeScale.data() )
sizeScaleElem.setAttribute( "field", qgsXmlEncode( mSizeScale->expression() ) );
sizeScaleElem.setAttribute( "field", mSizeScale->expression() );
sizeScaleElem.setAttribute( "scalemethod", QgsSymbolLayerV2Utils::encodeScaleMethod( mScaleMethod ) );
rendererElem.appendChild( sizeScaleElem );

0 comments on commit bf39737

Please sign in to comment.
You can’t perform that action at this time.