Skip to content

Commit

Permalink
Complete addTopologicalPoints result values for QgsVectorLayer; add t…
Browse files Browse the repository at this point in the history
…ests for error result codes (-1 and 1)
  • Loading branch information
gacarrillor authored and nyalldawson committed Jul 22, 2021
1 parent 0d504ad commit 281fe95
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
24 changes: 24 additions & 0 deletions python/core/auto_generated/qgsvectorlayer.sip.in
Expand Up @@ -1658,8 +1658,14 @@ Adds topological points for every vertex of the geometry.

:param geom: the geometry where each vertex is added to segments of other features

:return: -1 in case of layer error (invalid or non editable)

:return: 0 in case of success

:return: 1 in case of geometry error (non spatial or null geometry)

:return: 2 in case no vertices needed to be added

.. note::

geom is not going to be modified by the function
Expand All @@ -1681,8 +1687,14 @@ editing.

:param p: position of the vertex

:return: -1 in case of layer error (invalid or non editable)

:return: 0 in case of success

:return: 1 in case of geometry error (non spatial or null geometry)

:return: 2 in case no vertices needed to be added

.. note::

Calls to :py:func:`~QgsVectorLayer.addTopologicalPoints` are only valid for layers in which edits have been enabled
Expand All @@ -1703,8 +1715,14 @@ editing.

:param p: position of the vertex

:return: -1 in case of layer error (invalid or non editable)

:return: 0 in case of success

:return: 1 in case of geometry error (non spatial or null geometry)

:return: 2 in case no vertices needed to be added

.. note::

Calls to :py:func:`~QgsVectorLayer.addTopologicalPoints` are only valid for layers in which edits have been enabled
Expand All @@ -1724,8 +1742,14 @@ editing.

:param ps: point sequence of the vertices

:return: -1 in case of layer error (invalid or non editable)

:return: 0 in case of success

:return: 1 in case of geometry error (non spatial or null geometry)

:return: 2 in case no vertices needed to be added

.. note::

Calls to :py:func:`~QgsVectorLayer.addTopologicalPoints` are only valid for layers in which edits have been enabled
Expand Down
12 changes: 12 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1593,7 +1593,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
/**
* Adds topological points for every vertex of the geometry.
* \param geom the geometry where each vertex is added to segments of other features
* \returns -1 in case of layer error (invalid or non editable)
* \returns 0 in case of success
* \returns 1 in case of geometry error (non spatial or null geometry)
* \returns 2 in case no vertices needed to be added
* \note geom is not going to be modified by the function
* \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
* by a call to startEditing(). Changes made to features using this method are not committed
Expand All @@ -1608,7 +1611,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* no additional vertex is inserted. This method is useful for topological
* editing.
* \param p position of the vertex
* \returns -1 in case of layer error (invalid or non editable)
* \returns 0 in case of success
* \returns 1 in case of geometry error (non spatial or null geometry)
* \returns 2 in case no vertices needed to be added
* \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
* by a call to startEditing(). Changes made to features using this method are not committed
* to the underlying data provider until a commitChanges() call is made. Any uncommitted
Expand All @@ -1623,7 +1629,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* no additional vertex is inserted. This method is useful for topological
* editing.
* \param p position of the vertex
* \returns -1 in case of layer error (invalid or non editable)
* \returns 0 in case of success
* \returns 1 in case of geometry error (non spatial or null geometry)
* \returns 2 in case no vertices needed to be added
* \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
* by a call to startEditing(). Changes made to features using this method are not committed
* to the underlying data provider until a commitChanges() call is made. Any uncommitted
Expand All @@ -1638,7 +1647,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* no additional vertex is inserted. This method is useful for topological
* editing.
* \param ps point sequence of the vertices
* \returns -1 in case of layer error (invalid or non editable)
* \returns 0 in case of success
* \returns 1 in case of geometry error (non spatial or null geometry)
* \returns 2 in case no vertices needed to be added
* \note Calls to addTopologicalPoints() are only valid for layers in which edits have been enabled
* by a call to startEditing(). Changes made to features using this method are not committed
* to the underlying data provider until a commitChanges() call is made. Any uncommitted
Expand Down
30 changes: 30 additions & 0 deletions tests/src/core/testqgsvectorlayer.cpp
Expand Up @@ -397,6 +397,36 @@ void TestQgsVectorLayer::testAddTopologicalPoints()
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 2, 1 3, 1 4, 1 5)" ).asWkt() );

delete layerLine;

// Test error results -1: layer error, 1: geometry error
QgsVectorLayer *nonSpatialLayer = new QgsVectorLayer( QStringLiteral( "None" ), QStringLiteral( "non spatial layer" ), QStringLiteral( "memory" ) );
QVERIFY( nonSpatialLayer->isValid() );

result = nonSpatialLayer->addTopologicalPoints( QgsPoint( 2, 2 ) );
QCOMPARE( result, -1 ); // Non editable

nonSpatialLayer->startEditing();
result = nonSpatialLayer->addTopologicalPoints( QgsPoint( 2, 2 ) );
QCOMPARE( result, 1 ); // Non spatial

delete nonSpatialLayer;

QgsVectorLayer *layerPoint = new QgsVectorLayer( QStringLiteral( "Point?crs=EPSG:27700" ), QStringLiteral( "layer point" ), QStringLiteral( "memory" ) );
QVERIFY( layerPoint->isValid() );

layerPoint->startEditing();
result = layerPoint->addTopologicalPoints( QgsGeometry() );
QCOMPARE( result, 1 ); // Null geometry

delete layerPoint;

QgsVectorLayer *layerInvalid = new QgsVectorLayer( QStringLiteral(), QStringLiteral( "layer invalid" ), QStringLiteral( "none" ) );
QVERIFY( !layerInvalid->isValid() );

result = layerInvalid->addTopologicalPoints( QgsPoint( 2, 2 ) );
QCOMPARE( result, -1 ); // Invalid layer

delete layerInvalid;
}

void TestQgsVectorLayer::testCopyPasteFieldConfiguration_data()
Expand Down

0 comments on commit 281fe95

Please sign in to comment.