Skip to content

Commit

Permalink
On delete, checks if there are referncing or joined layers where the …
Browse files Browse the repository at this point in the history
…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 013b935
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
10 changes: 10 additions & 0 deletions python/core/auto_generated/qgsvectorlayerutils.sip.in
Expand Up @@ -296,6 +296,16 @@ The following operations will be performed to convert the input features:


.. versionadded:: 3.12 .. versionadded:: 3.12
%End %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

}; };




Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -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 // 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?" ), 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 ); QMessageBox::Yes | QMessageBox::No );
if ( res != QMessageBox::Yes ) if ( res != QMessageBox::Yes )
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -864,10 +864,10 @@ void QgsAttributeTableDialog::setFilterExpression( const QString &filterString,
void QgsAttributeTableDialog::deleteFeature( const QgsFeatureId fid ) void QgsAttributeTableDialog::deleteFeature( const QgsFeatureId fid )
{ {
QgsDebugMsg( QStringLiteral( "Delete %1" ).arg( 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 // 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?" ), 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 ); QMessageBox::Yes | QMessageBox::No );
if ( res != QMessageBox::Yes ) if ( res != QMessageBox::Yes )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayerutils.cpp
Expand Up @@ -935,7 +935,7 @@ QString QgsVectorLayerUtils::getFeatureDisplayString( const QgsVectorLayer *laye
return displayString; return displayString;
} }


bool QgsVectorLayerUtils::impactsCascadeFeatures(const QgsVectorLayer *layer, const QgsProject *project) bool QgsVectorLayerUtils::impactsCascadeFeatures( const QgsVectorLayer *layer, const QgsProject *project )
{ {
if ( !layer ) if ( !layer )
return false; return false;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayerutils.h
Expand Up @@ -326,7 +326,7 @@ class CORE_EXPORT QgsVectorLayerUtils
* *
* \since QGIS 3.14 * \since QGIS 3.14
*/ */
static bool impactsCascadeFeatures(const QgsVectorLayer *layer, const QgsProject *project); static bool impactsCascadeFeatures( const QgsVectorLayer *layer, const QgsProject *project );


}; };


Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -728,10 +728,10 @@ void QgsRelationEditorWidget::deleteFeatures( const QgsFeatureIds &featureids )
layer = mRelation.referencingLayer(); 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 // 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?" ), 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 ); QMessageBox::Yes | QMessageBox::No );
if ( res == QMessageBox::No ) if ( res == QMessageBox::No )
Expand Down

0 comments on commit 013b935

Please sign in to comment.