Skip to content
Permalink
Browse files
Complete addTopologicalPoints result values for QgsVectorLayer; add t…
…ests for error result codes (-1 and 1)
  • Loading branch information
gacarrillor committed Jul 6, 2021
1 parent aeece71 commit 92231d74c861f6d40997efbe1e3a4a6de8f849fa
@@ -1630,8 +1630,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
@@ -1653,8 +1659,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
@@ -1675,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
@@ -1696,8 +1714,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
@@ -1580,7 +1580,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
@@ -1595,7 +1598,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
@@ -1610,7 +1616,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
@@ -1625,7 +1634,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
@@ -381,6 +381,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()

0 comments on commit 92231d7

Please sign in to comment.