[expressions] Silently alias "geom" named across to "geometry"

So that was can standardize on using "geometry" as the named argument
insted of mixing "geom" and "geometry" in the public docs.
This commit is contained in:
Nyall Dawson 2020-07-30 09:15:52 +10:00
parent fd19167c0a
commit 813ee5a68d
3 changed files with 19 additions and 1 deletions

View File

@ -170,6 +170,11 @@ class CORE_EXPORT QgsExpressionNode SIP_ABSTRACT
bool mHasNamedNodes = false;
/**
* Cleans up and standardises the name of a named node.
*/
static QString cleanNamedNodeName( const QString &name );
public:
};

View File

@ -52,7 +52,7 @@ QgsExpressionNode::NodeList::~NodeList()
void QgsExpressionNode::NodeList::append( QgsExpressionNode::NamedNode *node )
{
mList.append( node->node );
mNameList.append( node->name.toLower() );
mNameList.append( cleanNamedNodeName( node->name ) );
mHasNamedNodes = true;
delete node;
}
@ -82,6 +82,17 @@ QString QgsExpressionNode::NodeList::dump() const
return msg;
}
QString QgsExpressionNode::NodeList::cleanNamedNodeName( const QString &name )
{
QString cleaned = name.toLower();
// upgrade older argument names to standard versions
if ( cleaned == QLatin1String( "geom" ) )
cleaned = QStringLiteral( "geometry" );
return cleaned;
}
//

View File

@ -1038,6 +1038,8 @@ class TestQgsExpression: public QObject
QTest::newRow( "exterior_ring polygon" ) << "geom_to_wkt(exterior_ring(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),( 0.1 0.1, 0.1 0.2, 0.2 0.2, 0.2, 0.1, 0.1 0.1))')))" << false << QVariant( "LineString (-1 -1, 4 0, 4 2, 0 2, -1 -1)" );
QTest::newRow( "exterior_ring line" ) << "exterior_ring(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'))" << false << QVariant();
QTest::newRow( "centroid polygon" ) << "geom_to_wkt(centroid( geomFromWKT('POLYGON((0 0,0 9,9 0,0 0))')))" << false << QVariant( "Point (3 3)" );
QTest::newRow( "centroid named argument geom" ) << "geom_to_wkt(centroid( geom:=geomFromWKT('POLYGON((0 0,0 9,9 0,0 0))')))" << false << QVariant( "Point (3 3)" );
QTest::newRow( "centroid named argument geometry" ) << "geom_to_wkt(centroid( geometry:=geomFromWKT('POLYGON((0 0,0 9,9 0,0 0))')))" << false << QVariant( "Point (3 3)" );
QTest::newRow( "centroid multi polygon" ) << "geom_to_wkt(centroid( geomFromWKT('MULTIPOLYGON(((0 0,0 1,1 1,1 0,0 0)),((2 0,2 1,3 1,3 0,2 0)))') ))" << false << QVariant( "Point (1.5 0.5)" );
QTest::newRow( "centroid point" ) << "geom_to_wkt(centroid( geomFromWKT('POINT (1.5 0.5)') ))" << false << QVariant( "Point (1.5 0.5)" );
QTest::newRow( "centroid line" ) << "geom_to_wkt(centroid( geomFromWKT('LINESTRING (-1 2, 9 12)') ))" << false << QVariant( "Point (4 7)" );