Skip to content

Commit

Permalink
Fix layer extent was not invalidated for certain geometry editing
Browse files Browse the repository at this point in the history
operations (eg move feature, add/delete/move vertex) (fix #14573)

(cherry-picked from 4ece916)
  • Loading branch information
nyalldawson committed Apr 4, 2016
1 parent 8c9255e commit 239a8d6
Showing 1 changed file with 55 additions and 14 deletions.
69 changes: 55 additions & 14 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1004,7 +1004,10 @@ bool QgsVectorLayer::insertVertex( double x, double y, QgsFeatureId atFeatureId,
return false;

QgsVectorLayerEditUtils utils( this );
return utils.insertVertex( x, y, atFeatureId, beforeVertex );
bool result = utils.insertVertex( x, y, atFeatureId, beforeVertex );
if ( result )
updateExtents();
return result;
}


Expand All @@ -1014,7 +1017,11 @@ bool QgsVectorLayer::moveVertex( double x, double y, QgsFeatureId atFeatureId, i
return false;

QgsVectorLayerEditUtils utils( this );
return utils.moveVertex( x, y, atFeatureId, atVertex );
bool result = utils.moveVertex( x, y, atFeatureId, atVertex );

if ( result )
updateExtents();
return result;
}

bool QgsVectorLayer::moveVertex( const QgsPointV2& p, QgsFeatureId atFeatureId, int atVertex )
Expand All @@ -1023,13 +1030,21 @@ bool QgsVectorLayer::moveVertex( const QgsPointV2& p, QgsFeatureId atFeatureId,
return false;

QgsVectorLayerEditUtils utils( this );
return utils.moveVertex( p, atFeatureId, atVertex );
bool result = utils.moveVertex( p, atFeatureId, atVertex );

if ( result )
updateExtents();
return result;
}

bool QgsVectorLayer::deleteVertex( QgsFeatureId atFeatureId, int atVertex )
{
QgsVectorLayer::EditResult res = deleteVertexV2( atFeatureId, atVertex );
return res == QgsVectorLayer::Success || res == QgsVectorLayer::EmptyGeometry;
bool result = ( res == QgsVectorLayer::Success || res == QgsVectorLayer::EmptyGeometry );

if ( result )
updateExtents();
return result;
}

QgsVectorLayer::EditResult QgsVectorLayer::deleteVertexV2( QgsFeatureId featureId, int vertex )
Expand All @@ -1038,7 +1053,11 @@ QgsVectorLayer::EditResult QgsVectorLayer::deleteVertexV2( QgsFeatureId featureI
return QgsVectorLayer::InvalidLayer;

QgsVectorLayerEditUtils utils( this );
return utils.deleteVertexV2( featureId, vertex );
EditResult result = utils.deleteVertexV2( featureId, vertex );

if ( result == Success )
updateExtents();
return result;
}


Expand Down Expand Up @@ -1154,7 +1173,11 @@ int QgsVectorLayer::addPart( const QList<QgsPoint> &points )
}

QgsVectorLayerEditUtils utils( this );
return utils.addPart( points, *mSelectedFeatureIds.constBegin() );
int result = utils.addPart( points, *mSelectedFeatureIds.constBegin() );

if ( result == 0 )
updateExtents();
return result;
}

int QgsVectorLayer::addPart( const QgsPointSequenceV2 &points )
Expand All @@ -1176,7 +1199,11 @@ int QgsVectorLayer::addPart( const QgsPointSequenceV2 &points )
}

QgsVectorLayerEditUtils utils( this );
return utils.addPart( points, *mSelectedFeatureIds.constBegin() );
int result = utils.addPart( points, *mSelectedFeatureIds.constBegin() );

if ( result == 0 )
updateExtents();
return result;
}

int QgsVectorLayer::addPart( QgsCurveV2* ring )
Expand All @@ -1198,7 +1225,11 @@ int QgsVectorLayer::addPart( QgsCurveV2* ring )
}

QgsVectorLayerEditUtils utils( this );
return utils.addPart( ring, *mSelectedFeatureIds.constBegin() );
int result = utils.addPart( ring, *mSelectedFeatureIds.constBegin() );

if ( result == 0 )
updateExtents();
return result;
}

int QgsVectorLayer::translateFeature( QgsFeatureId featureId, double dx, double dy )
Expand All @@ -1207,7 +1238,11 @@ int QgsVectorLayer::translateFeature( QgsFeatureId featureId, double dx, double
return -1;

QgsVectorLayerEditUtils utils( this );
return utils.translateFeature( featureId, dx, dy );
int result = utils.translateFeature( featureId, dx, dy );

if ( result == 0 )
updateExtents();
return result;
}

int QgsVectorLayer::splitParts( const QList<QgsPoint>& splitLine, bool topologicalEditing )
Expand Down Expand Up @@ -2093,7 +2128,11 @@ bool QgsVectorLayer::changeGeometry( QgsFeatureId fid, QgsGeometry* geom )

updateExtents();

return mEditBuffer->changeGeometry( fid, geom );
bool result = mEditBuffer->changeGeometry( fid, geom );

if ( result )
updateExtents();
return result;
}


Expand Down Expand Up @@ -2210,9 +2249,10 @@ bool QgsVectorLayer::deleteFeature( QgsFeatureId fid )

bool res = mEditBuffer->deleteFeature( fid );
if ( res )
{
mSelectedFeatureIds.remove( fid ); // remove it from selection

updateExtents();
updateExtents();
}

return res;
}
Expand All @@ -2225,9 +2265,10 @@ bool QgsVectorLayer::deleteFeatures( const QgsFeatureIds& fids )
bool res = mEditBuffer->deleteFeatures( fids );

if ( res )
{
mSelectedFeatureIds.subtract( fids ); // remove it from selection

updateExtents();
updateExtents();
}

return res;
}
Expand Down

0 comments on commit 239a8d6

Please sign in to comment.