Skip to content

Commit 72553a6

Browse files
authoredNov 24, 2017
Merge pull request #5710 from elpaso/api-code-cleaning-int-2-enums
QgsVectorLayer code cleaning use enums instead of int
2 parents 916c9c4 + 58f5596 commit 72553a6

14 files changed

+298
-212
lines changed
 

‎doc/api_break.dox

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,6 +2615,10 @@ displayExpression instead. For the map tip use mapTipTemplate() instead.
26152615
- setLayerTransparency, layerTransparency, and layerTransparencyChanged were removed. Use opacity, setOpacity and opacityChanged instead.
26162616
- The c++ signature for uniqueValues() has changed (the PyQGIS method remains unchanged)
26172617
- hasGeometryType() has been removed, replaced by QgsMapLayer::isSpatial()
2618+
- addRing() now returns QgsGeometry::OperationResult enum, integer representation of returned values may have changed
2619+
- addPart() now returns QgsGeometry::OperationResult enum, integer representation of returned values may have changed
2620+
- splitParts() now returns QgsGeometry::OperationResult enum, integer representation of returned values may have changed
2621+
- splitFeatured() now returns QgsGeometry::OperationResult enum, integer representation of returned values may have changed
26182622

26192623

26202624
QgsVectorLayerEditBuffer {#qgis_api_break_3_0_QgsVectorLayerEditBuffer}

‎python/core/geometry/qgsgeometry.sip

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ class QgsGeometry
5252
Success,
5353
NothingHappened,
5454
InvalidBaseGeometry,
55-
InvalidInput,
55+
InvalidInputGeometryType,
56+
SelectionIsEmpty,
57+
SelectionIsGreaterThanOne,
5658
GeometryEngineError,
59+
LayerNotEditable,
5760
AddPartSelectedGeometryNotFound,
5861
AddPartNotMultiGeometry,
5962
AddRingNotClosed,

‎python/core/qgsvectorlayer.sip

Lines changed: 96 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,32 +1043,80 @@ Return the provider type for this layer
10431043
:rtype: bool
10441044
%End
10451045

1046-
int addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = 0 );
1047-
%Docstring
1048-
:rtype: int
1049-
%End
1050-
1051-
int addRing( QgsCurve *ring /Transfer/, QgsFeatureId *featureId = 0 ) /PyName=addCurvedRing/;
1052-
%Docstring
1053-
:rtype: int
1054-
%End
1046+
QgsGeometry::OperationResult addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = 0 );
1047+
%Docstring
1048+
Adds a ring to polygon/multipolygon features
1049+
\param ring ring to add
1050+
\param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
1051+
:return: QgsGeometry.OperationResult
1052+
- Success
1053+
- LayerNotEditable
1054+
- AddRingNotInExistingFeature
1055+
- InvalidInputGeometryType
1056+
- AddRingNotClosed
1057+
- AddRingNotValid
1058+
- AddRingCrossesExistingRings
1059+
:rtype: QgsGeometry.OperationResult
1060+
%End
1061+
1062+
QgsGeometry::OperationResult addRing( QgsCurve *ring /Transfer/, QgsFeatureId *featureId = 0 ) /PyName=addCurvedRing/;
1063+
%Docstring
1064+
Adds a ring to polygon/multipolygon features (takes ownership)
1065+
\param ring ring to add
1066+
\param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
1067+
:return: QgsGeometry.OperationResult
1068+
- Success
1069+
- LayerNotEditable
1070+
- AddRingNotInExistingFeature
1071+
- InvalidInputGeometryType
1072+
- AddRingNotClosed
1073+
- AddRingNotValid
1074+
- AddRingCrossesExistingRings
1075+
.. note::
10551076

1056-
int addPart( const QList<QgsPointXY> &ring );
1057-
%Docstring
1058-
:rtype: int
1059-
%End
1077+
available in Python as addCurvedRing
1078+
:rtype: QgsGeometry.OperationResult
1079+
%End
1080+
1081+
QgsGeometry::OperationResult addPart( const QList<QgsPointXY> &ring );
1082+
%Docstring
1083+
Adds a new part polygon to a multipart feature
1084+
:return: QgsGeometry.OperationResult
1085+
- Success
1086+
- LayerNotEditable
1087+
- SelectionIsEmpty
1088+
- SelectionIsGreaterThanOne
1089+
- AddPartSelectedGeometryNotFound
1090+
- AddPartNotMultiGeometry
1091+
- InvalidBaseGeometry
1092+
- InvalidInputGeometryType
1093+
:rtype: QgsGeometry.OperationResult
1094+
%End
1095+
1096+
QgsGeometry::OperationResult addPart( const QgsPointSequence &ring ) /PyName=addPartV2/;
1097+
%Docstring
1098+
Adds a new part polygon to a multipart feature
1099+
:return: QgsGeometry.OperationResult
1100+
- Success
1101+
- LayerNotEditable
1102+
- SelectionIsEmpty
1103+
- SelectionIsGreaterThanOne
1104+
- AddPartSelectedGeometryNotFound
1105+
- AddPartNotMultiGeometry
1106+
- InvalidBaseGeometry
1107+
- InvalidInputGeometryType
1108+
.. note::
10601109

