Skip to content

Commit

Permalink
refacto: replace the parameter name 'i' to 'vertex'
Browse files Browse the repository at this point in the history
  • Loading branch information
Koyaani committed Nov 29, 2022
1 parent 77e9491 commit 46ed1e1
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions resources/function_help/json/$x_at
Expand Up @@ -4,8 +4,8 @@
"groups": ["GeometryGroup"],
"description": "Retrieves a x coordinate of the current feature's geometry. <b>WARNING: This function is deprecated. It is recommended to use the replacement x_at function with @geometry variable instead.</b>",
"arguments": [{
"arg": "i",
"description": "index of point of a line (indices start at 0; negative values apply from the last index, starting at -1)"
"arg": "vertex",
"description": "index of the vertex of the current geometry (indices start at 0; negative values apply from the last index, starting at -1)"
}],
"examples": [{
"expression": "$x_at(1)",
Expand Down
4 changes: 2 additions & 2 deletions resources/function_help/json/$y_at
Expand Up @@ -4,8 +4,8 @@
"groups": ["GeometryGroup"],
"description": "Retrieves a y coordinate of the current feature's geometry. <b>WARNING: This function is deprecated. It is recommended to use the replacement y_at function with @geometry variable instead.</b>",
"arguments": [{
"arg": "i",
"description": "index of point of a line (indices start at 0; negative values apply from the last index, starting at -1)"
"arg": "vertex",
"description": "index of the vertex of the current geometry (indices start at 0; negative values apply from the last index, starting at -1)"
}],
"examples": [{
"expression": "$y_at(1)",
Expand Down
2 changes: 1 addition & 1 deletion resources/function_help/json/m_at
Expand Up @@ -7,7 +7,7 @@
"arg": "geometry",
"description": "geometry object"
}, {
"arg": "i",
"arg": "vertex",
"description": "index of the vertex of the geometry (indices start at 0; negative values apply from the last index, starting at -1)"
}],
"examples": [{
Expand Down
2 changes: 1 addition & 1 deletion resources/function_help/json/x_at
Expand Up @@ -7,7 +7,7 @@
"arg": "geometry",
"description": "geometry object"
}, {
"arg": "i",
"arg": "vertex",
"description": "index of the vertex of the geometry (indices start at 0; negative values apply from the last index, starting at -1)"
}],
"examples": [{
Expand Down
2 changes: 1 addition & 1 deletion resources/function_help/json/y_at
Expand Up @@ -7,7 +7,7 @@
"arg": "geometry",
"description": "geometry object"
}, {
"arg": "i",
"arg": "vertex",
"description": "index of the vertex of the geometry (indices start at 0; negative values apply from the last index, starting at -1)"
}],
"examples": [{
Expand Down
2 changes: 1 addition & 1 deletion resources/function_help/json/z_at
Expand Up @@ -7,7 +7,7 @@
"arg": "geometry",
"description": "geometry object"
}, {
"arg": "i",
"arg": "vertex",
"description": "index of the vertex of the geometry (indices start at 0; negative values apply from the last index, starting at -1)"
}],
"examples": [{
Expand Down
12 changes: 6 additions & 6 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -8113,17 +8113,17 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
QgsExpressionFunction::Parameter( QStringLiteral( "keep_collapsed" ), true, false )
}, fcnGeomMakeValid, QStringLiteral( "GeometryGroup" ) );

functions << new QgsStaticExpressionFunction( QStringLiteral( "x_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ), true ) << QgsExpressionFunction::Parameter( QStringLiteral( "i" ), true ), fcnXat, QStringLiteral( "GeometryGroup" ) );
functions << new QgsStaticExpressionFunction( QStringLiteral( "y_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ), true ) << QgsExpressionFunction::Parameter( QStringLiteral( "i" ), true ), fcnYat, QStringLiteral( "GeometryGroup" ) );
functions << new QgsStaticExpressionFunction( QStringLiteral( "z_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ) ) << QgsExpressionFunction::Parameter( QStringLiteral( "i" ), true ), fcnZat, QStringLiteral( "GeometryGroup" ) );
functions << new QgsStaticExpressionFunction( QStringLiteral( "m_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ) ) << QgsExpressionFunction::Parameter( QStringLiteral( "i" ), true ), fcnMat, QStringLiteral( "GeometryGroup" ) );
functions << new QgsStaticExpressionFunction( QStringLiteral( "x_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ), true ) << QgsExpressionFunction::Parameter( QStringLiteral( "vertex" ), true ), fcnXat, QStringLiteral( "GeometryGroup" ) );
functions << new QgsStaticExpressionFunction( QStringLiteral( "y_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ), true ) << QgsExpressionFunction::Parameter( QStringLiteral( "vertex" ), true ), fcnYat, QStringLiteral( "GeometryGroup" ) );
functions << new QgsStaticExpressionFunction( QStringLiteral( "z_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ) ) << QgsExpressionFunction::Parameter( QStringLiteral( "vertex" ), true ), fcnZat, QStringLiteral( "GeometryGroup" ) );
functions << new QgsStaticExpressionFunction( QStringLiteral( "m_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ) ) << QgsExpressionFunction::Parameter( QStringLiteral( "vertex" ), true ), fcnMat, QStringLiteral( "GeometryGroup" ) );

QgsStaticExpressionFunction *xAtFunc = new QgsStaticExpressionFunction( QStringLiteral( "$x_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "i" ) ), fcnOldXat, QStringLiteral( "GeometryGroup" ), QString(), true, QSet<QString>(), false, QStringList() << QStringLiteral( "xat" ) );
QgsStaticExpressionFunction *xAtFunc = new QgsStaticExpressionFunction( QStringLiteral( "$x_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "vertex" ) ), fcnOldXat, QStringLiteral( "GeometryGroup" ), QString(), true, QSet<QString>(), false, QStringList() << QStringLiteral( "xat" ) );
xAtFunc->setIsStatic( false );
functions << xAtFunc;


QgsStaticExpressionFunction *yAtFunc = new QgsStaticExpressionFunction( QStringLiteral( "$y_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "i" ) ), fcnOldYat, QStringLiteral( "GeometryGroup" ), QString(), true, QSet<QString>(), false, QStringList() << QStringLiteral( "yat" ) );
QgsStaticExpressionFunction *yAtFunc = new QgsStaticExpressionFunction( QStringLiteral( "$y_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "vertex" ) ), fcnOldYat, QStringLiteral( "GeometryGroup" ), QString(), true, QSet<QString>(), false, QStringList() << QStringLiteral( "yat" ) );
yAtFunc->setIsStatic( false );
functions << yAtFunc;

Expand Down
2 changes: 2 additions & 0 deletions src/core/expression/qgsexpressionnodeimpl.cpp
Expand Up @@ -99,6 +99,8 @@ QString QgsExpressionNode::NodeList::cleanNamedNodeName( const QString &name )
cleaned = QStringLiteral( "geometry1" );
else if ( cleaned == QLatin1String( "geometry b" ) )
cleaned = QStringLiteral( "geometry2" );
else if ( cleaned == QLatin1String( "i" ) )
cleaned = QStringLiteral( "vertex" );

return cleaned;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -3386,6 +3386,18 @@ class TestQgsExpression: public QObject
yAt = expYAtNeg2.evaluate( &context );
QCOMPARE( yAt.toDouble(), 6.0 );

// test with named parameter
QgsExpression expYAtWithI( QStringLiteral( "x_at(@geometry, i:=1)" ) );
context.setFeature( fPolygon );
yAt = expYAtWithI.evaluate( &context );
QCOMPARE( yAt.toDouble(), 10.0 );

QgsExpression expYAtWithVertex( QStringLiteral( "x_at(@geometry, vertex:=1)" ) );
context.setFeature( fPolygon );
yAt = expYAtWithVertex.evaluate( &context );
QCOMPARE( yAt.toDouble(), 10.0 );


// Test z_at

// a basic case
Expand Down

0 comments on commit 46ed1e1

Please sign in to comment.