Skip to content
Permalink
Browse files

further optional parameters decode hack

  • Loading branch information
enricofer authored and m-kuhn committed Jul 3, 2020
1 parent 50e07df commit e741750494866e602dbbf35bd147a8a4c00af286
Showing with 18 additions and 10 deletions.
  1. +15 −10 src/core/expression/qgsexpressionfunction.cpp
  2. +3 −0 tests/src/core/testqgsoverlayexpression.cpp
@@ -5692,8 +5692,13 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
request.setFilterExpression( filterString ); //filter cached features
}

int limit = QgsExpressionUtils::getIntValue( values.at( 3 ), parent ); //in expressions overlay functions throw the exception: Eval Error: Cannot convert '' to int
request.setLimit( limit );
node = QgsExpressionUtils::getNode( values.at( 3 ), parent ); //in expressions overlay functions throw the exception: Eval Error: Cannot convert '' to int
ENSURE_NO_EVAL_ERROR
QString limitString = node->dump();
if ( limitString != "NULL" ) {
int limit = QgsExpressionUtils::getIntValue( limitString, parent );
request.setLimit( limit );
}

int neighbors = 1;
/*
@@ -6284,7 +6289,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, QVariant(), true),
fcnGeomOverlayIntersects, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );

// The current feature is accessed for the geometry, so this should not be cached
@@ -6304,7 +6309,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, QVariant() ),
// TODO: limit param
fcnGeomOverlayContains, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
// The current feature is accessed for the geometry, so this should not be cached
@@ -6324,7 +6329,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, QVariant() ),
fcnGeomOverlayCrosses, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
// The current feature is accessed for the geometry, so this should not be cached
fcnGeomOverlayCrossesFunc->setIsStatic( false );
@@ -6343,7 +6348,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, QVariant() ),
fcnGeomOverlayEquals, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
// The current feature is accessed for the geometry, so this should not be cached
fcnGeomOverlayEqualsFunc->setIsStatic( false );
@@ -6362,7 +6367,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, QVariant() ),
fcnGeomOverlayTouches, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
// The current feature is accessed for the geometry, so this should not be cached
fcnGeomOverlayTouchesFunc->setIsStatic( false );
@@ -6381,7 +6386,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, QVariant() ),
fcnGeomOverlayDisjoint, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
// The current feature is accessed for the geometry, so this should not be cached
fcnGeomOverlayDisjointFunc->setIsStatic( false );
@@ -6400,7 +6405,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, QVariant() ),
fcnGeomOverlayWithin, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
// The current feature is accessed for the geometry, so this should not be cached
fcnGeomOverlayWithinFunc->setIsStatic( false );
@@ -6419,7 +6424,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 )
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, QVariant() )
<< QgsExpressionFunction::Parameter( QStringLiteral( "neighbors" ), true, 1 )
<< QgsExpressionFunction::Parameter( QStringLiteral( "max_distance" ), true, 0 ),
//<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true ),
@@ -164,10 +164,13 @@ void TestQgsOverlayExpression::testOverlayExpression_data()

QTest::newRow( "intersects get geometry" ) << "geometry_overlay_intersects('rectangles', $geometry)" << "POLYGON((-120 30, -105 30, -105 20, -120 20, -120 30))" << QVariantList { QgsGeometry::fromWkt( "MultiPolygon (((-130 40, -115 40, -115 25, -130 25, -130 40)))" ) };
QTest::newRow( "intersects get ids" ) << "geometry_overlay_intersects('rectangles', $id)" << "LINESTRING(-178 52, -133 33, -64 46)" << QVariantList { 1, 2, 3 };
QTest::newRow( "intersects get ids limit 2" ) << "geometry_overlay_intersects('rectangles', $id, limit:=2)" << "LINESTRING(-178 52, -133 33, -64 46)" << QVariantList { 1, 2 };
QTest::newRow( "intersects filtered get ids" ) << "geometry_overlay_intersects('rectangles', $id, $id != 2)" << "LINESTRING(-178 52, -133 33, -64 46)" << QVariantList { 1, 3 };
QTest::newRow( "intersects filtered get ids limit 1" ) << "geometry_overlay_intersects('rectangles', $id, $id != 2, 1)" << "LINESTRING(-178 52, -133 33, -64 46)" << QVariantList { 1 };
QTest::newRow( "touches get ids" ) << "geometry_overlay_touches('rectangles',$id)" << "POLYGON((-86 54, -95 50, -81 50, -86 54))" << QVariantList { 3 };
QTest::newRow( "equals get ids" ) << "geometry_overlay_equals('rectangles',$id)" << "MULTIPOLYGON(((-160 50, -145 50, -145 35, -160 35, -160 50)))" << QVariantList { 1 };
QTest::newRow( "disjoint get ids" ) << "geometry_overlay_disjoint('rectangles',$id)" << "LINESTRING(-155 15, -122 55, -84 4)" << QVariantList { 1, 2, 3 };
QTest::newRow( "disjoint get ids limit 2" ) << "geometry_overlay_disjoint('rectangles',$id, limit:=2)" << "LINESTRING(-155 15, -122 55, -84 4)" << QVariantList { 1, 2 };
QTest::newRow( "nearest" ) << "geometry_overlay_nearest('rectangles',$id)" << "POINT(-135 38)" << QVariantList { 2 };
QTest::newRow( "nearest filtered" ) << "geometry_overlay_nearest('rectangles',$id,$id != 2)" << "POINT(-135 38)" << QVariantList { 1 };
}

0 comments on commit e741750

Please sign in to comment.