Skip to content

Commit

Permalink
manage new geom compatibility check when changeGeometry
Browse files Browse the repository at this point in the history
  • Loading branch information
luipir committed Sep 26, 2017
1 parent 101c5cc commit 7012c12
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 23 deletions.
7 changes: 6 additions & 1 deletion src/app/qgsfieldcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,12 @@ void QgsFieldCalculator::accept()
if ( value.canConvert< QgsGeometry >() )
{
QgsGeometry geom = value.value< QgsGeometry >();
mVectorLayer->changeGeometry( feature.id(), &geom );
if ( !mVectorLayer->changeGeometry( feature.id(), &geom ) )
{
calculationSuccess = false;
error = tr( "Invalid edit operation see the log for more info" );
break;
}
}
}
else
Expand Down
6 changes: 5 additions & 1 deletion src/app/qgsmaptooldeletepart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ void QgsMapToolDeletePart::canvasReleaseEvent( QgsMapMouseEvent* e )
if ( g->deletePart( mPressedPartNum ) )
{
vlayer->beginEditCommand( tr( "Part of multipart feature deleted" ) );
vlayer->changeGeometry( f.id(), g );
if ( !vlayer->changeGeometry( f.id(), g ) )
{
emit messageEmitted( tr( "Invalid edit operation see the log for more info" ) );
vlayer->destroyEditCommand();
}
vlayer->endEditCommand();
vlayer->triggerRepaint();
}
Expand Down
7 changes: 6 additions & 1 deletion src/app/qgsmaptooldeletering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ void QgsMapToolDeleteRing::canvasReleaseEvent( QgsMapMouseEvent* e )
if ( g->deleteRing( mPressedRingNum, mPressedPartNum ) )
{
vlayer->beginEditCommand( tr( "Ring deleted" ) );
vlayer->changeGeometry( mPressedFid, g );
if ( !vlayer->changeGeometry( mPressedFid, g ) )
{
emit messageEmitted( tr( "Invalid edit operation see the log for more info" ) );
vlayer->destroyEditCommand();
return;
}
vlayer->endEditCommand();
vlayer->triggerRepaint();
}
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmaptooloffsetcurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void QgsMapToolOffsetCurve::applyOffset()
}
else
{
emit messageEmitted( tr( "Invalid edit operation see the log for more info" ) );
layer->destroyEditCommand();
}

Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmaptoolreshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void QgsMapToolReshape::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
}
else
{
emit messageEmitted( tr( "Invalid edit operation see the log for more info" ) );
vlayer->destroyEditCommand();
}

Expand Down
22 changes: 18 additions & 4 deletions src/app/qgsmaptoolsimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,31 @@ void QgsMapToolSimplify::storeSimplified()
double layerTolerance = QgsTolerance::toleranceInMapUnits( mTolerance, vlayer, mCanvas->mapSettings(), mToleranceUnits );

vlayer->beginEditCommand( tr( "Geometry simplified" ) );
bool success = true;
Q_FOREACH ( const QgsFeature& feat, mSelectedFeatures )
{
if ( QgsGeometry* g = feat.constGeometry()->simplify( layerTolerance ) )
{
vlayer->changeGeometry( feat.id(), g );
if ( !vlayer->changeGeometry( feat.id(), g ) )
{
emit messageEmitted( tr( "Invalid edit operation see the log for more info" ) );
success = false;
}
delete g;

if ( !success )
break;
}
}
vlayer->endEditCommand();

clearSelection();
if ( success )
{
vlayer->endEditCommand();
clearSelection();
}
else
{
vlayer->destroyEditCommand();
}

