Geopackage: switch the action from add/remove connection

depending on the connection being already stored or not,
this allows the user to remove and existing connection.
This commit is contained in:
Alessandro Pasotti 2017-09-18 14:08:48 +02:00
parent 808cbf3526
commit d7029bb5a5
2 changed files with 15 additions and 6 deletions

View File

@ -166,10 +166,19 @@ QList<QAction *> QgsGeoPackageCollectionItem::actions()
{
QList<QAction *> lst;
if ( QgsOgrDbConnection::connectionList( QStringLiteral( "GPKG" ) ).contains( mName ) )
{
QAction *actionDeleteConnection = new QAction( tr( "Remove connection" ), this );
connect( actionDeleteConnection, &QAction::triggered, this, &QgsGeoPackageConnectionItem::deleteConnection );
lst.append( actionDeleteConnection );
}
else
{
// Add to stored connections
QAction *actionAddConnection = new QAction( tr( "Add connection" ), this );
connect( actionAddConnection, &QAction::triggered, this, &QgsGeoPackageCollectionItem::addConnection );
lst.append( actionAddConnection );
}
// Add table to existing DB
QAction *actionAddTable = new QAction( tr( "Create a new layer or table..." ), this );
@ -481,7 +490,7 @@ QList<QAction *> QgsGeoPackageConnectionItem::actions()
return lst;
}
void QgsGeoPackageConnectionItem::deleteConnection()
void QgsGeoPackageCollectionItem::deleteConnection()
{
QgsOgrDbConnection::deleteConnection( name(), QStringLiteral( "GPKG" ) );
mParent->refreshConnections();

View File

@ -93,6 +93,7 @@ class QgsGeoPackageCollectionItem : public QgsDataCollectionItem
#ifdef HAVE_GUI
void addTable();
void addConnection();
void deleteConnection();
#endif
protected:
@ -119,7 +120,6 @@ class QgsGeoPackageConnectionItem : public QgsGeoPackageCollectionItem
public slots:
#ifdef HAVE_GUI
void editConnection();
void deleteConnection();
#endif
};