Skip to content

Commit d7029bb

Browse files
committedSep 18, 2017
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.
1 parent 808cbf3 commit d7029bb

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed
 

‎src/providers/ogr/qgsgeopackagedataitems.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,19 @@ QList<QAction *> QgsGeoPackageCollectionItem::actions()
166166
{
167167
QList<QAction *> lst;
168168

169-
// Add to stored connections
170-
QAction *actionAddConnection = new QAction( tr( "Add connection" ), this );
171-
connect( actionAddConnection, &QAction::triggered, this, &QgsGeoPackageCollectionItem::addConnection );
172-
lst.append( actionAddConnection );
169+
if ( QgsOgrDbConnection::connectionList( QStringLiteral( "GPKG" ) ).contains( mName ) )
170+
{
171+
QAction *actionDeleteConnection = new QAction( tr( "Remove connection" ), this );
172+
connect( actionDeleteConnection, &QAction::triggered, this, &QgsGeoPackageConnectionItem::deleteConnection );
173+
lst.append( actionDeleteConnection );
174+
}
175+
else
176+
{
177+
// Add to stored connections
178+
QAction *actionAddConnection = new QAction( tr( "Add connection" ), this );
179+
connect( actionAddConnection, &QAction::triggered, this, &QgsGeoPackageCollectionItem::addConnection );
180+
lst.append( actionAddConnection );
181+
}
173182

174183
// Add table to existing DB
175184
QAction *actionAddTable = new QAction( tr( "Create a new layer or table..." ), this );
@@ -481,7 +490,7 @@ QList<QAction *> QgsGeoPackageConnectionItem::actions()
481490
return lst;
482491
}
483492

484-
void QgsGeoPackageConnectionItem::deleteConnection()
493+
void QgsGeoPackageCollectionItem::deleteConnection()
485494
{
486495
QgsOgrDbConnection::deleteConnection( name(), QStringLiteral( "GPKG" ) );
487496
mParent->refreshConnections();

‎src/providers/ogr/qgsgeopackagedataitems.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class QgsGeoPackageCollectionItem : public QgsDataCollectionItem
9393
#ifdef HAVE_GUI
9494
void addTable();
9595
void addConnection();
96+
void deleteConnection();
9697
#endif
9798

9899
protected:
@@ -119,7 +120,6 @@ class QgsGeoPackageConnectionItem : public QgsGeoPackageCollectionItem
119120
public slots:
120121
#ifdef HAVE_GUI
121122
void editConnection();
122-
void deleteConnection();
123123
#endif
124124

125125
};

0 commit comments

Comments
 (0)
Please sign in to comment.