Skip to content

Commit 7acd83f

Browse files
committedNov 15, 2018
delete selected layers on spatialite and pg
1 parent be0ce0c commit 7acd83f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed
 

‎src/providers/postgres/qgspostgresdataitems.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,18 @@ QList<QAction *> QgsPGLayerItem::actions( QWidget *parent )
317317
connect( actionRenameLayer, &QAction::triggered, this, &QgsPGLayerItem::renameLayer );
318318
lst.append( actionRenameLayer );
319319

320-
QAction *actionDeleteLayer = new QAction( tr( "Delete %1" ).arg( typeName ), parent );
321-
connect( actionDeleteLayer, &QAction::triggered, this, &QgsPGLayerItem::deleteLayer );
320+
const QString deleteText = selectedItems().count() == 1 ? tr( "Delete %1" ).arg( typeName )
321+
: tr( "Delete Selected Tables" );
322+
QAction *actionDeleteLayer = new QAction( deleteText, parent );
323+
connect( actionDeleteLayer, &QAction::triggered, this, [ = ]
324+
{
325+
QList<QgsDataItem *> items = selectedItems();
326+
for ( QgsDataItem *item : items )
327+
{
328+
if ( QgsPGLayerItem *pgLayerItem = qobject_cast< QgsPGLayerItem *>( item ) )
329+
pgLayerItem->deleteLayer();
330+
}
331+
} ) ;
322332
lst.append( actionDeleteLayer );
323333

324334
if ( !mLayerProperty.isView )

‎src/providers/spatialite/qgsspatialitedataitems.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,19 @@ QList<QAction *> QgsSLLayerItem::actions( QWidget *parent )
4545
{
4646
QList<QAction *> lst;
4747

48-
QAction *actionDeleteLayer = new QAction( tr( "Delete Layer" ), parent );
49-
connect( actionDeleteLayer, &QAction::triggered, this, &QgsSLLayerItem::deleteLayer );
48+
const QString deleteText = selectedItems().count() == 1 ? tr( "Delete Layer '%1'…" ).arg( mName )
49+
: tr( "Delete Selected Layers" );
50+
QAction *actionDeleteLayer = new QAction( deleteText, parent );
51+
52+
connect( actionDeleteLayer, &QAction::triggered, this, [ = ]
53+
{
54+
QList<QgsDataItem *> items = selectedItems();
55+
for ( QgsDataItem *item : items )
56+
{
57+
if ( QgsSLLayerItem *slLayerItem = qobject_cast< QgsSLLayerItem *>( item ) )
58+
slLayerItem->deleteLayer();
59+
}
60+
} ) ;
5061
lst.append( actionDeleteLayer );
5162

5263
return lst;

0 commit comments

Comments
 (0)