Skip to content

Commit

Permalink
delete selected layers on spatialite and pg
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Nov 15, 2018
1 parent be0ce0c commit 7acd83f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/providers/postgres/qgspostgresdataitems.cpp
Expand Up @@ -317,8 +317,18 @@ QList<QAction *> QgsPGLayerItem::actions( QWidget *parent )
connect( actionRenameLayer, &QAction::triggered, this, &QgsPGLayerItem::renameLayer );
lst.append( actionRenameLayer );

QAction *actionDeleteLayer = new QAction( tr( "Delete %1" ).arg( typeName ), parent );
connect( actionDeleteLayer, &QAction::triggered, this, &QgsPGLayerItem::deleteLayer );
const QString deleteText = selectedItems().count() == 1 ? tr( "Delete %1" ).arg( typeName )
: tr( "Delete Selected Tables" );
QAction *actionDeleteLayer = new QAction( deleteText, parent );
connect( actionDeleteLayer, &QAction::triggered, this, [ = ]
{
QList<QgsDataItem *> items = selectedItems();
for ( QgsDataItem *item : items )
{
if ( QgsPGLayerItem *pgLayerItem = qobject_cast< QgsPGLayerItem *>( item ) )
pgLayerItem->deleteLayer();
}
} ) ;
lst.append( actionDeleteLayer );

if ( !mLayerProperty.isView )
Expand Down
15 changes: 13 additions & 2 deletions src/providers/spatialite/qgsspatialitedataitems.cpp
Expand Up @@ -45,8 +45,19 @@ QList<QAction *> QgsSLLayerItem::actions( QWidget *parent )
{
QList<QAction *> lst;

QAction *actionDeleteLayer = new QAction( tr( "Delete Layer" ), parent );
connect( actionDeleteLayer, &QAction::triggered, this, &QgsSLLayerItem::deleteLayer );
const QString deleteText = selectedItems().count() == 1 ? tr( "Delete Layer '%1'…" ).arg( mName )
: tr( "Delete Selected Layers" );
QAction *actionDeleteLayer = new QAction( deleteText, parent );

connect( actionDeleteLayer, &QAction::triggered, this, [ = ]
{
QList<QgsDataItem *> items = selectedItems();
for ( QgsDataItem *item : items )
{
if ( QgsSLLayerItem *slLayerItem = qobject_cast< QgsSLLayerItem *>( item ) )
slLayerItem->deleteLayer();
}
} ) ;
lst.append( actionDeleteLayer );

return lst;
Expand Down

0 comments on commit 7acd83f

Please sign in to comment.