Skip to content
Permalink
Browse files

Merge pull request #36937 from elpaso/bugfix-gh36930-gpkg-delete-from…

…-browser

Fix GPKG delete from browser stored connection
  • Loading branch information
elpaso committed Jun 4, 2020
2 parents b923b3d + 5c856b0 commit eacca238b0c568923aee1c52816d9c00ae71578d
Showing with 17 additions and 2 deletions.
  1. +17 −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,19 @@ 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" ) ) };
try
{
md->deleteConnection( name );
}
catch ( QgsProviderConnectionException &ex )
{
QgsDebugMsg( QStringLiteral( "Could not remove GPKG connection %1: %2" ).arg( name, ex.what() ) );
}
}
if ( parent )
parent->refresh();
}
@@ -363,7 +378,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 eacca23

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