Skip to content

Commit

Permalink
fixed bug in rotation & removed xml encode/decode
Browse files Browse the repository at this point in the history
  • Loading branch information
vmora committed Jan 15, 2014
1 parent e8205c9 commit bf39737
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 48 deletions.
24 changes: 0 additions & 24 deletions src/core/qgis.h
Expand Up @@ -413,28 +413,4 @@ typedef unsigned long long qgssize;
# define QGISEXTERN extern "C" # define QGISEXTERN extern "C"
#endif #endif
#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 #endif
18 changes: 9 additions & 9 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Expand Up @@ -217,7 +217,7 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForFeature( QgsFeature& featu
if ( tempSymbol->type() == QgsSymbolV2::Marker ) if ( tempSymbol->type() == QgsSymbolV2::Marker )
{ {
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( tempSymbol ); QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( tempSymbol );
markerSymbol->setAngle( rotation ); if ( mRotation.data() ) markerSymbol->setAngle( rotation );
markerSymbol->setSize( sizeScale * static_cast<QgsMarkerSymbolV2*>( symbol )->size() ); markerSymbol->setSize( sizeScale * static_cast<QgsMarkerSymbolV2*>( symbol )->size() );
markerSymbol->setScaleMethod( mScaleMethod ); markerSymbol->setScaleMethod( mScaleMethod );
} }
Expand Down Expand Up @@ -434,10 +434,10 @@ void QgsCategorizedSymbolRendererV2::toSld( QDomDocument &doc, QDomElement &elem
{ {
QgsStringMap props; QgsStringMap props;
props[ "attribute" ] = mAttrName; props[ "attribute" ] = mAttrName;
if ( !mRotation.data() ) if ( mRotation.data() )
props[ "angle" ] = qgsXmlEncode( mRotation->expression() ).append( "\"" ).prepend( "\"" ); props[ "angle" ] = QString( mRotation->expression() ).append( "\"" ).prepend( "\"" );
if ( !mSizeScale.data() ) if ( mSizeScale.data() )
props[ "scale" ] = qgsXmlEncode( mSizeScale->expression() ).append( "\"" ).prepend( "\"" ); props[ "scale" ] = QString( mSizeScale->expression() ).append( "\"" ).prepend( "\"" );


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


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


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


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


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


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


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


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


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


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


Expand Down
16 changes: 8 additions & 8 deletions src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
Expand Up @@ -77,7 +77,7 @@ QgsSymbolV2* QgsSingleSymbolRendererV2::symbolForFeature( QgsFeature& feature )
if ( mTempSymbol->type() == QgsSymbolV2::Marker ) if ( mTempSymbol->type() == QgsSymbolV2::Marker )
{ {
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( mTempSymbol.data() ); QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( mTempSymbol.data() );
markerSymbol->setAngle( rotation ); if ( mRotation.data() ) markerSymbol->setAngle( rotation );
markerSymbol->setSize( sizeScale * mOrigSize ); markerSymbol->setSize( sizeScale * mOrigSize );
markerSymbol->setScaleMethod( mScaleMethod ); markerSymbol->setScaleMethod( mScaleMethod );
} }
Expand All @@ -89,7 +89,7 @@ QgsSymbolV2* QgsSingleSymbolRendererV2::symbolForFeature( QgsFeature& feature )
else if ( mTempSymbol->type() == QgsSymbolV2::Fill ) else if ( mTempSymbol->type() == QgsSymbolV2::Fill )
{ {
QgsFillSymbolV2* fillSymbol = static_cast<QgsFillSymbolV2*>( mTempSymbol.data() ); QgsFillSymbolV2* fillSymbol = static_cast<QgsFillSymbolV2*>( mTempSymbol.data() );
fillSymbol->setAngle( rotation ); if ( mRotation.data() ) fillSymbol->setAngle( rotation );
} }


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


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


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


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


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


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


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


Expand Down

0 comments on commit bf39737

Please sign in to comment.