Skip to content

Commit

Permalink
Improved lambda capture
Browse files Browse the repository at this point in the history
Even if the collection item is deleted before the action is triggered,
we can still safely show the creation dialog and act on it (we just
can't trigger the item refresh automatically)
  • Loading branch information
nyalldawson committed Nov 4, 2019
1 parent cdc03e1 commit d8341b8
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/gui/providers/ogr/qgsgeopackageitemguiprovider.cpp
Expand Up @@ -94,20 +94,18 @@ void QgsGeoPackageItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu
// Add table to existing DB
QAction *actionAddTable = new QAction( tr( "Create a New Layer or Table…" ), collectionItem->parent() );
QPointer<QgsGeoPackageCollectionItem>collectionItemPtr { collectionItem };
connect( actionAddTable, &QAction::triggered, actionAddTable, [ collectionItemPtr ]
const QString itemPath = collectionItem->path();
connect( actionAddTable, &QAction::triggered, actionAddTable, [ collectionItemPtr, itemPath ]
{
if ( collectionItemPtr )
QgsNewGeoPackageLayerDialog dialog( nullptr );
dialog.setDatabasePath( itemPath );
dialog.setCrs( QgsProject::instance()->defaultCrsForNewLayers() );
dialog.setOverwriteBehavior( QgsNewGeoPackageLayerDialog::AddNewLayer );
dialog.lockDatabasePath();
if ( dialog.exec() == QDialog::Accepted )
{
QgsNewGeoPackageLayerDialog dialog( nullptr );
dialog.setDatabasePath( collectionItemPtr->path() );
dialog.setCrs( QgsProject::instance()->defaultCrsForNewLayers() );
dialog.setOverwriteBehavior( QgsNewGeoPackageLayerDialog::AddNewLayer );
dialog.lockDatabasePath();
if ( dialog.exec() == QDialog::Accepted )
{
if ( collectionItemPtr )
collectionItemPtr->refreshConnections();
}
if ( collectionItemPtr )
collectionItemPtr->refreshConnections();
}
} );

Expand Down

0 comments on commit d8341b8

Please sign in to comment.