Skip to content

Commit

Permalink
SLD support: try to convert OGC Literal to number before using it as …
Browse files Browse the repository at this point in the history
…string, fix parser error check
  • Loading branch information
brushtyler committed Aug 27, 2012
1 parent 86a20e9 commit 7feb1c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions src/core/qgsexpression.cpp
Expand Up @@ -1948,12 +1948,20 @@ QgsExpression::Node* QgsExpression::NodeLiteral::createFromOgcFilter( QDomElemen
}
else
{
// probably a text/CDATA node, convert its content to string
operand = new QgsExpression::NodeLiteral( childNode.nodeValue() );
}
// probably a text/CDATA node
QVariant value = childNode.nodeValue();

if ( !operand )
continue;
// try to convert the node content to number if possible,
// otherwise let's use it as string
bool ok;
double d = value.toDouble( &ok );
if ( ok )
value = d;

operand = new QgsExpression::NodeLiteral( value );
if ( !operand )
continue;
}

// use the concat operator to merge the ogc:Literal children
if ( !root )
Expand Down
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -1922,7 +1922,7 @@ bool QgsSymbolLayerV2Utils::rotationFromSldElement( QDomElement &element, QStrin
QDomElement rotationElem = element.firstChildElement( "Rotation" );
if ( !rotationElem.isNull() )
{
functionFromSldElement( rotationElem, rotationFunc );
return functionFromSldElement( rotationElem, rotationFunc );
}
return true;
}
Expand All @@ -1943,7 +1943,7 @@ bool QgsSymbolLayerV2Utils::opacityFromSldElement( QDomElement &element, QString
QDomElement opacityElem = element.firstChildElement( "Opacity" );
if ( !opacityElem.isNull() )
{
functionFromSldElement( opacityElem, alphaFunc );
return functionFromSldElement( opacityElem, alphaFunc );
}
return true;
}
Expand Down Expand Up @@ -2086,7 +2086,7 @@ bool QgsSymbolLayerV2Utils::functionFromSldElement( QDomElement &element, QStrin
if ( !expr )
return false;

bool valid = expr->hasParserError();
bool valid = !expr->hasParserError();
if ( !valid )
{
QgsDebugMsg( "parser error: " + expr->parserErrorString() );
Expand Down

0 comments on commit 7feb1c3

Please sign in to comment.