Skip to content

Commit

Permalink
Fix incorrect error message in add ring tool
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 3, 2021
1 parent 01e3e1d commit 519bc4e
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions src/app/qgsmaptooladdring.cpp
Expand Up @@ -111,36 +111,43 @@ void QgsMapToolAddRing::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
curveToAdd = captureCurve()->curveToLine();
}

int addRingReturnCode = vlayer->addRing( curveToAdd );
if ( addRingReturnCode != 0 )
Qgis::GeometryOperationResult addRingReturnCode = vlayer->addRing( curveToAdd );
QString errorMessage;
switch ( addRingReturnCode )
{
QString errorMessage;
//todo: open message box to communicate errors
if ( addRingReturnCode == 1 )
{
case Qgis::GeometryOperationResult::Success:
break;
case Qgis::GeometryOperationResult::InvalidInputGeometryType:
errorMessage = tr( "a problem with geometry type occurred" );
}
else if ( addRingReturnCode == 2 )
{
break;
case Qgis::GeometryOperationResult::AddRingNotClosed:
errorMessage = tr( "the inserted ring is not closed" );
}
else if ( addRingReturnCode == 3 )
{
break;
case Qgis::GeometryOperationResult::AddRingNotValid:
errorMessage = tr( "the inserted ring is not a valid geometry" );
}
else if ( addRingReturnCode == 4 )
{
break;
case Qgis::GeometryOperationResult::AddRingCrossesExistingRings:
errorMessage = tr( "the inserted ring crosses existing rings" );
}
else if ( addRingReturnCode == 5 )
{
break;
case Qgis::GeometryOperationResult::AddRingNotInExistingFeature:
errorMessage = tr( "the inserted ring is not contained in a feature" );
}
else
{
errorMessage = tr( "an unknown error occurred" );
}
emit messageEmitted( tr( "Could not add ring since %1." ).arg( errorMessage ), Qgis::MessageLevel::Critical );
break;
case Qgis::GeometryOperationResult::SplitCannotSplitPoint:
case Qgis::GeometryOperationResult::InvalidBaseGeometry:
case Qgis::GeometryOperationResult::NothingHappened:
case Qgis::GeometryOperationResult::SelectionIsEmpty:
case Qgis::GeometryOperationResult::SelectionIsGreaterThanOne:
case Qgis::GeometryOperationResult::GeometryEngineError:
case Qgis::GeometryOperationResult::LayerNotEditable:
case Qgis::GeometryOperationResult::AddPartSelectedGeometryNotFound:
case Qgis::GeometryOperationResult::AddPartNotMultiGeometry:
errorMessage = tr( "an unknown error occurred (%1)" ).arg( qgsEnumValueToKey( addRingReturnCode ) );
break;
}

if ( addRingReturnCode != Qgis::GeometryOperationResult::Success )
{
emit messageEmitted( tr( "Could not add ring: %1." ).arg( errorMessage ), Qgis::MessageLevel::Critical );
vlayer->destroyEditCommand();
}
else
Expand Down

0 comments on commit 519bc4e

Please sign in to comment.