Skip to content

Commit aeda955

Browse files
committed
Add confirmation prompt before deleting PostGIS and Spatialite
tables through the browser. Also add confirmation before dropping connections (fix #12853).
1 parent aa6db0e commit aeda955

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/providers/postgres/qgspostgresdataitems.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ void QgsPGConnectionItem::editConnection()
123123

124124
void QgsPGConnectionItem::deleteConnection()
125125
{
126+
if ( QMessageBox::question( 0, QObject::tr( "Delete Connection" ),
127+
QObject::tr( "Are you sure you want to delete the connection to %1?" ).arg( mName ),
128+
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
129+
return;
130+
126131
QgsPostgresConn::deleteConnection( mName );
127132
// the parent should be updated
128133
if ( mParent )
@@ -227,7 +232,7 @@ QList<QAction*> QgsPGLayerItem::actions()
227232
{
228233
QList<QAction*> lst;
229234

230-
QAction* actionDeleteLayer = new QAction( tr( "Delete layer" ), this );
235+
QAction* actionDeleteLayer = new QAction( tr( "Delete Layer" ), this );
231236
connect( actionDeleteLayer, SIGNAL( triggered() ), this, SLOT( deleteLayer() ) );
232237
lst.append( actionDeleteLayer );
233238

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

237242
void QgsPGLayerItem::deleteLayer()
238243
{
244+
if ( QMessageBox::question( 0, QObject::tr( "Delete Object" ),
245+
QObject::tr( "Are you sure you want to delete %1.%2?" ).arg( mLayerProperty.schemaName ).arg( mLayerProperty.tableName ),
246+
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
247+
return;
248+
239249
QString errCause;
240250
bool res = ::deleteLayer( mUri, errCause );
241251
if ( !res )
242252
{
243-
QMessageBox::warning( 0, tr( "Delete layer" ), errCause );
253+
QMessageBox::warning( 0, tr( "Delete Layer" ), errCause );
244254
}
245255
else
246256
{
247-
QMessageBox::information( 0, tr( "Delete layer" ), tr( "Layer deleted successfully." ) );
257+
QMessageBox::information( 0, tr( "Delete Layer" ), tr( "Layer deleted successfully." ) );
248258
if ( mParent )
249259
mParent->refresh();
250260
}

src/providers/spatialite/qgsspatialitedataitems.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ QList<QAction*> QgsSLLayerItem::actions()
3939
{
4040
QList<QAction*> lst;
4141

42-
QAction* actionDeleteLayer = new QAction( tr( "Delete layer" ), this );
42+
QAction* actionDeleteLayer = new QAction( tr( "Delete Layer" ), this );
4343
connect( actionDeleteLayer, SIGNAL( triggered() ), this, SLOT( deleteLayer() ) );
4444
lst.append( actionDeleteLayer );
4545

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

4949
void QgsSLLayerItem::deleteLayer()
5050
{
51+
if ( QMessageBox::question( 0, QObject::tr( "Delete Object" ),
52+
QObject::tr( "Are you sure you want to delete %1?" ).arg( mName ),
53+
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
54+
return;
55+
5156
QgsDataSourceURI uri( mUri );
5257
QString errCause;
5358
bool res = ::deleteLayer( uri.database(), uri.table(), errCause );
5459
if ( !res )
5560
{
56-
QMessageBox::warning( 0, tr( "Delete layer" ), errCause );
61+
QMessageBox::warning( 0, tr( "Delete Layer" ), errCause );
5762
}
5863
else
5964
{
60-
QMessageBox::information( 0, tr( "Delete layer" ), tr( "Layer deleted successfully." ) );
65+
QMessageBox::information( 0, tr( "Delete Layer" ), tr( "Layer deleted successfully." ) );
6166
mParent->refresh();
6267
}
6368
}
@@ -167,6 +172,11 @@ void QgsSLConnectionItem::editConnection()
167172

168173
void QgsSLConnectionItem::deleteConnection()
169174
{
175+
if ( QMessageBox::question( 0, QObject::tr( "Delete Connection" ),
176+
QObject::tr( "Are you sure you want to delete the connection to %1?" ).arg( mName ),
177+
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
178+
return;
179+
170180
QgsSpatiaLiteConnection::deleteConnection( mName );
171181
// the parent should be updated
172182
mParent->refresh();

0 commit comments

Comments
 (0)