Skip to content
Permalink
Browse files

Fix GPKG delete from browser stored connection

Fixes #36930 - also delete from stored connections
before refresh.
  • Loading branch information
elpaso committed Jun 3, 2020
1 parent af474ea commit d7a33d3ecad8c10e5f63c0f5f42432fa0411461f
Showing with 11 additions and 2 deletions.
  1. +11 −2 src/gui/providers/ogr/qgsgeopackageitemguiprovider.cpp
@@ -119,6 +119,7 @@ void QgsGeoPackageItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu
QAction *actionDelete = new QAction( message, collectionItem->parent() );
QVariantMap dataDelete;
dataDelete.insert( QStringLiteral( "path" ), collectionItem->path() );
dataDelete.insert( QStringLiteral( "name" ), collectionItem->name() );
dataDelete.insert( QStringLiteral( "parent" ), QVariant::fromValue( QPointer< QgsDataItem >( collectionItem->parent() ) ) );
actionDelete->setData( dataDelete );
connect( actionDelete, &QAction::triggered, this, &QgsGeoPackageItemGuiProvider::deleteGpkg );
@@ -139,7 +140,8 @@ void QgsGeoPackageItemGuiProvider::deleteGpkg()
{
QAction *s = qobject_cast<QAction *>( sender() );
QVariantMap data = s->data().toMap();
const QString path = data[QStringLiteral( "path" )].toString();
const QString path = data[QStringLiteral( "path" )].toString().remove( QStringLiteral( "gpkg:/" ) );
const QString name = data[QStringLiteral( "name" )].toString();
QPointer< QgsDataItem > parent = data[QStringLiteral( "parent" )].value<QPointer< QgsDataItem >>();
if ( parent )
{
@@ -171,6 +173,13 @@ void QgsGeoPackageItemGuiProvider::deleteGpkg()
else
{
QMessageBox::information( nullptr, title, tr( "GeoPackage deleted successfully." ) );
// If the deleted file was a stored connection, remove it too
if ( ! name.isEmpty() )
{
QgsProviderMetadata *md { QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) };
std::unique_ptr<QgsAbstractProviderConnection> conn { md->createConnection( name ) };
conn->remove( name );
}
if ( parent )
parent->refresh();
}
@@ -363,7 +372,7 @@ void QgsGeoPackageItemGuiProvider::vacuum()
{
QAction *s = qobject_cast<QAction *>( sender() );
QVariantMap data = s->data().toMap();
const QString path = data[QStringLiteral( "path" )].toString();
const QString path = data[QStringLiteral( "path" )].toString().remove( QStringLiteral( "gpkg:/" ) );
const QString name = data[QStringLiteral( "name" )].toString();
vacuumGeoPackageDbAction( path, name );
}

0 comments on commit d7a33d3

Please sign in to comment.
You can’t perform that action at this time.