Skip to content

Commit

Permalink
Geopackage: switch the action from add/remove connection
Browse files Browse the repository at this point in the history
depending on the connection being already stored or not,
this allows the user to remove and existing connection.
  • Loading branch information
elpaso committed Sep 18, 2017
1 parent 808cbf3 commit d7029bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/providers/ogr/qgsgeopackagedataitems.cpp
Expand Up @@ -166,10 +166,19 @@ QList<QAction *> QgsGeoPackageCollectionItem::actions()
{
QList<QAction *> lst;

// Add to stored connections
QAction *actionAddConnection = new QAction( tr( "Add connection" ), this );
connect( actionAddConnection, &QAction::triggered, this, &QgsGeoPackageCollectionItem::addConnection );
lst.append( actionAddConnection );
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 );
Expand Down Expand Up @@ -481,7 +490,7 @@ QList<QAction *> QgsGeoPackageConnectionItem::actions()
return lst;
}

void QgsGeoPackageConnectionItem::deleteConnection()
void QgsGeoPackageCollectionItem::deleteConnection()
{
QgsOgrDbConnection::deleteConnection( name(), QStringLiteral( "GPKG" ) );
mParent->refreshConnections();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsgeopackagedataitems.h
Expand Up @@ -93,6 +93,7 @@ class QgsGeoPackageCollectionItem : public QgsDataCollectionItem
#ifdef HAVE_GUI
void addTable();
void addConnection();
void deleteConnection();
#endif

protected:
Expand All @@ -119,7 +120,6 @@ class QgsGeoPackageConnectionItem : public QgsGeoPackageCollectionItem
public slots:
#ifdef HAVE_GUI
void editConnection();
void deleteConnection();
#endif

};
Expand Down

0 comments on commit d7029bb

Please sign in to comment.