QgsVectorLayer code cleaning use enums instead of int

It was one of the TODOs for QGIS 3
This commit is contained in:
Alessandro Pasotti 2017-11-23 12:09:30 +01:00
parent d1cf7e614f
commit def85fa202
12 changed files with 164 additions and 170 deletions

View File

@ -52,8 +52,11 @@ class QgsGeometry
Success,
NothingHappened,
InvalidBaseGeometry,
InvalidInput,
InvalidInputGeometryType,
SelectionIsEmpty,
SelectionIsGreaterThanOne,
GeometryEngineError,
LayerNotEditable,
AddPartSelectedGeometryNotFound,
AddPartNotMultiGeometry,
AddRingNotClosed,

View File

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

View File

@ -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" );
}

View File

@ -93,9 +93,9 @@ 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" ),
@ -103,7 +103,7 @@ void QgsMapToolSplitFeatures::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QgsMessageBar::WARNING,
QgisApp::instance()->messageTimeout() );
}
else if ( returnCode == 3 )
else if ( returnCode == QgsGeometry::OperationResult::GeometryEngineError )
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "No feature split done" ),
@ -111,7 +111,7 @@ void QgsMapToolSplitFeatures::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QgsMessageBar::WARNING,
QgisApp::instance()->messageTimeout() );
}
else if ( returnCode == 7 )
else if ( returnCode == QgsGeometry::OperationResult::InvalidBaseGeometry )
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "No feature split done" ),
@ -119,7 +119,7 @@ void QgsMapToolSplitFeatures::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
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(

View File

@ -91,9 +91,9 @@ 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" ),
@ -101,7 +101,7 @@ void QgsMapToolSplitParts::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QgsMessageBar::WARNING,
QgisApp::instance()->messageTimeout() );
}
else if ( returnCode == 3 )
else if ( returnCode == QgsGeometry::OperationResult::GeometryEngineError )
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "No part split done" ),
@ -109,7 +109,7 @@ void QgsMapToolSplitParts::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QgsMessageBar::WARNING,
QgisApp::instance()->messageTimeout() );
}
else if ( returnCode == 7 )
else if ( returnCode == QgsGeometry::OperationResult::InvalidBaseGeometry )
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "No part split done" ),
@ -117,7 +117,7 @@ void QgsMapToolSplitParts::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
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(

View File

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

View File

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

View File

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

View File

@ -491,7 +491,7 @@ void QgsVectorLayer::modifySelection( const QgsFeatureIds &selectIds, const QgsF
QgsFeatureIds intersectingIds = selectIds & deselectIds;
if ( !intersectingIds.isEmpty() )
{
QgsDebugMsg( "Trying to select and deselect the same item at the same time. Unsure what to do. Selecting dubious items." );
QgsDebugMsgLevel( QStringLiteral( "Trying to select and deselect the same item at the same time. Unsure what to do. Selecting dubious items." ), 3 );
}
mSelectedFeatureIds -= deselectIds;
@ -584,7 +584,7 @@ QgsWkbTypes::GeometryType QgsVectorLayer::geometryType() const
}
else
{
QgsDebugMsg( "invalid layer or pointer to mDataProvider is null" );
QgsDebugMsgLevel( QStringLiteral( "invalid layer or pointer to mDataProvider is null" ), 3 );
}
// We shouldn't get here, and if we have, other things are likely to
@ -592,7 +592,9 @@ QgsWkbTypes::GeometryType QgsVectorLayer::geometryType() const
// rewritten to cope with a value of Qgis::Unknown. To make this
// need known, the following message is printed every time we get
// here.
QgsDebugMsg( "WARNING: This code should never be reached. Problems may occur..." );
// AP: it looks like we almost always get here, since 2.x ... either we remove this
// warning of take care of the problems that may occur
QgsDebugMsg( QStringLiteral( "WARNING: This code should never be reached. Problems may occur..." ) );
return QgsWkbTypes::UnknownGeometry;
}
@ -736,17 +738,17 @@ QgsVectorLayerFeatureCounter *QgsVectorLayer::countSymbolFeatures()
if ( !mValid )
{
QgsDebugMsg( "invoked with invalid layer" );
QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer" ), 3 );
return mFeatureCounter;
}
if ( !mDataProvider )
{
QgsDebugMsg( "invoked with null mDataProvider" );
QgsDebugMsgLevel( QStringLiteral( "invoked with null mDataProvider" ), 3 );
return mFeatureCounter;
}
if ( !mRenderer )
{
QgsDebugMsg( "invoked with null mRenderer" );
QgsDebugMsgLevel( QStringLiteral( "invoked with null mRenderer" ), 3 );
return mFeatureCounter;
}
@ -816,7 +818,7 @@ QgsRectangle QgsVectorLayer::extent() const
QgsRectangle mbr = mDataProvider->extent();
// show the extent
QgsDebugMsg( "Extent of layer: " + mbr.toString() );
QgsDebugMsgLevel( QStringLiteral( "Extent of layer: %1" ).arg( mbr.toString() ), 3 );
// store the extent
mValidExtent = true;
mExtent = mbr;
@ -829,7 +831,7 @@ QgsRectangle QgsVectorLayer::extent() const
if ( !mValid || !mDataProvider )
{
QgsDebugMsg( "invoked with invalid layer or null mDataProvider" );
QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
return rect;
}
@ -899,7 +901,7 @@ QString QgsVectorLayer::subsetString() const
{
if ( !mValid || !mDataProvider )
{
QgsDebugMsg( "invoked with invalid layer or null mDataProvider" );
QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
return QString();
}
return mDataProvider->subsetString();
@ -909,7 +911,7 @@ bool QgsVectorLayer::setSubsetString( const QString &subset )
{
if ( !mValid || !mDataProvider )
{
QgsDebugMsg( "invoked with invalid layer or null mDataProvider" );
QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
return false;
}
@ -977,7 +979,7 @@ bool QgsVectorLayer::updateFeature( const QgsFeature &updatedFeature, bool skipD
QgsFeature currentFeature = getFeature( updatedFeature.id() );
if ( currentFeature.isValid() )
{
QgsDebugMsg( QString( "feature %1 could not be retrieved" ).arg( updatedFeature.id() ) );
QgsDebugMsgLevel( QStringLiteral( "feature %1 could not be retrieved" ).arg( updatedFeature.id() ), 3 );
if ( updatedFeature.hasGeometry() && currentFeature.hasGeometry() && !updatedFeature.geometry().isGeosEqual( currentFeature.geometry() ) )
{
@ -987,7 +989,7 @@ bool QgsVectorLayer::updateFeature( const QgsFeature &updatedFeature, bool skipD
}
else
{
QgsDebugMsg( QString( "geometry of feature %1 could not be changed." ).arg( updatedFeature.id() ) );
QgsDebugMsgLevel( QStringLiteral( "geometry of feature %1 could not be changed." ).arg( updatedFeature.id() ), 3 );
}
}
@ -1004,7 +1006,7 @@ bool QgsVectorLayer::updateFeature( const QgsFeature &updatedFeature, bool skipD
}
else
{
QgsDebugMsg( QString( "attribute %1 of feature %2 could not be changed." ).arg( attr ).arg( updatedFeature.id() ) );
QgsDebugMsgLevel( QStringLiteral( "attribute %1 of feature %2 could not be changed." ).arg( attr ).arg( updatedFeature.id() ), 3 );
hasError = true;
}
}
@ -1116,13 +1118,13 @@ bool QgsVectorLayer::deleteSelectedFeatures( int *deletedCount )
return deleted == count;
}
int QgsVectorLayer::addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId )
QgsGeometry::OperationResult QgsVectorLayer::addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
return 6;
return QgsGeometry::OperationResult::LayerNotEditable;
QgsVectorLayerEditUtils utils( this );
int result = 5;
QgsGeometry::OperationResult result = QgsGeometry::OperationResult::AddRingNotInExistingFeature;
//first try with selected features
if ( !mSelectedFeatureIds.isEmpty() )
@ -1130,7 +1132,7 @@ int QgsVectorLayer::addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *feat
result = utils.addRing( ring, mSelectedFeatureIds, featureId );
}
if ( result != 0 )
if ( result != QgsGeometry::OperationResult::Success )
{
//try with all intersecting features
result = utils.addRing( ring, QgsFeatureIds(), featureId );
@ -1139,27 +1141,27 @@ int QgsVectorLayer::addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *feat
return result;
}
int QgsVectorLayer::addRing( QgsCurve *ring, QgsFeatureId *featureId )
QgsGeometry::OperationResult QgsVectorLayer::addRing( QgsCurve *ring, QgsFeatureId *featureId )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
{
delete ring;
return 6;
return QgsGeometry::OperationResult::LayerNotEditable;
}
if ( !ring )
{
return 1;
return QgsGeometry::OperationResult::InvalidInputGeometryType;
}
if ( !ring->isClosed() )
{
delete ring;
return 2;
return QgsGeometry::OperationResult::AddRingNotClosed;
}
QgsVectorLayerEditUtils utils( this );
int result = 5;
QgsGeometry::OperationResult result = QgsGeometry::OperationResult::AddRingNotInExistingFeature;
//first try with selected features
if ( !mSelectedFeatureIds.isEmpty() )
@ -1167,7 +1169,7 @@ int QgsVectorLayer::addRing( QgsCurve *ring, QgsFeatureId *featureId )
result = utils.addRing( static_cast< QgsCurve * >( ring->clone() ), mSelectedFeatureIds, featureId );
}
if ( result != 0 )
if ( result != QgsGeometry::OperationResult::Success )
{
//try with all intersecting features
result = utils.addRing( static_cast< QgsCurve * >( ring->clone() ), QgsFeatureIds(), featureId );
@ -1177,80 +1179,80 @@ int QgsVectorLayer::addRing( QgsCurve *ring, QgsFeatureId *featureId )
return result;
}
int QgsVectorLayer::addPart( const QList<QgsPointXY> &points )
QgsGeometry::OperationResult QgsVectorLayer::addPart( const QList<QgsPointXY> &points )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
return 7;
return QgsGeometry::OperationResult::LayerNotEditable;
//number of selected features must be 1
if ( mSelectedFeatureIds.empty() )
{
QgsDebugMsg( "Number of selected features <1" );
return 4;
QgsDebugMsgLevel( "Number of selected features < 1", 3 );
return QgsGeometry::OperationResult::SelectionIsEmpty;
}
else if ( mSelectedFeatureIds.size() > 1 )
{
QgsDebugMsg( "Number of selected features >1" );
return 5;
QgsDebugMsgLevel( "Number of selected features > 1", 3 );
return QgsGeometry::OperationResult::SelectionIsGreaterThanOne;
}
QgsVectorLayerEditUtils utils( this );
int result = utils.addPart( points, *mSelectedFeatureIds.constBegin() );
QgsGeometry::OperationResult result = utils.addPart( points, *mSelectedFeatureIds.constBegin() );
if ( result == 0 )
if ( result == QgsGeometry::OperationResult::Success )
updateExtents();
return result;
}
int QgsVectorLayer::addPart( const QgsPointSequence &points )
QgsGeometry::OperationResult QgsVectorLayer::addPart( const QgsPointSequence &points )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
return 7;
return QgsGeometry::OperationResult::LayerNotEditable;
//number of selected features must be 1
if ( mSelectedFeatureIds.empty() )
{
QgsDebugMsg( "Number of selected features <1" );
return 4;
QgsDebugMsgLevel( "Number of selected features <1", 3 );
return QgsGeometry::OperationResult::SelectionIsEmpty;
}
else if ( mSelectedFeatureIds.size() > 1 )
{
QgsDebugMsg( "Number of selected features >1" );
return 5;
QgsDebugMsgLevel( "Number of selected features >1", 3 );
return QgsGeometry::OperationResult::SelectionIsGreaterThanOne;
}
QgsVectorLayerEditUtils utils( this );
int result = utils.addPart( points, *mSelectedFeatureIds.constBegin() );
QgsGeometry::OperationResult result = utils.addPart( points, *mSelectedFeatureIds.constBegin() );
if ( result == 0 )
if ( result == QgsGeometry::OperationResult::Success )
updateExtents();
return result;
}
int QgsVectorLayer::addPart( QgsCurve *ring )
QgsGeometry::OperationResult QgsVectorLayer::addPart( QgsCurve *ring )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
return 7;
return QgsGeometry::OperationResult::LayerNotEditable;
//number of selected features must be 1
if ( mSelectedFeatureIds.empty() )
{
QgsDebugMsg( "Number of selected features <1" );
return 4;
QgsDebugMsgLevel( "Number of selected features <1", 3 );
return QgsGeometry::OperationResult::SelectionIsEmpty;
}
else if ( mSelectedFeatureIds.size() > 1 )
{
QgsDebugMsg( "Number of selected features >1" );
return 5;
QgsDebugMsgLevel( "Number of selected features >1", 3 );
return QgsGeometry::OperationResult::SelectionIsGreaterThanOne;
}
QgsVectorLayerEditUtils utils( this );
int result = utils.addPart( ring, *mSelectedFeatureIds.constBegin() );
QgsGeometry::OperationResult result = utils.addPart( ring, *mSelectedFeatureIds.constBegin() );
if ( result == 0 )
if ( result == QgsGeometry::OperationResult::Success )
updateExtents();
return result;
}
@ -1258,29 +1260,29 @@ int QgsVectorLayer::addPart( QgsCurve *ring )
int QgsVectorLayer::translateFeature( QgsFeatureId featureId, double dx, double dy )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
return -1;
return QgsGeometry::OperationResult::LayerNotEditable;
QgsVectorLayerEditUtils utils( this );
int result = utils.translateFeature( featureId, dx, dy );
if ( result == 0 )
if ( result == QgsGeometry::OperationResult::Success )
updateExtents();
return result;
}
int QgsVectorLayer::splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing )
QgsGeometry::OperationResult QgsVectorLayer::splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
return -1;
return QgsGeometry::OperationResult::LayerNotEditable;
QgsVectorLayerEditUtils utils( this );
return utils.splitParts( splitLine, topologicalEditing );
}
int QgsVectorLayer::splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing )
QgsGeometry::OperationResult QgsVectorLayer::splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
return -1;
return QgsGeometry::OperationResult::LayerNotEditable;
QgsVectorLayerEditUtils utils( this );
return utils.splitFeatures( splitLine, topologicalEditing );
@ -1377,7 +1379,7 @@ bool QgsVectorLayer::startEditing()
bool QgsVectorLayer::readXml( const QDomNode &layer_node, const QgsReadWriteContext &context )
{
QgsDebugMsg( QString( "Datasource in QgsVectorLayer::readXml: " ) + mDataSource.toLocal8Bit().data() );
QgsDebugMsgLevel( QStringLiteral( "Datasource in QgsVectorLayer::readXml: %1" ).arg( mDataSource.toLocal8Bit().data() ), 3 );
//process provider key
QDomNode pkeyNode = layer_node.namedItem( QStringLiteral( "provider" ) );
@ -1532,18 +1534,18 @@ bool QgsVectorLayer::setDataProvider( QString const &provider )
mDataProvider = qobject_cast<QgsVectorDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource ) );
if ( !mDataProvider )
{
QgsDebugMsg( " unable to get data provider" );
QgsDebugMsgLevel( QStringLiteral( "Unable to get data provider" ), 2 );
return false;
}
connect( mDataProvider, &QgsVectorDataProvider::raiseError, this, &QgsVectorLayer::raiseError );
QgsDebugMsgLevel( "Instantiated the data provider plugin", 4 );
QgsDebugMsgLevel( QStringLiteral( "Instantiated the data provider plugin" ), 2 );
mValid = mDataProvider->isValid();
if ( !mValid )
{
QgsDebugMsg( "Invalid provider plugin " + QString( mDataSource.toUtf8() ) );
QgsDebugMsgLevel( QStringLiteral( "Invalid provider plugin %1" ).arg( QString( mDataSource.toUtf8() ) ), 2 );
return false;
}
@ -1558,7 +1560,7 @@ bool QgsVectorLayer::setDataProvider( QString const &provider )
if ( mProviderKey == QLatin1String( "postgres" ) )
{
QgsDebugMsg( "Beautifying layer name " + name() );
QgsDebugMsgLevel( QStringLiteral( "Beautifying layer name %1" ).arg( name() ), 3 );
// adjust the display name for postgres layers
QRegExp reg( R"lit("[^"]+"\."([^"] + )"( \([^)]+\))?)lit" );
@ -1582,7 +1584,7 @@ bool QgsVectorLayer::setDataProvider( QString const &provider )
setName( lName );
}
QgsDebugMsg( "Beautified layer name " + name() );
QgsDebugMsgLevel( QStringLiteral( "Beautified layer name %1" ).arg( name() ), 3 );
// deal with unnecessary schema qualification to make v.in.ogr happy
// and remove unnecessary key
@ -1629,7 +1631,7 @@ bool QgsVectorLayer::writeXml( QDomNode &layer_node,
if ( mapLayerNode.isNull() || ( "maplayer" != mapLayerNode.nodeName() ) )
{
QgsDebugMsg( "can't find <maplayer>" );
QgsDebugMsgLevel( QStringLiteral( "can't find <maplayer>" ), 2 );
return false;
}
@ -2520,7 +2522,7 @@ bool QgsVectorLayer::deleteFeatures( const QgsFeatureIds &fids )
{
if ( !mEditBuffer )
{
QgsDebugMsg( "Cannot delete features (mEditBuffer==NULL)" );
QgsDebugMsgLevel( QStringLiteral( "Cannot delete features (mEditBuffer==NULL)" ), 1 );
return false;
}
@ -2717,12 +2719,7 @@ bool QgsVectorLayer::addFeatures( QgsFeatureList &features, Flags )
void QgsVectorLayer::setCoordinateSystem()
{
QgsDebugMsgLevel( "----- Computing Coordinate System", 4 );
//
// Get the layers project info and set up the QgsCoordinateTransform
// for this layer
//
QgsDebugMsgLevel( QStringLiteral( "Computing Coordinate System" ), 4 );
if ( isSpatial() )
{
@ -3708,14 +3705,14 @@ void QgsVectorLayer::readSldLabeling( const QDomNode &node )
QDomElement userStyleElem = element.firstChildElement( QStringLiteral( "UserStyle" ) );
if ( userStyleElem.isNull() )
{
QgsDebugMsg( "Info: UserStyle element not found." );
QgsDebugMsgLevel( QStringLiteral( "Info: UserStyle element not found." ), 4 );
return;
}
QDomElement featureTypeStyleElem = userStyleElem.firstChildElement( QStringLiteral( "FeatureTypeStyle" ) );
if ( featureTypeStyleElem.isNull() )
{
QgsDebugMsg( "Info: FeatureTypeStyle element not found." );
QgsDebugMsgLevel( QStringLiteral( "Info: FeatureTypeStyle element not found." ), 4 );
return;
}
@ -3723,7 +3720,7 @@ void QgsVectorLayer::readSldLabeling( const QDomNode &node )
QDomElement ruleElem = featureTypeStyleElem.lastChildElement( QStringLiteral( "Rule" ) );
if ( ruleElem.isNull() )
{
QgsDebugMsg( "Info: Rule element not found." );
QgsDebugMsgLevel( QStringLiteral( "Info: Rule element not found." ), 4 );
return;
}
@ -3731,7 +3728,7 @@ void QgsVectorLayer::readSldLabeling( const QDomNode &node )
QDomElement textSymbolizerElem = ruleElem.lastChildElement( QStringLiteral( "TextSymbolizer" ) );
if ( textSymbolizerElem.isNull() )
{
QgsDebugMsg( "Info: TextSymbolizer element not found." );
QgsDebugMsgLevel( QStringLiteral( "Info: TextSymbolizer element not found." ), 4 );
return;
}
@ -3762,19 +3759,19 @@ void QgsVectorLayer::readSldLabeling( const QDomNode &node )
}
else
{
QgsDebugMsg( "SLD label attribute error: " + exp.evalErrorString() );
QgsDebugMsgLevel( QStringLiteral( "SLD label attribute error: %1" ).arg( exp.evalErrorString() ), 3 );
}
}
}
else
{
QgsDebugMsg( "Info: PropertyName element not found." );
QgsDebugMsgLevel( QStringLiteral( "Info: PropertyName element not found." ), 4 );
return;
}
}
else
{
QgsDebugMsg( "Info: Label element not found." );
QgsDebugMsgLevel( QStringLiteral( "Info: Label element not found." ), 4 );
return;
}
@ -4013,7 +4010,7 @@ QString QgsVectorLayer::htmlMetadata() const
QgsWkbTypes::GeometryType type = geometryType();
if ( type < 0 || type > QgsWkbTypes::NullGeometry )
{
QgsDebugMsg( "Invalid vector type" );
QgsDebugMsgLevel( QStringLiteral( "Invalid vector type" ), 2 );
}
else
{

View File

@ -1049,65 +1049,34 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* 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
* \returns
* 0 in case of success,
* 1 problem with feature type,
* 2 ring not closed,
* 3 ring not valid,
* 4 ring crosses existing rings,
* 5 no feature found where ring can be inserted
* 6 layer not editable
* \returns QgsGeometry::OperationResult
*/
// TODO QGIS 3.0 returns an enum instead of a magic constant
int addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = nullptr );
QgsGeometry::OperationResult addRing( const QVector<QgsPointXY> &ring, QgsFeatureId *featureId = nullptr );
/**
* 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
* \returns
* 0 in case of success
* 1 problem with feature type
* 2 ring not closed
* 6 layer not editable
* \returns QgsGeometry::OperationResult
* \note available in Python as addCurvedRing
*/
// TODO QGIS 3.0 returns an enum instead of a magic constant
int addRing( QgsCurve *ring SIP_TRANSFER, QgsFeatureId *featureId = nullptr ) SIP_PYNAME( addCurvedRing );
QgsGeometry::OperationResult addRing( QgsCurve *ring SIP_TRANSFER, QgsFeatureId *featureId = nullptr ) SIP_PYNAME( addCurvedRing );
/**
* Adds a new part polygon to a multipart feature
* \returns
* 0 in case of success,
* 1 if selected feature is not multipart,
* 2 if ring is not a valid geometry,
* 3 if new polygon ring not disjoint with existing rings,
* 4 if no feature was selected,
* 5 if several features are selected,
* 6 if selected geometry not found
* 7 layer not editable
* \returns QgsGeometry::OperationResult
*/
// TODO QGIS 3.0 returns an enum instead of a magic constant
int addPart( const QList<QgsPointXY> &ring );
QgsGeometry::OperationResult addPart( const QList<QgsPointXY> &ring );
/**
* Adds a new part polygon to a multipart feature
* \returns
* 0 in case of success,
* 1 if selected feature is not multipart,
* 2 if ring is not a valid geometry,
* 3 if new polygon ring not disjoint with existing rings,
* 4 if no feature was selected,
* 5 if several features are selected,
* 6 if selected geometry not found
* 7 layer not editable
* \returns QgsGeometry::OperationResult
* \note available in Python bindings as addPartV2
*/
// TODO QGIS 3.0 returns an enum instead of a magic constant
int addPart( const QgsPointSequence &ring ) SIP_PYNAME( addPartV2 );
QgsGeometry::OperationResult addPart( const QgsPointSequence &ring ) SIP_PYNAME( addPartV2 );
//! \note available in Python as addCurvedPart
int addPart( QgsCurve *ring SIP_TRANSFER ) SIP_PYNAME( addCurvedPart );
QgsGeometry::OperationResult addPart( QgsCurve *ring SIP_TRANSFER ) SIP_PYNAME( addCurvedPart );
/**
* Translates feature by dx, dy
@ -1122,23 +1091,17 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* Splits parts cut by the given line
* \param splitLine line that splits the layer features
* \param topologicalEditing true if topological editing is enabled
* \returns
* 0 in case of success,
* 4 if there is a selection but no feature split
* \returns QgsGeometry::OperationResult
*/
// TODO QGIS 3.0 returns an enum instead of a magic constant
int splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
QgsGeometry::OperationResult splitParts( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
/**
* Splits features cut by the given line
* \param splitLine line that splits the layer features
* \param topologicalEditing true if topological editing is enabled
* \returns
* 0 in case of success,
* 4 if there is a selection but no feature split
* \returns QgsGeometry::OperationResult
*/
// TODO QGIS 3.0 returns an enum instead of a magic constant
int splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
QgsGeometry::OperationResult splitFeatures( const QVector<QgsPointXY> &splitLine, bool topologicalEditing = false );
/**
* Adds topological points for every vertex of the geometry.

View File

@ -301,7 +301,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitFeatures( const QVect
}
else
{
return QgsGeometry::InvalidInput;
return QgsGeometry::InvalidInputGeometryType;
}
if ( bBox.isEmpty() )
@ -410,7 +410,7 @@ QgsGeometry::OperationResult QgsVectorLayerEditUtils::splitParts( const QVector<
}
else
{
return QgsGeometry::InvalidInput;
return QgsGeometry::InvalidInputGeometryType;
}
if ( bBox.isEmpty() )

Binary file not shown.