Skip to content

Commit

Permalink
feedback messages on delete cascade
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed May 7, 2020
1 parent 79d8601 commit 73b1b2d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -9012,7 +9012,21 @@ void QgisApp::deleteSelected( QgsMapLayer *layer, QWidget *parent, bool checkFea
}
else
{
showStatusMessage( tr( "%n feature(s) deleted.", "number of features deleted", numberOfSelectedFeatures ) );
//if it effected more than one layer, print feedback for all descendants
if ( context.handledFeatures.count() > 1 )
{
deletedCount = 0;
QString feedbackMessage;
QMap<QgsVectorLayer *, QgsFeatureIds>::const_iterator i;
for ( i = context.handledFeatures.begin(); i != context.handledFeatures.end(); ++i )
{
feedbackMessage += tr( " %1 on layer %2." ).arg( i.value().count() ).arg( i.key()->name() );
deletedCount += i.value().count();
}
visibleMessageBar()->pushMessage( tr( "%1 features deleted: %2" ).arg( deletedCount ).arg( feedbackMessage ), Qgis::Success );
}

showStatusMessage( tr( "%n feature(s) deleted.", "number of features deleted", deletedCount ) );
}

vlayer->endEditCommand();
Expand Down
13 changes: 13 additions & 0 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -866,6 +866,19 @@ void QgsAttributeTableDialog::deleteFeature( const QgsFeatureId fid )
QgsDebugMsg( QStringLiteral( "Delete %1" ).arg( fid ) );
QgsVectorLayer::DeleteContext context { true };
mLayer->deleteFeature( fid, &context );
//if it effected more than one layer, print feedback for all descendants
if ( context.handledFeatures.count() > 1 )
{
int deletedCount = 0;
QString feedbackMessage;
QMap<QgsVectorLayer *, QgsFeatureIds>::const_iterator i;
for ( i = context.handledFeatures.begin(); i != context.handledFeatures.end(); ++i )
{
feedbackMessage += tr( " %1 on layer %2." ).arg( i.value().count() ).arg( i.key()->name() );
deletedCount += i.value().count();
}
QgisApp::instance()->messageBar()->pushMessage( tr( "%1 features deleted: %2" ).arg( deletedCount ).arg( feedbackMessage ), Qgis::Success );
}
}

void QgsAttributeTableDialog::showContextMenu( QgsActionMenu *menu, const QgsFeatureId fid )
Expand Down
8 changes: 5 additions & 3 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -3207,9 +3207,11 @@ bool QgsVectorLayer::deleteFeatureCascade( QgsFeatureId fid, QgsVectorLayer::Del
{
childFeatureIds.insert( childFeature.id() );
}

relation.referencingLayer()->startEditing();
relation.referencingLayer()->deleteFeatures( childFeatureIds, context );
if ( childFeatureIds.count() > 0 )
{
relation.referencingLayer()->startEditing();
relation.referencingLayer()->deleteFeatures( childFeatureIds, context );
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -732,6 +732,18 @@ void QgsRelationEditorWidget::deleteFeatures( const QgsFeatureIds &featureids )
{
QgsVectorLayer::DeleteContext context { true };
layer->deleteFeatures( featureids, &context );
if ( context.handledFeatures.count() > 1 )
{
int deletedCount = 0;
QString feedbackMessage;
QMap<QgsVectorLayer *, QgsFeatureIds>::const_iterator i;
for ( i = context.handledFeatures.begin(); i != context.handledFeatures.end(); ++i )
{
feedbackMessage += tr( " %1 on layer %2." ).arg( i.value().count() ).arg( i.key()->name() );
deletedCount += i.value().count();
}
mEditorContext.mainMessageBar()->pushMessage( tr( "%1 features deleted: %2" ).arg( deletedCount ).arg( feedbackMessage ), Qgis::Success );
}
updateUi();
}
}
Expand Down

0 comments on commit 73b1b2d

Please sign in to comment.