Skip to content
Permalink
Browse files

Merge pull request #5710 from elpaso/api-code-cleaning-int-2-enums

QgsVectorLayer code cleaning use enums instead of int
  • Loading branch information
elpaso committed Nov 24, 2017
2 parents 916c9c4 + 58f5596 commit 72553a60a9fc61cf14c274e76880beb20ff2040d
@@ -2615,6 +2615,10 @@ displayExpression instead. For the map tip use mapTipTemplate() instead.
- setLayerTransparency, layerTransparency, and layerTransparencyChanged were removed. Use opacity, setOpacity and opacityChanged instead.
- The c++ signature for uniqueValues() has changed (the PyQGIS method remains unchanged)
- hasGeometryType() has been removed, replaced by QgsMapLayer::isSpatial()
- addRing() now returns QgsGeometry::OperationResult enum, integer representation of returned values may have changed
- addPart() now returns QgsGeometry::OperationResult enum, integer representation of returned values may have changed
- splitParts() now returns QgsGeometry::OperationResult enum, integer representation of returned values may have changed
- splitFeatured() now returns QgsGeometry::OperationResult enum, integer representation of returned values may have changed


QgsVectorLayerEditBuffer {#qgis_api_break_3_0_QgsVectorLayerEditBuffer}
@@ -52,8 +52,11 @@ class QgsGeometry
Success,
NothingHappened,
InvalidBaseGeometry,
InvalidInput,
InvalidInputGeometryType,
SelectionIsEmpty,
SelectionIsGreaterThanOne,
GeometryEngineError,
LayerNotEditable,
AddPartSelectedGeometryNotFound,
AddPartNotMultiGeometry,
AddRingNotClosed,
@@ -1043,32 +1043,80 @@ Return the provider type for this layer
:rtype: bool
%End

int addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = 0 );
%Docstring
:rtype: int
%End

int addRing( QgsCurve *ring /Transfer/, QgsFeatureId *featureId = 0 ) /PyName=addCurvedRing/;
%Docstring
:rtype: int
%End
QgsGeometry::OperationResult addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = 0 );
%Docstring
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
- Success
- LayerNotEditable
- AddRingNotInExistingFeature
- InvalidInputGeometryType
- AddRingNotClosed
- AddRingNotValid
- AddRingCrossesExistingRings
:rtype: QgsGeometry.OperationResult
%End

QgsGeometry::OperationResult addRing( QgsCurve *ring /Transfer/, QgsFeatureId *featureId = 0 ) /PyName=addCurvedRing/;
%Docstring
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
- Success
- LayerNotEditable
- AddRingNotInExistingFeature
- InvalidInputGeometryType
- AddRingNotClosed
- AddRingNotValid
- AddRingCrossesExistingRings
.. note::

int addPart( const QList<QgsPointXY> &ring );
%Docstring
:rtype: int
%End
available in Python as addCurvedRing
:rtype: QgsGeometry.OperationResult
%End

QgsGeometry::OperationResult addPart( const QList<QgsPointXY> &ring );
%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::

int addPart( const QgsPointSequence &ring ) /PyName=addPartV2/;
%Docstring
:rtype: int
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 +1129,36 @@ Return the provider type for this layer
:rtype: int
%End

int splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
%Docstring
:rtype: int
%End

int splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
%Docstring
:rtype: int
QgsGeometry::OperationResult splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
%Docstring
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
- Success
- NothingHappened
- LayerNotEditable
- InvalidInputGeometryType
- InvalidBaseGeometry
- GeometryEngineError
- SplitCannotSplitPoint
:rtype: QgsGeometry.OperationResult
%End

QgsGeometry::OperationResult splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
%Docstring
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
- Success
- NothingHappened
- LayerNotEditable
- InvalidInputGeometryType
- InvalidBaseGeometry
- GeometryEngineError
- SplitCannotSplitPoint
: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();
@@ -674,7 +674,7 @@ QgsGeometry::OperationResult QgsGeometry::addPart( QgsAbstractGeometry *part, Qg
break;
default:
reset( nullptr );
return QgsGeometry::AddPartNotMultiGeometry;
return QgsGeometry::OperationResult::AddPartNotMultiGeometry;
}
}
else
@@ -785,7 +785,7 @@ QgsGeometry::OperationResult QgsGeometry::splitGeometry( const QVector<QgsPointX
{
if ( !d->geometry )
{
return InvalidBaseGeometry;
return QgsGeometry::OperationResult::InvalidBaseGeometry;
}

QVector<QgsGeometry > newGeoms;
@@ -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::InvalidInput;
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
}

@@ -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

0 comments on commit 72553a6

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