Skip to content

Commit

Permalink
Add return cases to the docs and fully qualified enums
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Nov 24, 2017
1 parent 4f82adf commit 7a63a07
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 32 deletions.
44 changes: 44 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -1049,6 +1049,13 @@ Return the provider type for this layer
\param ring ring to add
\param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
:return: QgsGeometry.OperationResult
- Success
- LayerNotEditable
- AddRingNotInExistingFeature
- InvalidInputGeometryType
- AddRingNotClosed
- AddRingNotValid
- AddRingCrossesExistingRings
:rtype: QgsGeometry.OperationResult
%End

Expand All @@ -1058,6 +1065,13 @@ Return the provider type for this layer
\param ring ring to add
\param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
:return: QgsGeometry.OperationResult
- Success
- LayerNotEditable
- AddRingNotInExistingFeature
- InvalidInputGeometryType
- AddRingNotClosed
- AddRingNotValid
- AddRingCrossesExistingRings
.. note::

available in Python as addCurvedRing
Expand All @@ -1068,13 +1082,29 @@ Return the provider type for this layer
%Docstring
Adds a new part polygon to a multipart feature
:return: QgsGeometry.OperationResult
- Success
- LayerNotEditable
- SelectionIsEmpty
- SelectionIsGreaterThanOne
- AddPartSelectedGeometryNotFound
- AddPartNotMultiGeometry
- InvalidBaseGeometry
- InvalidInputGeometryType
:rtype: QgsGeometry.OperationResult
%End

QgsGeometry::OperationResult addPart( const QgsPointSequence &ring ) /PyName=addPartV2/;
%Docstring
Adds a new part polygon to a multipart feature
:return: QgsGeometry.OperationResult
- Success
- LayerNotEditable
- SelectionIsEmpty
- SelectionIsGreaterThanOne
- AddPartSelectedGeometryNotFound
- AddPartNotMultiGeometry
- InvalidBaseGeometry
- InvalidInputGeometryType
.. note::

available in Python bindings as addPartV2
Expand Down Expand Up @@ -1105,6 +1135,13 @@ Return the provider type for this layer
\param splitLine line that splits the layer features
\param topologicalEditing true if topological editing is enabled
:return: QgsGeometry.OperationResult
- Success
- NothingHappened
- LayerNotEditable
- InvalidInputGeometryType
- InvalidBaseGeometry
- GeometryEngineError
- SplitCannotSplitPoint
:rtype: QgsGeometry.OperationResult
%End

Expand All @@ -1114,6 +1151,13 @@ Return the provider type for this layer
\param splitLine line that splits the layer features
\param topologicalEditing true if topological editing is enabled
:return: QgsGeometry.OperationResult
- Success
- NothingHappened
- LayerNotEditable
- InvalidInputGeometryType
- InvalidBaseGeometry
- GeometryEngineError
- SplitCannotSplitPoint
:rtype: QgsGeometry.OperationResult
%End

