Skip to content

Commit

Permalink
Implements deleteCascade option
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Aug 28, 2017
1 parent f92c23f commit 293f0f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,9 @@ bool QgsVectorLayer::deleteFeature( QgsFeatureId fid )
if ( !mEditBuffer )
return false;

if ( mJoinBuffer->containsJoins() )
deleteFeaturesFromJoinedLayers( QgsFeatureIds() << fid );

bool res = mEditBuffer->deleteFeature( fid );
if ( res )
{
Expand All @@ -2456,6 +2459,9 @@ bool QgsVectorLayer::deleteFeatures( const QgsFeatureIds &fids )
return false;
}

if ( mJoinBuffer->containsJoins() )
deleteFeaturesFromJoinedLayers( fids );

bool res = mEditBuffer->deleteFeatures( fids );

if ( res )
Expand All @@ -2467,6 +2473,26 @@ bool QgsVectorLayer::deleteFeatures( const QgsFeatureIds &fids )
return res;
}

bool QgsVectorLayer::deleteFeaturesFromJoinedLayers( QgsFeatureIds fids )
{
bool rc = false;

Q_FOREACH ( const QgsFeatureId &fid, fids )
{
Q_FOREACH ( const QgsVectorLayerJoinInfo &info, vectorJoins() )
{
if ( info.isEditable() && info.isDeleteCascade() )
{
QgsFeature joinFeature = mJoinBuffer->joinedFeatureOf( &info, getFeature( fid ) );
if ( joinFeature.isValid() )
info.joinLayer()->deleteFeature( joinFeature.id() );
}
}
}

return rc;
}

QgsAttributeList QgsVectorLayer::pkAttributeList() const
{
QgsAttributeList pkAttributesList;
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
QgsAbstractVectorLayerLabeling *readLabelingFromCustomProperties();

bool addFeaturesToJoinedLayers( QgsFeatureList &features, Flags flags = 0 );
bool deleteFeaturesFromJoinedLayers( QgsFeatureIds fids );

#ifdef SIP_RUN
QgsVectorLayer( const QgsVectorLayer &rhs );
Expand Down

0 comments on commit 293f0f4

Please sign in to comment.