Skip to content

Commit

Permalink
Set delete feature dialog parent. Fixes #5062
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Feb 21, 2012
1 parent 927dcbd commit 083e4c7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/app/qgisapp.cpp
Expand Up @@ -3512,16 +3512,21 @@ void QgisApp::layerProperties()
showLayerProperties( activeLayer() ); showLayerProperties( activeLayer() );
} }


void QgisApp::deleteSelected( QgsMapLayer *layer ) void QgisApp::deleteSelected( QgsMapLayer *layer, QWidget* parent )
{ {
if ( !layer ) if ( !layer )
{ {
layer = mMapLegend->currentLayer(); layer = mMapLegend->currentLayer();
} }


if ( !parent )
{
parent = this;
}

if ( !layer ) if ( !layer )
{ {
QMessageBox::information( this, QMessageBox::information( parent,
tr( "No Layer Selected" ), tr( "No Layer Selected" ),
tr( "To delete features, you must select a vector layer in the legend" ) ); tr( "To delete features, you must select a vector layer in the legend" ) );
return; return;
Expand All @@ -3530,37 +3535,37 @@ void QgisApp::deleteSelected( QgsMapLayer *layer )
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer ); QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer ) if ( !vlayer )
{ {
QMessageBox::information( this, QMessageBox::information( parent,
tr( "No Vector Layer Selected" ), tr( "No Vector Layer Selected" ),
tr( "Deleting features only works on vector layers" ) ); tr( "Deleting features only works on vector layers" ) );
return; return;
} }


if ( !( vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteFeatures ) ) if ( !( vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteFeatures ) )
{ {
QMessageBox::information( this, tr( "Provider does not support deletion" ), QMessageBox::information( parent, tr( "Provider does not support deletion" ),
tr( "Data provider does not support deleting features" ) ); tr( "Data provider does not support deleting features" ) );
return; return;
} }


if ( !vlayer->isEditable() ) if ( !vlayer->isEditable() )
{ {
QMessageBox::information( this, tr( "Layer not editable" ), QMessageBox::information( parent, tr( "Layer not editable" ),
tr( "The current layer is not editable. Choose 'Start editing' in the digitizing toolbar." ) ); tr( "The current layer is not editable. Choose 'Start editing' in the digitizing toolbar." ) );
return; return;
} }


//display a warning //display a warning
int numberOfDeletedFeatures = vlayer->selectedFeaturesIds().size(); int numberOfDeletedFeatures = vlayer->selectedFeaturesIds().size();
if ( QMessageBox::warning( this, tr( "Delete features" ), tr( "Delete %n feature(s)?", "number of features to delete", numberOfDeletedFeatures ), QMessageBox::Ok, QMessageBox::Cancel ) == QMessageBox::Cancel ) if ( QMessageBox::warning( parent, tr( "Delete features" ), tr( "Delete %n feature(s)?", "number of features to delete", numberOfDeletedFeatures ), QMessageBox::Ok, QMessageBox::Cancel ) == QMessageBox::Cancel )
{ {
return; return;
} }


vlayer->beginEditCommand( tr( "Features deleted" ) ); vlayer->beginEditCommand( tr( "Features deleted" ) );
if ( !vlayer->deleteSelectedFeatures() ) if ( !vlayer->deleteSelectedFeatures() )
{ {
QMessageBox::information( this, tr( "Problem deleting features" ), QMessageBox::information( parent, tr( "Problem deleting features" ),
tr( "A problem occured during deletion of features" ) ); tr( "A problem occured during deletion of features" ) );
} }


Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.h
Expand Up @@ -418,7 +418,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
void loadOGRSublayers( QString layertype, QString uri, QStringList list ); void loadOGRSublayers( QString layertype, QString uri, QStringList list );


/**Deletes the selected attributes for the currently selected vector layer*/ /**Deletes the selected attributes for the currently selected vector layer*/
void deleteSelected( QgsMapLayer *layer = 0 ); void deleteSelected( QgsMapLayer *layer = 0, QWidget* parent = 0 );


//! project was written //! project was written
void writeProject( QDomDocument & ); void writeProject( QDomDocument & );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsattributetabledialog.cpp
Expand Up @@ -246,7 +246,7 @@ void QgsAttributeTableDialog::on_mRemoveSelectionButton_clicked()


void QgsAttributeTableDialog::on_mDeleteSelectedButton_clicked() void QgsAttributeTableDialog::on_mDeleteSelectedButton_clicked()
{ {
QgisApp::instance()->deleteSelected( mLayer ); QgisApp::instance()->deleteSelected( mLayer, this );
} }


void QgsAttributeTableDialog::on_cbxShowSelectedOnly_toggled( bool theFlag ) void QgsAttributeTableDialog::on_cbxShowSelectedOnly_toggled( bool theFlag )
Expand Down

0 comments on commit 083e4c7

Please sign in to comment.