1061-
int addPart( const QgsPointSequence &ring ) /PyName=addPartV2/;
1062-
%Docstring
1063-
:rtype: int
1110+
available in Python bindings as addPartV2
1111+
:rtype: QgsGeometry.OperationResult
10641112
%End
10651113

1066-
int addPart( QgsCurve *ring /Transfer/ ) /PyName=addCurvedPart/;
1114+
QgsGeometry::OperationResult addPart( QgsCurve *ring /Transfer/ ) /PyName=addCurvedPart/;
10671115
%Docstring
10681116
.. note::
10691117

10701118
available in Python as addCurvedPart
1071-
:rtype: int
1119+
:rtype: QgsGeometry.OperationResult
10721120
%End
10731121

10741122
int translateFeature( QgsFeatureId featureId, double dx, double dy );
@@ -1081,14 +1129,36 @@ Return the provider type for this layer
10811129
:rtype: int
10821130
%End
10831131

1084-
int splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
1085-
%Docstring
1086-
:rtype: int
1087-
%End
1088-
1089-
int splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
1090-
%Docstring
1091-
:rtype: int
1132+
QgsGeometry::OperationResult splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
1133+
%Docstring
1134+
Splits parts cut by the given line
1135+
\param splitLine line that splits the layer features
1136+
\param topologicalEditing true if topological editing is enabled
1137+
:return: QgsGeometry.OperationResult
1138+
- Success
1139+
- NothingHappened
1140+
- LayerNotEditable
1141+
- InvalidInputGeometryType
1142+
- InvalidBaseGeometry
1143+
- GeometryEngineError
1144+
- SplitCannotSplitPoint
1145+
:rtype: QgsGeometry.OperationResult
1146+
%End
1147+
1148+
QgsGeometry::OperationResult splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
1149+
%Docstring
1150+
Splits features cut by the given line
1151+
\param splitLine line that splits the layer features
1152+
\param topologicalEditing true if topological editing is enabled
1153+
:return: QgsGeometry.OperationResult
1154+
- Success
1155+
- NothingHappened
1156+
- LayerNotEditable
1157+
- InvalidInputGeometryType
1158+
- InvalidBaseGeometry
1159+
- GeometryEngineError
1160+
- SplitCannotSplitPoint
1161+
:rtype: QgsGeometry.OperationResult
10921162
%End
10931163

10941164
int addTopologicalPoints( const QgsGeometry &geom );

‎src/app/qgsmaptoolfillring.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,30 @@ void QgsMapToolFillRing::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
9090

9191
QVector< QgsPointXY > pointList = points();
9292