Expand Down
16 changes: 8 additions & 8 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -674,7 +674,7 @@ QgsGeometry::OperationResult QgsGeometry::addPart( QgsAbstractGeometry *part, Qg
break;
default:
reset( nullptr );
return QgsGeometry::AddPartNotMultiGeometry;
return QgsGeometry::OperationResult::AddPartNotMultiGeometry;
}
}
else
Expand Down Expand Up @@ -785,7 +785,7 @@ QgsGeometry::OperationResult QgsGeometry::splitGeometry( const QVector<QgsPointX
{
if ( !d->geometry )
{
return InvalidBaseGeometry;
return QgsGeometry::OperationResult::InvalidBaseGeometry;
}

QVector<QgsGeometry > newGeoms;
Expand All @@ -808,19 +808,19 @@ QgsGeometry::OperationResult QgsGeometry::splitGeometry( const QVector<QgsPointX
switch ( result )
{
case QgsGeometryEngine::Success:
return QgsGeometry::Success;
return QgsGeometry::OperationResult::Success;
case QgsGeometryEngine::MethodNotImplemented:
case QgsGeometryEngine::EngineError:
case QgsGeometryEngine::NodedGeometryError:
return QgsGeometry::GeometryEngineError;
return QgsGeometry::OperationResult::GeometryEngineError;
case QgsGeometryEngine::InvalidBaseGeometry:
return QgsGeometry::InvalidBaseGeometry;
return QgsGeometry::OperationResult::InvalidBaseGeometry;
case QgsGeometryEngine::InvalidInput:
return QgsGeometry::InvalidInputGeometryType;
return QgsGeometry::OperationResult::InvalidInputGeometryType;
case QgsGeometryEngine::SplitCannotSplitPoint:
return QgsGeometry::SplitCannotSplitPoint;
return QgsGeometry::OperationResult::SplitCannotSplitPoint;
case QgsGeometryEngine::NothingHappened:
return QgsGeometry::NothingHappened;
return QgsGeometry::OperationResult::NothingHappened;
//default: do not implement default to handle properly all cases
}

Expand Down
24 changes: 12 additions & 12 deletions src/core/geometry/qgsgeometryeditutils.cpp
Expand Up @@ -50,17 +50,17 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addRing( QgsAbstractGeometry
}
else
{
return QgsGeometry::InvalidInputGeometryType; //not polygon / multipolygon;
return QgsGeometry::OperationResult::InvalidInputGeometryType; //not polygon / multipolygon;
}

//ring must be closed
if ( !ring->isClosed() )
{
return QgsGeometry::AddRingNotClosed;
return QgsGeometry::OperationResult::AddRingNotClosed;
}
else if ( !ring->isRing() )
{
return QgsGeometry::AddRingNotValid;
return QgsGeometry::OperationResult::AddRingNotValid;
}

std::unique_ptr<QgsGeometryEngine> ringGeom( QgsGeometry::createGeometryEngine( ring.get() ) );
Expand All @@ -78,7 +78,7 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addRing( QgsAbstractGeometry
{
if ( !ringGeom->disjoint( ( *polyIter )->interiorRing( i ) ) )
{
return QgsGeometry::AddRingCrossesExistingRings;
return QgsGeometry::OperationResult::AddRingCrossesExistingRings;
}
}

Expand All @@ -89,29 +89,29 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addRing( QgsAbstractGeometry
ring->addMValue( 0 );

( *polyIter )->addInteriorRing( ring.release() );
return QgsGeometry::Success; //success
return QgsGeometry::OperationResult::Success; //success
}
}
return QgsGeometry::AddRingNotInExistingFeature; //not contained in any outer ring
return QgsGeometry::OperationResult::AddRingNotInExistingFeature; //not contained in any outer ring
}

QgsGeometry::OperationResult QgsGeometryEditUtils::addPart( QgsAbstractGeometry *geom, std::unique_ptr<QgsAbstractGeometry> part )
{
if ( !geom )
{
return QgsGeometry::InvalidBaseGeometry;
return QgsGeometry::OperationResult::InvalidBaseGeometry;
}

if ( !part )
{
return QgsGeometry::InvalidInputGeometryType;
return QgsGeometry::OperationResult::InvalidInputGeometryType;
}

//multitype?
QgsGeometryCollection *geomCollection = qgsgeometry_cast<QgsGeometryCollection *>( geom );
if ( !geomCollection )
{
return QgsGeometry::AddPartNotMultiGeometry;
return QgsGeometry::OperationResult::AddPartNotMultiGeometry;
}

bool added = false;
Expand Down Expand Up @@ -155,19 +155,19 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addPart( QgsAbstractGeometry
{
while ( geomCollection->numGeometries() > n )
geomCollection->removeGeometry( n );
return QgsGeometry::InvalidInputGeometryType;
return QgsGeometry::OperationResult::InvalidInputGeometryType;
}
}
else
{
return QgsGeometry::InvalidInputGeometryType;
return QgsGeometry::OperationResult::InvalidInputGeometryType;
}
}
else
{
added = geomCollection->addGeometry( part.release() );
}
return added ? QgsGeometry::Success : QgsGeometry::InvalidInputGeometryType;
return added ? QgsGeometry::Success : QgsGeometry::OperationResult::InvalidInputGeometryType;
}

bool QgsGeometryEditUtils::deleteRing( QgsAbstractGeometry *geom, int ringNum, int partNum )
Expand Down
44 changes: 44 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1050,6 +1050,13 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* \param ring ring to add
* \param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
* \returns QgsGeometry::OperationResult
* - Success
* - LayerNotEditable
* - AddRingNotInExistingFeature
* - InvalidInputGeometryType
* - AddRingNotClosed
* - AddRingNotValid
* - AddRingCrossesExistingRings
*/
QgsGeometry::OperationResult addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = nullptr );

Expand All @@ -1058,19 +1065,42 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* \param ring ring to add
* \param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
* \returns QgsGeometry::OperationResult
* - Success
* - LayerNotEditable
* - AddRingNotInExistingFeature
* - InvalidInputGeometryType
* - AddRingNotClosed
* - AddRingNotValid
* - AddRingCrossesExistingRings
* \note available in Python as addCurvedRing
*/
QgsGeometry::OperationResult addRing( QgsCurve *ring SIP_TRANSFER, QgsFeatureId *featureId = nullptr ) SIP_PYNAME( addCurvedRing );

/**
* Adds a new part polygon to a multipart feature
* \returns QgsGeometry::OperationResult
* - Success
* - LayerNotEditable
* - SelectionIsEmpty
* - SelectionIsGreaterThanOne
* - AddPartSelectedGeometryNotFound
* - AddPartNotMultiGeometry
* - InvalidBaseGeometry
* - InvalidInputGeometryType
*/
QgsGeometry::OperationResult addPart( const QList<QgsPointXY> &ring );

/**
* Adds a new part polygon to a multipart feature
* \returns QgsGeometry::OperationResult
* - Success
* - LayerNotEditable
* - SelectionIsEmpty
* - SelectionIsGreaterThanOne
* - AddPartSelectedGeometryNotFound
* - AddPartNotMultiGeometry
* - InvalidBaseGeometry
* - InvalidInputGeometryType
* \note available in Python bindings as addPartV2
*/
QgsGeometry::OperationResult addPart( const QgsPointSequence &ring ) SIP_PYNAME( addPartV2 );
Expand All @@ -1092,6 +1122,13 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* \param splitLine line that splits the layer features
* \param topologicalEditing true if topological editing is enabled
* \returns QgsGeometry::OperationResult
* - Success
* - NothingHappened
* - LayerNotEditable
* - InvalidInputGeometryType
* - InvalidBaseGeometry
* - GeometryEngineError
* - SplitCannotSplitPoint
*/
QgsGeometry::OperationResult splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );

Expand All @@ -1100,6 +1137,13 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* \param splitLine line that splits the layer features
* \param topologicalEditing true if topological editing is enabled
* \returns QgsGeometry::OperationResult
* - Success
* - NothingHappened
* - LayerNotEditable
* - InvalidInputGeometryType
* - InvalidBaseGeometry
* - GeometryEngineError
* - SplitCannotSplitPoint
*/
QgsGeometry::OperationResult splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );

Expand Down

0 comments on commit 7a63a07

Please sign in to comment.