Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #36937 from elpaso/bugfix-gh36930-gpkg-delete-from…
…-browser

Fix GPKG delete from browser stored connection

(cherry picked from commit bc85a3a)
  • Loading branch information
elpaso authored and nyalldawson committed Jun 19, 2020
1 parent 94b15ab commit ba66097
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/gui/providers/ogr/qgsgeopackageitemguiprovider.cpp
Expand Up @@ -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 );
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -364,7 +379,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 );
}
Expand Down

0 comments on commit ba66097

Please sign in to comment.