Skip to content

Commit 9cc2496

Browse files
committedMay 7, 2020
call deleteFeature in deleteFeatures, instead going through the loops in QgsVectorLayerEditBuffer instead to have everything going the same way on the QgsVectorLayer level
and use of private deleteFeature function to avoid multiple remove of selected feature ids and multiple call of updateExtents()
1 parent 9e91eb5 commit 9cc2496

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed
 

‎src/core/qgsvectorlayer.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,7 +3164,7 @@ bool QgsVectorLayer::deleteAttributes( const QList<int> &attrs )
31643164
return deleted;
31653165
}
31663166

3167-
bool QgsVectorLayer::deleteFeature( QgsFeatureId fid )
3167+
bool QgsVectorLayer::deleteFeatureWithDependencies( QgsFeatureId fid )
31683168
{
31693169
if ( !mEditBuffer )
31703170
return false;
@@ -3173,6 +3173,17 @@ bool QgsVectorLayer::deleteFeature( QgsFeatureId fid )
31733173
mJoinBuffer->deleteFeature( fid );
31743174

31753175
bool res = mEditBuffer->deleteFeature( fid );
3176+
3177+
return res;
3178+
}
3179+
3180+
bool QgsVectorLayer::deleteFeature( QgsFeatureId fid )
3181+
{
3182+
if ( !mEditBuffer )
3183+
return false;
3184+
3185+
bool res = deleteFeatureWithDependencies( fid );
3186+
31763187
if ( res )
31773188
{
31783189
mSelectedFeatureIds.remove( fid ); // remove it from selection
@@ -3184,16 +3195,10 @@ bool QgsVectorLayer::deleteFeature( QgsFeatureId fid )
31843195

31853196
bool QgsVectorLayer::deleteFeatures( const QgsFeatureIds &fids )
31863197
{
3187-
if ( !mEditBuffer )
3188-
{
3189-
QgsDebugMsgLevel( QStringLiteral( "Cannot delete features (mEditBuffer==NULL)" ), 1 );
3190-
return false;
3191-
}
3192-
3193-
if ( mJoinBuffer->containsJoins() )
3194-
mJoinBuffer->deleteFeatures( fids );
3195-
3196-
bool res = mEditBuffer->deleteFeatures( fids );
3198+
bool res = true;
3199+
const auto constFids = fids;
3200+
for ( QgsFeatureId fid : constFids )
3201+
res = deleteFeatureWithDependencies( fid ) && res;
31973202

31983203
if ( res )
31993204
{

‎src/core/qgsvectorlayer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
26892689
//! Read simple labeling from layer's custom properties (QGIS 2.x projects)
26902690
QgsAbstractVectorLayerLabeling *readLabelingFromCustomProperties();
26912691

2692+
bool deleteFeatureWithDependencies( QgsFeatureId fid );
2693+
26922694
#ifdef SIP_RUN
26932695
QgsVectorLayer( const QgsVectorLayer &rhs );
26942696
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.