93-
int addRingReturnCode = vlayer->addRing( pointList, &fid );
94-
if ( addRingReturnCode != 0 )
93+
QgsGeometry::OperationResult addRingReturnCode = vlayer->addRing( pointList, &fid );
94+
95+
// AP: this is all dead code:
96+
//todo: open message box to communicate errors
97+
if ( addRingReturnCode != QgsGeometry::OperationResult::Success )
9598
{
9699
QString errorMessage;
97-
//todo: open message box to communicate errors
98-
if ( addRingReturnCode == 1 )
100+
if ( addRingReturnCode == QgsGeometry::OperationResult::InvalidInputGeometryType )
99101
{
100102
errorMessage = tr( "a problem with geometry type occurred" );
101103
}
102-
else if ( addRingReturnCode == 2 )
104+
else if ( addRingReturnCode == QgsGeometry::OperationResult::AddRingNotClosed )
103105
{
104106
errorMessage = tr( "the inserted Ring is not closed" );
105107
}
106-
else if ( addRingReturnCode == 3 )
108+
else if ( addRingReturnCode == QgsGeometry::OperationResult::AddRingNotValid )
107109
{
108110
errorMessage = tr( "the inserted Ring is not a valid geometry" );
109111
}
110-
else if ( addRingReturnCode == 4 )
112+
else if ( addRingReturnCode == QgsGeometry::OperationResult::AddRingCrossesExistingRings )
111113
{
112114
errorMessage = tr( "the inserted Ring crosses existing rings" );
113115
}
114-
else if ( addRingReturnCode == 5 )
116+
else if ( addRingReturnCode == QgsGeometry::OperationResult::AddRingNotInExistingFeature )
115117
{
116118
errorMessage = tr( "the inserted Ring is not contained in a feature" );
117119
}

‎src/app/qgsmaptoolsplitfeatures.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,33 @@ void QgsMapToolSplitFeatures::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
9393
//bring up dialog if a split was not possible (polygon) or only done once (line)
9494
int topologicalEditing = QgsProject::instance()->topologicalEditing();
9595
vlayer->beginEditCommand( tr( "Features split" ) );
96-
int returnCode = vlayer->splitFeatures( points(), topologicalEditing );
96+
QgsGeometry::OperationResult returnCode = vlayer->splitFeatures( points(), topologicalEditing );
9797
vlayer->endEditCommand();
98-
if ( returnCode == 4 )
98+
if ( returnCode == QgsGeometry::OperationResult::NothingHappened )
9999
{
100100
QgisApp::instance()->messageBar()->pushMessage(
101101
tr( "No features were split" ),
102102
tr( "If there are selected features, the split tool only applies to those. If you would like to split all features under the split line, clear the selection." ),
103103
QgsMessageBar::WARNING,
104104
QgisApp::instance()->messageTimeout() );
105105
}
106-
else if ( returnCode == 3 )
106+
else if ( returnCode == QgsGeometry::OperationResult::GeometryEngineError )
107107
{
108108
QgisApp::instance()->messageBar()->pushMessage(
109109
tr( "No feature split done" ),
110110
tr( "Cut edges detected. Make sure the line splits features into multiple parts." ),
111111
QgsMessageBar::WARNING,
112112
QgisApp::instance()->messageTimeout() );
113113
}
114-
else if ( returnCode == 7 )
114+
else if ( returnCode == QgsGeometry::OperationResult::InvalidBaseGeometry )
115115
{
116116
QgisApp::instance()->messageBar()->pushMessage(
117117
tr( "No feature split done" ),
118118
tr( "The geometry is invalid. Please repair before trying to split it." ),
119119
QgsMessageBar::WARNING,
120120
QgisApp::instance()->messageTimeout() );
121121
}
122-
else if ( returnCode != 0 )
122+
else if ( returnCode != QgsGeometry::OperationResult::Success )
123123
{
124124
//several intersections but only one split (most likely line)
125125
QgisApp::instance()->messageBar()->pushMessage(

‎src/app/qgsmaptoolsplitparts.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,33 @@ void QgsMapToolSplitParts::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
9191
//bring up dialog if a split was not possible (polygon) or only done once (line)
9292
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
9393
vlayer->beginEditCommand( tr( "Parts split" ) );
94-
int returnCode = vlayer->splitParts( points(), topologicalEditing );
94+
QgsGeometry::OperationResult returnCode = vlayer->splitParts( points(), topologicalEditing );
9595
vlayer->endEditCommand();
96-
if ( returnCode == 4 )
96+
if ( returnCode == QgsGeometry::OperationResult::NothingHappened )
9797
{
9898
QgisApp::instance()->messageBar()->pushMessage(
9999
tr( "No parts were split" ),
100100
tr( "If there are selected parts, the split tool only applies to those. If you would like to split all parts under the split line, clear the selection." ),
101101
QgsMessageBar::WARNING,
102102
QgisApp::instance()->messageTimeout() );
103103
}
104-
else if ( returnCode == 3 )
104+
else if ( returnCode == QgsGeometry::OperationResult::GeometryEngineError )
105105
{
106106
QgisApp::instance()->messageBar()->pushMessage(
107107
tr( "No part split done" ),
108108
tr( "Cut edges detected. Make sure the line splits parts into multiple parts." ),
109109
QgsMessageBar::WARNING,
110110
QgisApp::instance()->messageTimeout() );
111111
}
112-
else if ( returnCode == 7 )
112+
else if ( returnCode == QgsGeometry::OperationResult::InvalidBaseGeometry )
113113
{
114114
QgisApp::instance()->messageBar()->pushMessage(
115115
tr( "No part split done" ),
116116
tr( "The geometry is invalid. Please repair before trying to split it." ),
117117
QgsMessageBar::WARNING,
118118
QgisApp::instance()->messageTimeout() );
119119
}
120-
else if ( returnCode != 0 )
120+
else if ( returnCode != QgsGeometry::OperationResult::Success )
121121
{
122122
//several intersections but only one split (most likely line)
123123
QgisApp::instance()->messageBar()->pushMessage(

‎src/core/geometry/qgsgeometry.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ QgsGeometry::OperationResult QgsGeometry::addRing( QgsCurve *ring )
625625
std::unique_ptr< QgsCurve > r( ring );
626626
if ( !d->geometry )
627627
{
628-
return InvalidInput;
628+
return InvalidInputGeometryType;
629629
}
630630

631631
detach();
@@ -674,7 +674,7 @@ QgsGeometry::OperationResult QgsGeometry::addPart( QgsAbstractGeometry *part, Qg
674674
break;
675675
default:
676676
reset( nullptr );
677-
return QgsGeometry::AddPartNotMultiGeometry;
677+
return QgsGeometry::OperationResult::AddPartNotMultiGeometry;
678678
}
679679
}
680680
else
@@ -785,7 +785,7 @@ QgsGeometry::OperationResult QgsGeometry::splitGeometry( const QVector<QgsPointX
785785
{
786786
if ( !d->geometry )
787787
{
788-
return InvalidBaseGeometry;
788+
return QgsGeometry::OperationResult::InvalidBaseGeometry;
789789
}
790790

791791
QVector<QgsGeometry > newGeoms;
@@ -808,19 +808,19 @@ QgsGeometry::OperationResult QgsGeometry::splitGeometry( const QVector<QgsPointX
808808
switch ( result )
809809
{
810810
case QgsGeometryEngine::Success:
811-
return QgsGeometry::Success;
811+
return QgsGeometry::OperationResult::Success;
812812
case QgsGeometryEngine::MethodNotImplemented:
813813
case QgsGeometryEngine::EngineError:
814814
case QgsGeometryEngine::NodedGeometryError:
815-
return QgsGeometry::GeometryEngineError;
815+
return QgsGeometry::OperationResult::GeometryEngineError;
816816
case QgsGeometryEngine::InvalidBaseGeometry:
817-
return QgsGeometry::InvalidBaseGeometry;
817+
return QgsGeometry::OperationResult::InvalidBaseGeometry;
818818
case QgsGeometryEngine::InvalidInput:
819-
return QgsGeometry::InvalidInput;
819+
return QgsGeometry::OperationResult::InvalidInputGeometryType;
820820
case QgsGeometryEngine::SplitCannotSplitPoint:
821-
return QgsGeometry::SplitCannotSplitPoint;
821+
return QgsGeometry::OperationResult::SplitCannotSplitPoint;
822822
case QgsGeometryEngine::NothingHappened:
823-
return QgsGeometry::NothingHappened;
823+
return QgsGeometry::OperationResult::NothingHappened;
824824
//default: do not implement default to handle properly all cases
825825
}
826826

@@ -857,7 +857,7 @@ QgsGeometry::OperationResult QgsGeometry::reshapeGeometry( const QgsLineString &
857857
case QgsGeometryEngine::InvalidBaseGeometry:
858858
return InvalidBaseGeometry;
859859
case QgsGeometryEngine::InvalidInput:
860-
return InvalidInput;
860+
return InvalidInputGeometryType;
861861
case QgsGeometryEngine::SplitCannotSplitPoint: // should not happen
862862
return GeometryEngineError;
863863
case QgsGeometryEngine::NothingHappened:

‎src/core/geometry/qgsgeometry.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ class CORE_EXPORT QgsGeometry
121121
Success = 0, //!< Operation succeeded
122122
NothingHappened = 1000, //!< Nothing happened, without any error
123123
InvalidBaseGeometry, //!< The base geometry on which the operation is done is invalid or empty
124-
InvalidInput, //!< The input geometry (ring, part, split line, etc.) has not the correct geometry type
124+
InvalidInputGeometryType, //!< The input geometry (ring, part, split line, etc.) has not the correct geometry type
125+
SelectionIsEmpty, //!< No features were selected
126+
SelectionIsGreaterThanOne, //!< More than one features were selected
125127
GeometryEngineError, //!< Geometry engine misses a method implemented or an error occurred in the geometry engine
128+
LayerNotEditable, //!< Cannot edit layer
126129
/* Add part issues */
127130
AddPartSelectedGeometryNotFound, //!< The selected geometry cannot be found
128131
AddPartNotMultiGeometry, //!< The source geometry is not multi

‎src/core/geometry/qgsgeometryeditutils.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addRing( QgsAbstractGeometry
3030
{
3131
if ( !ring )
3232
{
33-
return QgsGeometry::InvalidInput;
33+
return QgsGeometry::InvalidInputGeometryType;
3434
}
3535

3636
QVector< QgsCurvePolygon * > polygonList;
@@ -50,17 +50,17 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addRing( QgsAbstractGeometry
5050
}
5151
else
5252
{
53-
return QgsGeometry::InvalidInput; //not polygon / multipolygon;
53+
return QgsGeometry::OperationResult::InvalidInputGeometryType; //not polygon / multipolygon;
5454
}
5555

5656
//ring must be closed
5757
if ( !ring->isClosed() )
5858
{
59-
return QgsGeometry::AddRingNotClosed;
59+
return QgsGeometry::OperationResult::AddRingNotClosed;
6060
}
6161
else if ( !ring->isRing() )
6262
{
63-
return QgsGeometry::AddRingNotValid;
63+
return QgsGeometry::OperationResult::AddRingNotValid;
6464
}
6565

6666
std::unique_ptr<QgsGeometryEngine> ringGeom( QgsGeometry::createGeometryEngine( ring.get() ) );
@@ -78,7 +78,7 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addRing( QgsAbstractGeometry
7878
{
7979
if ( !ringGeom->disjoint( ( *polyIter )->interiorRing( i ) ) )
8080
{
81-
return QgsGeometry::AddRingCrossesExistingRings;
81+
return QgsGeometry::OperationResult::AddRingCrossesExistingRings;
8282
}
8383
}
8484

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

9191
( *polyIter )->addInteriorRing( ring.release() );
92-
return QgsGeometry::Success; //success
92+
return QgsGeometry::OperationResult::Success; //success
9393
}
9494
}
95-
return QgsGeometry::AddRingNotInExistingFeature; //not contained in any outer ring
95+
return QgsGeometry::OperationResult::AddRingNotInExistingFeature; //not contained in any outer ring
9696
}
9797

9898
QgsGeometry::OperationResult QgsGeometryEditUtils::addPart( QgsAbstractGeometry *geom, std::unique_ptr<QgsAbstractGeometry> part )
9999
{
100100
if ( !geom )
101101
{
102-
return QgsGeometry::InvalidBaseGeometry;
102+
return QgsGeometry::OperationResult::InvalidBaseGeometry;
103103
}
104104

105105
if ( !part )
106106
{
107-
return QgsGeometry::InvalidInput;
107+
return QgsGeometry::OperationResult::InvalidInputGeometryType;
108108
}
109109

110110
//multitype?
111111
QgsGeometryCollection *geomCollection = qgsgeometry_cast<QgsGeometryCollection *>( geom );
112112
if ( !geomCollection )
113113
{
114-
return QgsGeometry::AddPartNotMultiGeometry;
114+
return QgsGeometry::OperationResult::AddPartNotMultiGeometry;
115115
}
116116

117117
bool added = false;
@@ -155,19 +155,19 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addPart( QgsAbstractGeometry
155155
{
156156
while ( geomCollection->numGeometries() > n )
157157
geomCollection->removeGeometry( n );
158-
return QgsGeometry::InvalidInput;
158+
return QgsGeometry::OperationResult::InvalidInputGeometryType;
159159
}
160160
}
161161
else
162162
{
163-
return QgsGeometry::InvalidInput;
163+
return QgsGeometry::OperationResult::InvalidInputGeometryType;
164164
}
165165
}
166166
else
167167
{
168168
added = geomCollection->addGeometry( part.release() );
169169
}
170-
return added ? QgsGeometry::Success : QgsGeometry::InvalidInput;
170+
return added ? QgsGeometry::Success : QgsGeometry::OperationResult::InvalidInputGeometryType;
171171
}
172172

173173
bool QgsGeometryEditUtils::deleteRing( QgsAbstractGeometry *geom, int ringNum, int partNum )

‎src/core/qgsvectorlayer.cpp

Lines changed: 72 additions & 75 deletions
Large diffs are not rendered by default.

‎src/core/qgsvectorlayer.h

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,65 +1050,64 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
10501050
* Adds a ring to polygon/multipolygon features
10511051
* \param ring ring to add
10521052
* \param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
1053-
* \returns
1054-
* 0 in case of success,
1055-
* 1 problem with feature type,
1056-
* 2 ring not closed,
1057-
* 3 ring not valid,
1058-
* 4 ring crosses existing rings,
1059-
* 5 no feature found where ring can be inserted
1060-
* 6 layer not editable
1053+
* \returns QgsGeometry::OperationResult
1054+
* - Success
1055+
* - LayerNotEditable
1056+
* - AddRingNotInExistingFeature
1057+
* - InvalidInputGeometryType
1058+
* - AddRingNotClosed
1059+
* - AddRingNotValid
1060+
* - AddRingCrossesExistingRings
10611061
*/
1062-
// TODO QGIS 3.0 returns an enum instead of a magic constant
1063-
int addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = nullptr );
1062+
QgsGeometry::OperationResult addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = nullptr );
10641063

10651064
/**
10661065
* Adds a ring to polygon/multipolygon features (takes ownership)
10671066
* \param ring ring to add
10681067
* \param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
1069-
* \returns
1070-
* 0 in case of success
1071-
* 1 problem with feature type
1072-
* 2 ring not closed
1073-
* 6 layer not editable
1068+
* \returns QgsGeometry::OperationResult
1069+
* - Success
1070+
* - LayerNotEditable
1071+
* - AddRingNotInExistingFeature
1072+
* - InvalidInputGeometryType
1073+
* - AddRingNotClosed
1074+
* - AddRingNotValid
1075+
* - AddRingCrossesExistingRings
10741076
* \note available in Python as addCurvedRing
10751077
*/
1076-
// TODO QGIS 3.0 returns an enum instead of a magic constant
1077-
int addRing( QgsCurve *ring SIP_TRANSFER, QgsFeatureId *featureId = nullptr ) SIP_PYNAME( addCurvedRing );
1078+
QgsGeometry::OperationResult addRing( QgsCurve *ring SIP_TRANSFER, QgsFeatureId *featureId = nullptr ) SIP_PYNAME( addCurvedRing );
10781079

10791080
/**
10801081
* Adds a new part polygon to a multipart feature
1081-
* \returns
1082-
* 0 in case of success,
1083-
* 1 if selected feature is not multipart,
1084-
* 2 if ring is not a valid geometry,
1085-
* 3 if new polygon ring not disjoint with existing rings,
1086-
* 4 if no feature was selected,
1087-
* 5 if several features are selected,
1088-
* 6 if selected geometry not found
1089-
* 7 layer not editable
1082+
* \returns QgsGeometry::OperationResult
1083+
* - Success
1084+
* - LayerNotEditable
1085+
* - SelectionIsEmpty
1086+
* - SelectionIsGreaterThanOne
1087+
* - AddPartSelectedGeometryNotFound
1088+
* - AddPartNotMultiGeometry
1089+
* - InvalidBaseGeometry
1090+
* - InvalidInputGeometryType
10901091
*/
1091-
// TODO QGIS 3.0 returns an enum instead of a magic constant
1092-
int addPart( const QList<QgsPointXY> &ring );
1092+
QgsGeometry::OperationResult addPart( const QList<QgsPointXY> &ring );
10931093

10941094
/**
10951095
* Adds a new part polygon to a multipart feature
1096-
* \returns
1097-
* 0 in case of success,
1098-
* 1 if selected feature is not multipart,
1099-
* 2 if ring is not a valid geometry,
1100-
* 3 if new polygon ring not disjoint with existing rings,
1101-
* 4 if no feature was selected,
1102-
* 5 if several features are selected,
1103-
* 6 if selected geometry not found
1104-
* 7 layer not editable
1096+
* \returns QgsGeometry::OperationResult
1097+
* - Success
1098+
* - LayerNotEditable
1099+
* - SelectionIsEmpty
1100+
* - SelectionIsGreaterThanOne
1101+
* - AddPartSelectedGeometryNotFound
1102+
* - AddPartNotMultiGeometry
1103+
* - InvalidBaseGeometry
1104+
* - InvalidInputGeometryType
11051105
* \note available in Python bindings as addPartV2
11061106
*/
1107-
// TODO QGIS 3.0 returns an enum instead of a magic constant
1108-
int addPart( const QgsPointSequence &ring ) SIP_PYNAME( addPartV2 );
1107+
QgsGeometry::OperationResult addPart( const QgsPointSequence &ring ) SIP_PYNAME( addPartV2 );
11091108

11101109
//! \note available in Python as addCurvedPart
1111-
int addPart( QgsCurve *ring SIP_TRANSFER ) SIP_PYNAME( addCurvedPart );
1110+
QgsGeometry::OperationResult addPart( QgsCurve *ring SIP_TRANSFER ) SIP_PYNAME( addCurvedPart );
11121111

11131112
/**
11141113
* Translates feature by dx, dy
@@ -1123,23 +1122,31 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
11231122
* Splits parts cut by the given line
11241123
* \param splitLine line that splits the layer features
11251124
* \param topologicalEditing true if topological editing is enabled
1126-
* \returns
1127-
* 0 in case of success,
1128-
* 4 if there is a selection but no feature split
1125+
* \returns QgsGeometry::OperationResult
1126+
* - Success
1127+
* - NothingHappened
1128+
* - LayerNotEditable
1129+
* - InvalidInputGeometryType
1130+
* - InvalidBaseGeometry
1131+
* - GeometryEngineError
1132+
* - SplitCannotSplitPoint
11291133
*/
1130-
// TODO QGIS 3.0 returns an enum instead of a magic constant
1131-
int splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
1134+
QgsGeometry::OperationResult splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
11321135

11331136
/**
11341137
* Splits features cut by the given line
11351138
* \param splitLine line that splits the layer features
11361139
* \param topologicalEditing true if topological editing is enabled
1137-
* \returns
1138-
* 0 in case of success,
1139-
* 4 if there is a selection but no feature split
1140-
*/
1141-
// TODO QGIS 3.0 returns an enum instead of a magic constant
1142-
int splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
1140+
* \returns QgsGeometry::OperationResult
1141+
* - Success
1142+
* - NothingHappened
1143+
* - LayerNotEditable
1144+
* - InvalidInputGeometryType
1145+
* - InvalidBaseGeometry
1146+
* - GeometryEngineError
1147+
* - SplitCannotSplitPoint
1148+
*/
1149+
QgsGeometry::OperationResult splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
11431150

11441151
/**
11451152
* Adds topological points for every vertex of the geometry.

‎src/core/qgsvectorlayereditutils.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::addPart( const QList<QgsPo
184184
QgsGeometry::OperationResult QgsVectorLayerEditUtils::addPart( const QgsPointSequence &points, QgsFeatureId featureId )
185185
{
186186
if ( !mLayer->isSpatial() )
187-
return QgsGeometry::AddPartSelectedGeometryNotFound;
187+
return QgsGeometry::OperationResult::AddPartSelectedGeometryNotFound;
188188

189189
QgsGeometry geometry;
190190
bool firstPart = false;
191191
QgsFeature f;
192192
if ( !mLayer->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) )
193-
return QgsGeometry::AddPartSelectedGeometryNotFound; //not found
193+
return QgsGeometry::OperationResult::AddPartSelectedGeometryNotFound; //not found
194194

195195
if ( !f.hasGeometry() )
196196
{
@@ -279,7 +279,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitFeatures( const QVect
279279

280280
double xMin, yMin, xMax, yMax;
281281
QgsRectangle bBox; //bounding box of the split line
282-
QgsGeometry::OperationResult returnCode = QgsGeometry::Success;
282+
QgsGeometry::OperationResult returnCode = QgsGeometry::OperationResult::Success;
283283
QgsGeometry::OperationResult splitFunctionReturn; //return code of QgsGeometry::splitGeometry
284284
int numberOfSplitFeatures = 0;
285285

@@ -301,7 +301,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitFeatures( const QVect
301301
}
302302
else
303303
{
304-
return QgsGeometry::InvalidInput;
304+
return QgsGeometry::OperationResult::InvalidInputGeometryType;
305305
}
306306

307307
if ( bBox.isEmpty() )
@@ -344,7 +344,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitFeatures( const QVect
344344
QVector<QgsPointXY> topologyTestPoints;
345345
QgsGeometry featureGeom = feat.geometry();
346346
splitFunctionReturn = featureGeom.splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
347-
if ( splitFunctionReturn == QgsGeometry::Success )
347+
if ( splitFunctionReturn == QgsGeometry::OperationResult::Success )
348348
{
349349
//change this geometry
350350
mLayer->editBuffer()->changeGeometry( feat.id(), featureGeom );
@@ -366,7 +366,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitFeatures( const QVect
366366
}
367367
++numberOfSplitFeatures;
368368
}
369-
else if ( splitFunctionReturn != QgsGeometry::Success && splitFunctionReturn != QgsGeometry::NothingHappened ) // i.e. no split but no error occurred
369+
else if ( splitFunctionReturn != QgsGeometry::OperationResult::Success && splitFunctionReturn != QgsGeometry::NothingHappened ) // i.e. no split but no error occurred
370370
{
371371
returnCode = splitFunctionReturn;
372372
}
@@ -376,7 +376,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitFeatures( const QVect
376376
{
377377
//There is a selection but no feature has been split.
378378
//Maybe user forgot that only the selected features are split
379-
returnCode = QgsGeometry::NothingHappened;
379+
returnCode = QgsGeometry::OperationResult::NothingHappened;
380380
}
381381

382382
return returnCode;
@@ -389,7 +389,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitParts( const QVector<
389389

390390
double xMin, yMin, xMax, yMax;
391391
QgsRectangle bBox; //bounding box of the split line
392-
QgsGeometry::OperationResult returnCode = QgsGeometry::Success;
392+
QgsGeometry::OperationResult returnCode = QgsGeometry::OperationResult::Success;
393393
QgsGeometry::OperationResult splitFunctionReturn; //return code of QgsGeometry::splitGeometry
394394
int numberOfSplitParts = 0;
395395

@@ -410,7 +410,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitParts( const QVector<
410410
}
411411
else
412412
{
413-
return QgsGeometry::InvalidInput;
413+
return QgsGeometry::OperationResult::InvalidInputGeometryType;
414414
}
415415

416416
if ( bBox.isEmpty() )
@@ -442,7 +442,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitParts( const QVector<
442442
fit = mLayer->getFeatures( QgsFeatureRequest().setFilterRect( bBox ).setFlags( QgsFeatureRequest::ExactIntersect ) );
443443
}
444444

445-
QgsGeometry::OperationResult addPartRet = QgsGeometry::Success;
445+
QgsGeometry::OperationResult addPartRet = QgsGeometry::OperationResult::Success;
446446

447447
QgsFeature feat;
448448
while ( fit.nextFeature( feat ) )
@@ -482,7 +482,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitParts( const QVector<
482482
}
483483
++numberOfSplitParts;
484484
}
485-
else if ( splitFunctionReturn != QgsGeometry::Success && splitFunctionReturn != QgsGeometry::NothingHappened )
485+
else if ( splitFunctionReturn != QgsGeometry::OperationResult::Success && splitFunctionReturn != QgsGeometry::OperationResult::NothingHappened )
486486
{
487487
returnCode = splitFunctionReturn;
488488
}
@@ -492,7 +492,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitParts( const QVector<
492492
{
493493
//There is a selection but no feature has been split.
494494
//Maybe user forgot that only the selected features are split
495-
returnCode = QgsGeometry::NothingHappened;
495+
returnCode = QgsGeometry::OperationResult::NothingHappened;
496496
}
497497

498498
return returnCode;

‎tests/src/python/test_qgsgeometry.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ def testAddPart(self):
14371437
]
14381438

14391439
polyline = QgsGeometry.fromPolylineXY(points[0])
1440-
self.assertEqual(polyline.addPointsXY(points[1][0:1]), QgsGeometry.InvalidInput, "addPoints with one point line unexpectedly succeeded.")
1440+
self.assertEqual(polyline.addPointsXY(points[1][0:1]), QgsGeometry.InvalidInputGeometryType, "addPoints with one point line unexpectedly succeeded.")
14411441
self.assertEqual(polyline.addPointsXY(points[1][0:2]), QgsGeometry.Success, "addPoints with two point line failed.")
14421442
expwkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0), (3 0, 3 1))"
14431443
wkt = polyline.asWkt()
@@ -1470,10 +1470,10 @@ def testAddPart(self):
14701470

14711471
polygon = QgsGeometry.fromPolygonXY(points[0])
14721472

1473-
self.assertEqual(polygon.addPointsXY(points[1][0][0:1]), QgsGeometry.InvalidInput, "addPoints with one point ring unexpectedly succeeded.")
1474-
self.assertEqual(polygon.addPointsXY(points[1][0][0:2]), QgsGeometry.InvalidInput, "addPoints with two point ring unexpectedly succeeded.")
1475-
self.assertEqual(polygon.addPointsXY(points[1][0][0:3]), QgsGeometry.InvalidInput, "addPoints with unclosed three point ring unexpectedly succeeded.")
1476-
self.assertEqual(polygon.addPointsXY([QgsPointXY(4, 0), QgsPointXY(5, 0), QgsPointXY(4, 0)]), QgsGeometry.InvalidInput, "addPoints with 'closed' three point ring unexpectedly succeeded.")
1473+
self.assertEqual(polygon.addPointsXY(points[1][0][0:1]), QgsGeometry.InvalidInputGeometryType, "addPoints with one point ring unexpectedly succeeded.")
1474+
self.assertEqual(polygon.addPointsXY(points[1][0][0:2]), QgsGeometry.InvalidInputGeometryType, "addPoints with two point ring unexpectedly succeeded.")
1475+
self.assertEqual(polygon.addPointsXY(points[1][0][0:3]), QgsGeometry.InvalidInputGeometryType, "addPoints with unclosed three point ring unexpectedly succeeded.")
1476+
self.assertEqual(polygon.addPointsXY([QgsPointXY(4, 0), QgsPointXY(5, 0), QgsPointXY(4, 0)]), QgsGeometry.InvalidInputGeometryType, "addPoints with 'closed' three point ring unexpectedly succeeded.")
14771477

14781478
self.assertEqual(polygon.addPointsXY(points[1][0]), QgsGeometry.Success, "addPoints failed")
14791479
expwkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))"
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.