@@ -1903,6 +1903,10 @@ void QgisApp::setupConnections()
1903
1903
connect ( mRenderSuppressionCBox , SIGNAL ( toggled ( bool ) ),
1904
1904
mMapCanvas , SLOT ( setRenderFlag ( bool ) ) );
1905
1905
1906
+ // connect MapCanvas keyPress event so we can check if selected feature collection must be deleted
1907
+ connect ( mMapCanvas , SIGNAL ( keyPressed ( QKeyEvent * ) ),
1908
+ this , SLOT ( mapCanvas_keyPressed ( QKeyEvent * ) ) );
1909
+
1906
1910
// connect renderer
1907
1911
connect ( mMapCanvas ->mapRenderer (), SIGNAL ( drawingProgress ( int , int ) ),
1908
1912
this , SLOT ( showProgress ( int , int ) ) );
@@ -4800,7 +4804,7 @@ void QgisApp::layerProperties()
4800
4804
showLayerProperties ( activeLayer () );
4801
4805
}
4802
4806
4803
- void QgisApp::deleteSelected ( QgsMapLayer *layer, QWidget* parent )
4807
+ void QgisApp::deleteSelected ( QgsMapLayer *layer, QWidget* parent, bool promptConfirmation )
4804
4808
{
4805
4809
if ( !layer )
4806
4810
{
@@ -4845,9 +4849,17 @@ void QgisApp::deleteSelected( QgsMapLayer *layer, QWidget* parent )
4845
4849
return ;
4846
4850
}
4847
4851
4848
- // display a warning
4852
+ // validate selection
4849
4853
int numberOfDeletedFeatures = vlayer->selectedFeaturesIds ().size ();
4850
- if ( QMessageBox::warning ( parent, tr ( " Delete features" ), tr ( " Delete %n feature(s)?" , " number of features to delete" , numberOfDeletedFeatures ), QMessageBox::Ok, QMessageBox::Cancel ) == QMessageBox::Cancel )
4854
+ if ( numberOfDeletedFeatures == 0 )
4855
+ {
4856
+ messageBar ()->pushMessage ( tr ( " No Features Selected" ),
4857
+ tr ( " The current layer has not selected features" ),
4858
+ QgsMessageBar::INFO, messageTimeout () );
4859
+ return ;
4860
+ }
4861
+ // display a warning
4862
+ if ( promptConfirmation && QMessageBox::warning ( parent, tr ( " Delete features" ), tr ( " Delete %n feature(s)?" , " number of features to delete" , numberOfDeletedFeatures ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
4851
4863
{
4852
4864
return ;
4853
4865
}
@@ -4859,6 +4871,10 @@ void QgisApp::deleteSelected( QgsMapLayer *layer, QWidget* parent )
4859
4871
tr ( " A problem occured during deletion of features" ),
4860
4872
QgsMessageBar::WARNING );
4861
4873
}
4874
+ else
4875
+ {
4876
+ showStatusMessage ( tr ( " %n feature(s) deleted." , " number of features deleted" , numberOfDeletedFeatures ) );
4877
+ }
4862
4878
4863
4879
vlayer->endEditCommand ();
4864
4880
}
@@ -6477,7 +6493,7 @@ void QgisApp::removeAllLayers()
6477
6493
QgsMapLayerRegistry::instance ()->removeAllMapLayers ();
6478
6494
}
6479
6495
6480
- void QgisApp::removeLayer ()
6496
+ void QgisApp::removeLayer ( bool promptConfirmation )
6481
6497
{
6482
6498
if ( mMapCanvas && mMapCanvas ->isDrawing () )
6483
6499
{
@@ -6496,8 +6512,25 @@ void QgisApp::removeLayer()
6496
6512
return ;
6497
6513
}
6498
6514
6515
+ // validate selection
6516
+ int numberOfRemovedLayers = mMapLegend ->selectedLayers ().size ();
6517
+ if ( numberOfRemovedLayers == 0 )
6518
+ {
6519
+ messageBar ()->pushMessage ( tr ( " No Layer Selected" ),
6520
+ tr ( " To remove layers, you must select they in the legend" ),
6521
+ QgsMessageBar::INFO, messageTimeout () );
6522
+ return ;
6523
+ }
6524
+ // display a warning
6525
+ if ( promptConfirmation && QMessageBox::warning ( this , tr ( " Remove layers" ), tr ( " Remove %n layer(s)?" , " number of layers to remove" , numberOfRemovedLayers ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
6526
+ {
6527
+ return ;
6528
+ }
6529
+
6499
6530
mMapLegend ->removeSelectedLayers ();
6500
6531
6532
+ showStatusMessage ( tr ( " %n layer(s) removed." , " number of layers removed" , numberOfRemovedLayers ) );
6533
+
6501
6534
mMapCanvas ->refresh ();
6502
6535
}
6503
6536
@@ -9061,6 +9094,15 @@ void QgisApp::keyPressEvent( QKeyEvent * e )
9061
9094
}
9062
9095
}
9063
9096
9097
+ void QgisApp::mapCanvas_keyPressed ( QKeyEvent *e )
9098
+ {
9099
+ // Delete selected features when it is possible and KeyEvent was not managed by current MapTool
9100
+ if ( ( e->key () == Qt::Key_Backspace || e->key () == Qt::Key_Delete ) && e->isAccepted () )
9101
+ {
9102
+ deleteSelected ();
9103
+ }
9104
+ }
9105
+
9064
9106
#ifdef Q_OS_WIN
9065
9107
// hope your wearing your peril sensitive sunglasses.
9066
9108
void QgisApp::contextMenuEvent ( QContextMenuEvent *e )
0 commit comments