Skip to content

Commit

Permalink
Add confirmation prompt before deleting PostGIS and Spatialite
Browse files Browse the repository at this point in the history
tables through the browser. Also add confirmation before dropping
connections (fix #12853).

Cherry-picked from aeda955
  • Loading branch information
nyalldawson committed Jun 24, 2015
1 parent 5378f73 commit 4fbda18
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/providers/postgres/qgspostgresdataitems.cpp
Expand Up @@ -123,6 +123,11 @@ void QgsPGConnectionItem::editConnection()

void QgsPGConnectionItem::deleteConnection()
{
if ( QMessageBox::question( 0, QObject::tr( "Delete Connection" ),
QObject::tr( "Are you sure you want to delete the connection to %1?" ).arg( mName ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
return;

QgsPostgresConn::deleteConnection( mName );
// the parent should be updated
if ( mParent )
Expand Down Expand Up @@ -227,7 +232,7 @@ QList<QAction*> QgsPGLayerItem::actions()
{
QList<QAction*> lst;

QAction* actionDeleteLayer = new QAction( tr( "Delete layer" ), this );
QAction* actionDeleteLayer = new QAction( tr( "Delete Layer" ), this );
connect( actionDeleteLayer, SIGNAL( triggered() ), this, SLOT( deleteLayer() ) );
lst.append( actionDeleteLayer );

Expand All @@ -236,15 +241,20 @@ QList<QAction*> QgsPGLayerItem::actions()

void QgsPGLayerItem::deleteLayer()
{
if ( QMessageBox::question( 0, QObject::tr( "Delete Object" ),
QObject::tr( "Are you sure you want to delete %1.%2?" ).arg( mLayerProperty.schemaName ).arg( mLayerProperty.tableName ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
return;

QString errCause;
bool res = ::deleteLayer( mUri, errCause );
if ( !res )
{
QMessageBox::warning( 0, tr( "Delete layer" ), errCause );
QMessageBox::warning( 0, tr( "Delete Layer" ), errCause );
}
else
{
QMessageBox::information( 0, tr( "Delete layer" ), tr( "Layer deleted successfully." ) );
QMessageBox::information( 0, tr( "Delete Layer" ), tr( "Layer deleted successfully." ) );
if ( mParent )
mParent->refresh();
}
Expand Down
16 changes: 13 additions & 3 deletions src/providers/spatialite/qgsspatialitedataitems.cpp
Expand Up @@ -39,7 +39,7 @@ QList<QAction*> QgsSLLayerItem::actions()
{
QList<QAction*> lst;

QAction* actionDeleteLayer = new QAction( tr( "Delete layer" ), this );
QAction* actionDeleteLayer = new QAction( tr( "Delete Layer" ), this );
connect( actionDeleteLayer, SIGNAL( triggered() ), this, SLOT( deleteLayer() ) );
lst.append( actionDeleteLayer );

Expand All @@ -48,16 +48,21 @@ QList<QAction*> QgsSLLayerItem::actions()

void QgsSLLayerItem::deleteLayer()
{
if ( QMessageBox::question( 0, QObject::tr( "Delete Object" ),
QObject::tr( "Are you sure you want to delete %1?" ).arg( mName ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
return;

QgsDataSourceURI uri( mUri );
QString errCause;
bool res = ::deleteLayer( uri.database(), uri.table(), errCause );
if ( !res )
{
QMessageBox::warning( 0, tr( "Delete layer" ), errCause );
QMessageBox::warning( 0, tr( "Delete Layer" ), errCause );
}
else
{
QMessageBox::information( 0, tr( "Delete layer" ), tr( "Layer deleted successfully." ) );
QMessageBox::information( 0, tr( "Delete Layer" ), tr( "Layer deleted successfully." ) );
mParent->refresh();
}
}
Expand Down Expand Up @@ -167,6 +172,11 @@ void QgsSLConnectionItem::editConnection()

void QgsSLConnectionItem::deleteConnection()
{
if ( QMessageBox::question( 0, QObject::tr( "Delete Connection" ),
QObject::tr( "Are you sure you want to delete the connection to %1?" ).arg( mName ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
return;

QgsSpatiaLiteConnection::deleteConnection( mName );
// the parent should be updated
mParent->refresh();
Expand Down

0 comments on commit 4fbda18

Please sign in to comment.