Skip to content
Permalink
Browse files

QgsVectorLayer code cleaning use enums instead of int

It was one of the TODOs for QGIS 3
  • Loading branch information
elpaso committed Nov 23, 2017
1 parent d1cf7e6 commit def85fa20286c3b7c20949e76e0f65b18e6316cf
@@ -52,8 +52,11 @@ class QgsGeometry
Success,
NothingHappened,
InvalidBaseGeometry,
InvalidInput,
InvalidInputGeometryType,
SelectionIsEmpty,
SelectionIsGreaterThanOne,
GeometryEngineError,
LayerNotEditable,
AddPartSelectedGeometryNotFound,
AddPartNotMultiGeometry,
AddRingNotClosed,
@@ -1043,32 +1043,50 @@ Return the provider type for this layer
:rtype: bool
%End

int addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = 0 );
QgsGeometry::OperationResult addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = 0 );
%Docstring
:rtype: int
Adds a ring to polygon/multipolygon features
\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
:rtype: QgsGeometry.OperationResult
%End

int addRing( QgsCurve *ring /Transfer/, QgsFeatureId *featureId = 0 ) /PyName=addCurvedRing/;
QgsGeometry::OperationResult addRing( QgsCurve *ring /Transfer/, QgsFeatureId *featureId = 0 ) /PyName=addCurvedRing/;
%Docstring
:rtype: int
Adds a ring to polygon/multipolygon features (takes ownership)
\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
.. note::

available in Python as addCurvedRing
:rtype: QgsGeometry.OperationResult
%End

int addPart( const QList<QgsPointXY> &ring );
QgsGeometry::OperationResult addPart( const QList<QgsPointXY> &ring );
%Docstring
:rtype: int
Adds a new part polygon to a multipart feature
:return: QgsGeometry.OperationResult
:rtype: QgsGeometry.OperationResult
%End

int addPart( const QgsPointSequence &ring ) /PyName=addPartV2/;
QgsGeometry::OperationResult addPart( const QgsPointSequence &ring ) /PyName=addPartV2/;
%Docstring
:rtype: int
Adds a new part polygon to a multipart feature
:return: QgsGeometry.OperationResult
.. note::

available in Python bindings as addPartV2
:rtype: QgsGeometry.OperationResult
%End

int addPart( QgsCurve *ring /Transfer/ ) /PyName=addCurvedPart/;
QgsGeometry::OperationResult addPart( QgsCurve *ring /Transfer/ ) /PyName=addCurvedPart/;
%Docstring
.. note::

available in Python as addCurvedPart
:rtype: int
:rtype: QgsGeometry.OperationResult
%End

int translateFeature( QgsFeatureId featureId, double dx, double dy );
@@ -1081,14 +1099,22 @@ Return the provider type for this layer
:rtype: int
%End

int splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
QgsGeometry::OperationResult splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
%Docstring
:rtype: int
Splits parts cut by the given line
\param splitLine line that splits the layer features
\param topologicalEditing true if topological editing is enabled
:return: QgsGeometry.OperationResult
:rtype: QgsGeometry.OperationResult
%End

int splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
QgsGeometry::OperationResult splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
%Docstring
:rtype: int
Splits features cut by the given line
\param splitLine line that splits the layer features
\param topologicalEditing true if topological editing is enabled
:return: QgsGeometry.OperationResult
:rtype: QgsGeometry.OperationResult
%End

int addTopologicalPoints( const QgsGeometry &geom );
@@ -90,28 +90,30 @@ void QgsMapToolFillRing::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

QVector< QgsPointXY > pointList = points();

int addRingReturnCode = vlayer->addRing( pointList, &fid );
if ( addRingReturnCode != 0 )
QgsGeometry::OperationResult addRingReturnCode = vlayer->addRing( pointList, &fid );

