Skip to content
Permalink
Browse files

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.
  • Loading branch information
signedav committed May 8, 2020
1 parent 342521e commit 013b935c9a28cdcb85ccbba247011c570615a778
@@ -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

};


@@ -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 )
@@ -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 )
@@ -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;
@@ -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 );

};

@@ -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 )

0 comments on commit 013b935

Please sign in to comment.
You can’t perform that action at this time.