From 013b935c9a28cdcb85ccbba247011c570615a778 Mon Sep 17 00:00:00 2001 From: David Signer Date: Fri, 8 May 2020 07:43:44 +0200 Subject: [PATCH] On delete, checks if there are referncing or joined layers where the delete could have an impact (compositions on relations or cascade delete on joins). This is a general message checking the layer, not checking if the delete of the current feature will have impact. This to avoid long time on a big selection of features. --- python/core/auto_generated/qgsvectorlayerutils.sip.in | 10 ++++++++++ src/app/qgisapp.cpp | 4 ++-- src/app/qgsattributetabledialog.cpp | 4 ++-- src/core/qgsvectorlayerutils.cpp | 2 +- src/core/qgsvectorlayerutils.h | 2 +- src/gui/qgsrelationeditorwidget.cpp | 4 ++-- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/python/core/auto_generated/qgsvectorlayerutils.sip.in b/python/core/auto_generated/qgsvectorlayerutils.sip.in index 3d761707d678..f2e05bdb0aeb 100644 --- a/python/core/auto_generated/qgsvectorlayerutils.sip.in +++ b/python/core/auto_generated/qgsvectorlayerutils.sip.in @@ -296,6 +296,16 @@ The following operations will be performed to convert the input features: .. versionadded:: 3.12 %End + + static bool impactsCascadeFeatures( const QgsVectorLayer *layer, const QgsProject *project ); +%Docstring + +:return: true if the ``is`` connected as parent in at least one composition relation of the ``project`` + or contains joins, where cascade delete is set. + +.. versionadded:: 3.14 +%End + }; diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 7b2c0522622c..dc6379b5a4ea 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -9001,10 +9001,10 @@ void QgisApp::deleteSelected( QgsMapLayer *layer, QWidget *parent, bool checkFea } } - if ( QgsVectorLayerUtils::impactsCascadeFeatures(vlayer, QgsProject::instance() ) ) + if ( QgsVectorLayerUtils::impactsCascadeFeatures( vlayer, QgsProject::instance() ) ) { // for extra safety to make sure we know that the delete can have impact on children and joins - int res = QMessageBox::warning( mMapCanvas, tr( "Possible impact on descendants of layer \"%1\"").arg( vlayer->name() ), + int res = QMessageBox::warning( mMapCanvas, tr( "Possible impact on descendants of layer \"%1\"" ).arg( vlayer->name() ), tr( "A delete on this layer could have an impact on referencing or joined layers and their descendants. Would you still like to continue?" ), QMessageBox::Yes | QMessageBox::No ); if ( res != QMessageBox::Yes ) diff --git a/src/app/qgsattributetabledialog.cpp b/src/app/qgsattributetabledialog.cpp index c089eb565110..711b4bddb129 100644 --- a/src/app/qgsattributetabledialog.cpp +++ b/src/app/qgsattributetabledialog.cpp @@ -864,10 +864,10 @@ void QgsAttributeTableDialog::setFilterExpression( const QString &filterString, void QgsAttributeTableDialog::deleteFeature( const QgsFeatureId fid ) { QgsDebugMsg( QStringLiteral( "Delete %1" ).arg( fid ) ); - if ( QgsVectorLayerUtils::impactsCascadeFeatures(mLayer, QgsProject::instance() ) ) + if ( QgsVectorLayerUtils::impactsCascadeFeatures( mLayer, QgsProject::instance() ) ) { // for extra safety to make sure we know that the delete can have impact on children and joins - int res = QMessageBox::warning( this, tr( "Possible impact on descendants of layer \"%1\"").arg( mLayer->name() ), + int res = QMessageBox::warning( this, tr( "Possible impact on descendants of layer \"%1\"" ).arg( mLayer->name() ), tr( "A delete on this layer could have an impact on referencing or joined layers and their descendants. Would you still like to continue?" ), QMessageBox::Yes | QMessageBox::No ); if ( res != QMessageBox::Yes ) diff --git a/src/core/qgsvectorlayerutils.cpp b/src/core/qgsvectorlayerutils.cpp index 08a221c3431d..7323642529e1 100644 --- a/src/core/qgsvectorlayerutils.cpp +++ b/src/core/qgsvectorlayerutils.cpp @@ -935,7 +935,7 @@ QString QgsVectorLayerUtils::getFeatureDisplayString( const QgsVectorLayer *laye return displayString; } -bool QgsVectorLayerUtils::impactsCascadeFeatures(const QgsVectorLayer *layer, const QgsProject *project) +bool QgsVectorLayerUtils::impactsCascadeFeatures( const QgsVectorLayer *layer, const QgsProject *project ) { if ( !layer ) return false; diff --git a/src/core/qgsvectorlayerutils.h b/src/core/qgsvectorlayerutils.h index 614d20dd3bcd..d626621da37e 100644 --- a/src/core/qgsvectorlayerutils.h +++ b/src/core/qgsvectorlayerutils.h @@ -326,7 +326,7 @@ class CORE_EXPORT QgsVectorLayerUtils * * \since QGIS 3.14 */ - static bool impactsCascadeFeatures(const QgsVectorLayer *layer, const QgsProject *project); + static bool impactsCascadeFeatures( const QgsVectorLayer *layer, const QgsProject *project ); }; diff --git a/src/gui/qgsrelationeditorwidget.cpp b/src/gui/qgsrelationeditorwidget.cpp index 01e7df07964b..e08f7e8fca7a 100644 --- a/src/gui/qgsrelationeditorwidget.cpp +++ b/src/gui/qgsrelationeditorwidget.cpp @@ -728,10 +728,10 @@ void QgsRelationEditorWidget::deleteFeatures( const QgsFeatureIds &featureids ) layer = mRelation.referencingLayer(); } - if ( QgsVectorLayerUtils::impactsCascadeFeatures(layer, QgsProject::instance() ) ) + if ( QgsVectorLayerUtils::impactsCascadeFeatures( layer, QgsProject::instance() ) ) { // for extra safety to make sure we know that the delete can have impact on children and joins - int res = QMessageBox::warning( this, tr( "Possible impact on descendants of layer \"%1\"").arg( layer->name() ), + int res = QMessageBox::warning( this, tr( "Possible impact on descendants of layer \"%1\"" ).arg( layer->name() ), tr( "A delete on this layer could have an impact on referencing or joined layers and their descendants. Would you still like to continue?" ), QMessageBox::Yes | QMessageBox::No ); if ( res == QMessageBox::No )