vlayer->triggerRepaint();
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsofflineediting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,8 @@ void QgsOfflineEditing::applyGeometryChanges( QgsVectorLayer* remoteLayer, sqlit
for ( int i = 0; i < values.size(); i++ )
{
QgsFeatureId fid = remoteFid( db, layerId, values.at( i ).fid );
// TODO: check if changeGeometry success and find a way to
// interrupt applyGeometryChanges if it fail
remoteLayer->changeGeometry( fid, QgsGeometry::fromWkt( values.at( i ).geom_wkt ) );

emit progressUpdated( i + 1 );
Expand Down
40 changes: 24 additions & 16 deletions src/core/qgsvectorlayereditutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ bool QgsVectorLayerEditUtils::insertVertex( double x, double y, QgsFeatureId atF

geometry.insertVertex( x, y, beforeVertex );

L->editBuffer()->changeGeometry( atFeatureId, &geometry );
return true;
return L->editBuffer()->changeGeometry( atFeatureId, &geometry );
}


Expand Down Expand Up @@ -79,8 +78,7 @@ bool QgsVectorLayerEditUtils::moveVertex( const QgsPointV2& p, QgsFeatureId atFe

geometry.moveVertex( p, atVertex );

L->editBuffer()->changeGeometry( atFeatureId, &geometry );
return true;
return L->editBuffer()->changeGeometry( atFeatureId, &geometry );
}


Expand Down Expand Up @@ -115,7 +113,9 @@ QgsVectorLayer::EditResult QgsVectorLayerEditUtils::deleteVertexV2( QgsFeatureId
geometry.setGeometry( nullptr );
}

L->editBuffer()->changeGeometry( featureId, &geometry );
if ( !L->editBuffer()->changeGeometry( featureId, &geometry ) )
return QgsVectorLayer::EditFailed;

return !geometry.isEmpty() ? QgsVectorLayer::Success : QgsVectorLayer::EmptyGeometry;
}

Expand Down Expand Up @@ -166,7 +166,11 @@ int QgsVectorLayerEditUtils::addRing( QgsCurveV2* ring, const QgsFeatureIds& tar
addRingReturnCode = f.geometry()->addRing( static_cast< QgsCurveV2* >( ring->clone() ) );
if ( addRingReturnCode == 0 )
{
L->editBuffer()->changeGeometry( f.id(), f.geometry() );
if ( !L->editBuffer()->changeGeometry( f.id(), f.geometry() ) )
{
addRingReturnCode = 5;
break;
}
if ( modifiedFeatureId )
*modifiedFeatureId = f.id();

Expand Down Expand Up @@ -223,7 +227,8 @@ int QgsVectorLayerEditUtils::addPart( const QgsPointSequenceV2 &points, QgsFeatu
//convert back to single part if required by layer
geometry.convertToSingleType();
}
L->editBuffer()->changeGeometry( featureId, &geometry );
if ( !L->editBuffer()->changeGeometry( featureId, &geometry ) )
errorCode = 2; // ring is not a valid geometry
}
return errorCode;
}
Expand Down Expand Up @@ -262,7 +267,8 @@ int QgsVectorLayerEditUtils::addPart( QgsCurveV2* ring, QgsFeatureId featureId )
//convert back to single part if required by layer
geometry.convertToSingleType();
}
L->editBuffer()->changeGeometry( featureId, &geometry );
if ( !L->editBuffer()->changeGeometry( featureId, &geometry ) )
errorCode = 2; // ring is not a valid geometry
}
return errorCode;
}
Expand All @@ -287,7 +293,8 @@ int QgsVectorLayerEditUtils::translateFeature( QgsFeatureId featureId, double dx
int errorCode = geometry.translate( dx, dy );
if ( errorCode == 0 )
{
L->editBuffer()->changeGeometry( featureId, &geometry );
if ( !L->editBuffer()->changeGeometry( featureId, &geometry ) )
errorCode = 1;
}
return errorCode;
}
Expand Down Expand Up @@ -369,7 +376,8 @@ int QgsVectorLayerEditUtils::splitFeatures( const QList<QgsPoint>& splitLine, bo
if ( splitFunctionReturn == 0 )
{
//change this geometry
L->editBuffer()->changeGeometry( feat.id(), feat.geometry() );
if ( !L->editBuffer()->changeGeometry( feat.id(), feat.geometry() ) )
continue;

//insert new features
for ( int i = 0; i < newGeometries.size(); ++i )
Expand Down Expand Up @@ -513,11 +521,7 @@ int QgsVectorLayerEditUtils::splitParts( const QList<QgsPoint>& splitLine, bool
// For test only: Exception already thrown here...
// feat.geometry()->asWkb();

if ( !addPartRet )
{
L->editBuffer()->changeGeometry( feat.id(), feat.geometry() );
}
else
if ( addPartRet )
{
// Test addPartRet
switch ( addPartRet )
Expand All @@ -535,7 +539,11 @@ int QgsVectorLayerEditUtils::splitParts( const QList<QgsPoint>& splitLine, bool
break;
}
}
L->editBuffer()->changeGeometry( feat.id(), feat.geometry() );
if ( !L->editBuffer()->changeGeometry( feat.id(), feat.geometry() ) )
{
splitFunctionReturn = 2; // value > 1 means no split and error
break;
}

if ( topologicalEditing )
{
Expand Down

0 comments on commit 7012c12

Please sign in to comment.