Skip to content
Permalink
Browse files

manage new geom compatibility check when changeGeometry

  • Loading branch information
luipir committed Sep 26, 2017
1 parent 101c5cc commit 7012c1287cb64d846c63eb69230172f823c9b9e1
@@ -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
@@ -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();
}
@@ -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();
}
@@ -183,6 +183,7 @@ void QgsMapToolOffsetCurve::applyOffset()
}
else
{
emit messageEmitted( tr( "Invalid edit operation see the log for more info" ) );
layer->destroyEditCommand();
}

@@ -136,6 +136,7 @@ void QgsMapToolReshape::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
}
else
{
emit messageEmitted( tr( "Invalid edit operation see the log for more info" ) );
vlayer->destroyEditCommand();
}

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


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


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

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

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

0 comments on commit 7012c12

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