Skip to content

Commit

Permalink
[expressions] Silently alias "geom" named across to "geometry"
Browse files Browse the repository at this point in the history
So that was can standardize on using "geometry" as the named argument
insted of mixing "geom" and "geometry" in the public docs.
  • Loading branch information
nyalldawson committed Jul 30, 2020
1 parent fd19167 commit 813ee5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/core/expression/qgsexpressionnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
};

Expand Down
13 changes: 12 additions & 1 deletion src/core/expression/qgsexpressionnodeimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}


//

Expand Down
2 changes: 2 additions & 0 deletions tests/src/core/testqgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)" );
Expand Down

0 comments on commit 813ee5a

Please sign in to comment.