// AP: this is all dead code:
//todo: open message box to communicate errors
if ( addRingReturnCode != QgsGeometry::OperationResult::Success )
{
QString errorMessage;
//todo: open message box to communicate errors
if ( addRingReturnCode == 1 )
if ( addRingReturnCode == QgsGeometry::OperationResult::InvalidInputGeometryType )
{
errorMessage = tr( "a problem with geometry type occurred" );
}
else if ( addRingReturnCode == 2 )
else if ( addRingReturnCode == QgsGeometry::OperationResult::AddRingNotClosed )
{
errorMessage = tr( "the inserted Ring is not closed" );
}
else if ( addRingReturnCode == 3 )
else if ( addRingReturnCode == QgsGeometry::OperationResult::AddRingNotValid )
{
errorMessage = tr( "the inserted Ring is not a valid geometry" );
}
else if ( addRingReturnCode == 4 )
else if ( addRingReturnCode == QgsGeometry::OperationResult::AddRingCrossesExistingRings )
{
errorMessage = tr( "the inserted Ring crosses existing rings" );
}
else if ( addRingReturnCode == 5 )
else if ( addRingReturnCode == QgsGeometry::OperationResult::AddRingNotInExistingFeature )
{
errorMessage = tr( "the inserted Ring is not contained in a feature" );
}
@@ -93,33 +93,33 @@ void QgsMapToolSplitFeatures::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
//bring up dialog if a split was not possible (polygon) or only done once (line)
int topologicalEditing = QgsProject::instance()->topologicalEditing();
vlayer->beginEditCommand( tr( "Features split" ) );
int returnCode = vlayer->splitFeatures( points(), topologicalEditing );
QgsGeometry::OperationResult returnCode = vlayer->splitFeatures( points(), topologicalEditing );
vlayer->endEditCommand();
if ( returnCode == 4 )
if ( returnCode == QgsGeometry::OperationResult::NothingHappened )
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "No features were split" ),
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." ),
QgsMessageBar::WARNING,
QgisApp::instance()->messageTimeout() );
}
else if ( returnCode == 3 )
else if ( returnCode == QgsGeometry::OperationResult::GeometryEngineError )
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "No feature split done" ),
tr( "Cut edges detected. Make sure the line splits features into multiple parts." ),
QgsMessageBar::WARNING,
QgisApp::instance()->messageTimeout() );
}
else if ( returnCode == 7 )
else if ( returnCode == QgsGeometry::OperationResult::InvalidBaseGeometry )
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "No feature split done" ),
tr( "The geometry is invalid. Please repair before trying to split it." ),
QgsMessageBar::WARNING,
QgisApp::instance()->messageTimeout() );
}
else if ( returnCode != 0 )
else if ( returnCode != QgsGeometry::OperationResult::Success )
{
//several intersections but only one split (most likely line)
QgisApp::instance()->messageBar()->pushMessage(
@@ -91,33 +91,33 @@ void QgsMapToolSplitParts::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
//bring up dialog if a split was not possible (polygon) or only done once (line)
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
vlayer->beginEditCommand( tr( "Parts split" ) );
int returnCode = vlayer->splitParts( points(), topologicalEditing );
QgsGeometry::OperationResult returnCode = vlayer->splitParts( points(), topologicalEditing );
vlayer->endEditCommand();
if ( returnCode == 4 )
if ( returnCode == QgsGeometry::OperationResult::NothingHappened )
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "No parts were split" ),
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." ),
QgsMessageBar::WARNING,
QgisApp::instance()->messageTimeout() );
}
else if ( returnCode == 3 )
else if ( returnCode == QgsGeometry::OperationResult::GeometryEngineError )
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "No part split done" ),
tr( "Cut edges detected. Make sure the line splits parts into multiple parts." ),
QgsMessageBar::WARNING,
QgisApp::instance()->messageTimeout() );
}
else if ( returnCode == 7 )
else if ( returnCode == QgsGeometry::OperationResult::InvalidBaseGeometry )
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "No part split done" ),
tr( "The geometry is invalid. Please repair before trying to split it." ),
QgsMessageBar::WARNING,
QgisApp::instance()->messageTimeout() );
}
else if ( returnCode != 0 )
else if ( returnCode != QgsGeometry::OperationResult::Success )
{
//several intersections but only one split (most likely line)
QgisApp::instance()->messageBar()->pushMessage(
@@ -625,7 +625,7 @@ QgsGeometry::OperationResult QgsGeometry::addRing( QgsCurve *ring )
std::unique_ptr< QgsCurve > r( ring );
if ( !d->geometry )
{
return InvalidInput;
return InvalidInputGeometryType;
}

detach();
@@ -816,7 +816,7 @@ QgsGeometry::OperationResult QgsGeometry::splitGeometry( const QVector<QgsPointX
case QgsGeometryEngine::InvalidBaseGeometry:
return QgsGeometry::InvalidBaseGeometry;
case QgsGeometryEngine::InvalidInput:
return QgsGeometry::InvalidInput;
return QgsGeometry::InvalidInputGeometryType;
case QgsGeometryEngine::SplitCannotSplitPoint:
return QgsGeometry::SplitCannotSplitPoint;
case QgsGeometryEngine::NothingHappened:
@@ -857,7 +857,7 @@ QgsGeometry::OperationResult QgsGeometry::reshapeGeometry( const QgsLineString &
case QgsGeometryEngine::InvalidBaseGeometry:
return InvalidBaseGeometry;
case QgsGeometryEngine::InvalidInput:
return InvalidInput;
return InvalidInputGeometryType;
case QgsGeometryEngine::SplitCannotSplitPoint: // should not happen
return GeometryEngineError;
case QgsGeometryEngine::NothingHappened:
@@ -121,8 +121,11 @@ class CORE_EXPORT QgsGeometry
Success = 0, //!< Operation succeeded
NothingHappened = 1000, //!< Nothing happened, without any error
InvalidBaseGeometry, //!< The base geometry on which the operation is done is invalid or empty
InvalidInput, //!< The input geometry (ring, part, split line, etc.) has not the correct geometry type
InvalidInputGeometryType, //!< The input geometry (ring, part, split line, etc.) has not the correct geometry type
SelectionIsEmpty, //!< No features were selected
SelectionIsGreaterThanOne, //!< More than one features were selected
GeometryEngineError, //!< Geometry engine misses a method implemented or an error occurred in the geometry engine
LayerNotEditable, //!< Cannot edit layer
/* Add part issues */
AddPartSelectedGeometryNotFound, //!< The selected geometry cannot be found
AddPartNotMultiGeometry, //!< The source geometry is not multi
@@ -30,7 +30,7 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addRing( QgsAbstractGeometry
{
if ( !ring )
{
return QgsGeometry::InvalidInput;
return QgsGeometry::InvalidInputGeometryType;
}

QVector< QgsCurvePolygon * > polygonList;
@@ -50,7 +50,7 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addRing( QgsAbstractGeometry
}
else
{
return QgsGeometry::InvalidInput; //not polygon / multipolygon;
return QgsGeometry::InvalidInputGeometryType; //not polygon / multipolygon;
}

//ring must be closed
@@ -104,7 +104,7 @@ QgsGeometry::OperationResult QgsGeometryEditUtils::addPart( QgsAbstractGeometry

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

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

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

0 comments on commit def85fa

Please sign in to comment.
You can’t perform that action at this time.