Skip to content

Commit 7feb1c3

Browse files
committedAug 27, 2012
SLD support: try to convert OGC Literal to number before using it as string, fix parser error check
1 parent 86a20e9 commit 7feb1c3

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed
 

‎src/core/qgsexpression.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,12 +1948,20 @@ QgsExpression::Node* QgsExpression::NodeLiteral::createFromOgcFilter( QDomElemen
19481948
}
19491949
else
19501950
{
1951-
// probably a text/CDATA node, convert its content to string
1952-
operand = new QgsExpression::NodeLiteral( childNode.nodeValue() );
1953-
}
1951+
// probably a text/CDATA node
1952+
QVariant value = childNode.nodeValue();
19541953

1955-
if ( !operand )
1956-
continue;
1954+
// try to convert the node content to number if possible,
1955+
// otherwise let's use it as string
1956+
bool ok;
1957+
double d = value.toDouble( &ok );
1958+
if ( ok )
1959+
value = d;
1960+
1961+
operand = new QgsExpression::NodeLiteral( value );
1962+
if ( !operand )
1963+
continue;
1964+
}
19571965

19581966
// use the concat operator to merge the ogc:Literal children
19591967
if ( !root )

‎src/core/symbology-ng/qgssymbollayerv2utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ bool QgsSymbolLayerV2Utils::rotationFromSldElement( QDomElement &element, QStrin
19221922
QDomElement rotationElem = element.firstChildElement( "Rotation" );
19231923
if ( !rotationElem.isNull() )
19241924
{
1925-
functionFromSldElement( rotationElem, rotationFunc );
1925+
return functionFromSldElement( rotationElem, rotationFunc );
19261926
}
19271927
return true;
19281928
}
@@ -1943,7 +1943,7 @@ bool QgsSymbolLayerV2Utils::opacityFromSldElement( QDomElement &element, QString
19431943
QDomElement opacityElem = element.firstChildElement( "Opacity" );
19441944
if ( !opacityElem.isNull() )
19451945
{
1946-
functionFromSldElement( opacityElem, alphaFunc );
1946+
return functionFromSldElement( opacityElem, alphaFunc );
19471947
}
19481948
return true;
19491949
}
@@ -2086,7 +2086,7 @@ bool QgsSymbolLayerV2Utils::functionFromSldElement( QDomElement &element, QStrin
20862086
if ( !expr )
20872087
return false;
20882088

2089-
bool valid = expr->hasParserError();
2089+
bool valid = !expr->hasParserError();
20902090
if ( !valid )
20912091
{
20922092
QgsDebugMsg( "parser error: " + expr->parserErrorString() );

0 commit comments

Comments
 (0)
Please sign in to comment.