@@ -120,7 +120,7 @@ void QgsGeoPackageRootItem::createDatabase()
120
120
#endif
121
121
122
122
123
- QgsGeoPackageConnectionItem::QgsGeoPackageConnectionItem ( QgsDataItem *parent, const QString &name, const QString &path )
123
+ QgsGeoPackageCollectionItem::QgsGeoPackageCollectionItem ( QgsDataItem *parent, const QString &name, const QString &path )
124
124
: QgsDataCollectionItem( parent, name, path )
125
125
, mPath( path )
126
126
{
@@ -129,7 +129,7 @@ QgsGeoPackageConnectionItem::QgsGeoPackageConnectionItem( QgsDataItem *parent, c
129
129
130
130
131
131
132
- QVector<QgsDataItem *> QgsGeoPackageConnectionItem ::createChildren ()
132
+ QVector<QgsDataItem *> QgsGeoPackageCollectionItem ::createChildren ()
133
133
{
134
134
QVector<QgsDataItem *> children;
135
135
const auto layers = QgsOgrLayerItem::subLayers ( mPath , QStringLiteral ( " GPKG" ) );
@@ -148,30 +148,31 @@ QVector<QgsDataItem *> QgsGeoPackageConnectionItem::createChildren()
148
148
return children;
149
149
}
150
150
151
- bool QgsGeoPackageConnectionItem ::equal ( const QgsDataItem *other )
151
+ bool QgsGeoPackageCollectionItem ::equal ( const QgsDataItem *other )
152
152
{
153
153
if ( type () != other->type () )
154
154
{
155
155
return false ;
156
156
}
157
- const QgsGeoPackageConnectionItem *o = dynamic_cast <const QgsGeoPackageConnectionItem *>( other );
157
+ const QgsGeoPackageCollectionItem *o = dynamic_cast <const QgsGeoPackageCollectionItem *>( other );
158
158
return o && mPath == o->mPath && mName == o->mName ;
159
159
160
160
}
161
161
162
162
#ifdef HAVE_GUI
163
163
164
- QList<QAction *> QgsGeoPackageConnectionItem ::actions ()
164
+ QList<QAction *> QgsGeoPackageCollectionItem ::actions ()
165
165
{
166
166
QList<QAction *> lst;
167
167
168
- QAction *actionDeleteConnection = new QAction ( tr ( " Remove connection" ), this );
169
- connect ( actionDeleteConnection, &QAction::triggered, this , &QgsGeoPackageConnectionItem::deleteConnection );
170
- lst.append ( actionDeleteConnection );
168
+ // Add to stored connections
169
+ QAction *actionAddConnection = new QAction ( tr ( " Add connection" ), this );
170
+ connect ( actionAddConnection, &QAction::triggered, this , &QgsGeoPackageCollectionItem::addConnection );
171
+ lst.append ( actionAddConnection );
171
172
172
173
// Add table to existing DB
173
174
QAction *actionAddTable = new QAction ( tr ( " Create a new layer or table..." ), this );
174
- connect ( actionAddTable, &QAction::triggered, this , &QgsGeoPackageConnectionItem ::addTable );
175
+ connect ( actionAddTable, &QAction::triggered, this , &QgsGeoPackageCollectionItem ::addTable );
175
176
lst.append ( actionAddTable );
176
177
177
178
return lst;
@@ -180,7 +181,7 @@ QList<QAction *> QgsGeoPackageConnectionItem::actions()
180
181
181
182
182
183
183
- bool QgsGeoPackageConnectionItem ::handleDrop ( const QMimeData *data, Qt::DropAction )
184
+ bool QgsGeoPackageCollectionItem ::handleDrop ( const QMimeData *data, Qt::DropAction )
184
185
{
185
186
186
187
if ( !QgsMimeDataUtils::isUriList ( data ) )
@@ -327,7 +328,7 @@ bool QgsGeoPackageConnectionItem::handleDrop( const QMimeData *data, Qt::DropAct
327
328
}
328
329
329
330
330
- bool QgsGeoPackageConnectionItem ::deleteGeoPackageRasterLayer ( const QString &uri, QString &errCause )
331
+ bool QgsGeoPackageCollectionItem ::deleteGeoPackageRasterLayer ( const QString &uri, QString &errCause )
331
332
{
332
333
bool result = false ;
333
334
// Better safe than sorry
@@ -444,15 +445,49 @@ bool QgsGeoPackageConnectionItem::deleteGeoPackageRasterLayer( const QString &ur
444
445
return result;
445
446
}
446
447
448
+ QgsGeoPackageConnectionItem::QgsGeoPackageConnectionItem ( QgsDataItem *parent, const QString &name, const QString &path )
449
+ : QgsGeoPackageCollectionItem( parent, name, path )
450
+ {
451
+
452
+ }
453
+
454
+ bool QgsGeoPackageConnectionItem::equal ( const QgsDataItem *other )
455
+ {
456
+ if ( type () != other->type () )
457
+ {
458
+ return false ;
459
+ }
460
+ const QgsGeoPackageConnectionItem *o = dynamic_cast <const QgsGeoPackageConnectionItem *>( other );
461
+ return o && mPath == o->mPath && mName == o->mName ;
462
+
463
+ }
464
+
465
+ #ifdef HAVE_GUI
466
+ QList<QAction *> QgsGeoPackageConnectionItem::actions ()
467
+ {
468
+ QList<QAction *> lst;
469
+
470
+ QAction *actionDeleteConnection = new QAction ( tr ( " Remove connection" ), this );
471
+ connect ( actionDeleteConnection, &QAction::triggered, this , &QgsGeoPackageConnectionItem::deleteConnection );
472
+ lst.append ( actionDeleteConnection );
473
+
474
+ // Add table to existing DB
475
+ QAction *actionAddTable = new QAction ( tr ( " Create a new layer or table..." ), this );
476
+ connect ( actionAddTable, &QAction::triggered, this , &QgsGeoPackageConnectionItem::addTable );
477
+ lst.append ( actionAddTable );
478
+
479
+
480
+ return lst;
481
+ }
447
482
448
483
void QgsGeoPackageConnectionItem::deleteConnection ()
449
484
{
450
485
QgsOgrDbConnection::deleteConnection ( name (), QStringLiteral ( " GPKG" ) );
451
486
mParent ->refreshConnections ();
452
487
}
453
488
454
- # ifdef HAVE_GUI
455
- void QgsGeoPackageConnectionItem ::addTable ()
489
+
490
+ void QgsGeoPackageCollectionItem ::addTable ()
456
491
{
457
492
QgsNewGeoPackageLayerDialog dialog ( nullptr );
458
493
QFileInfo fileInfo ( mPath );
@@ -472,6 +507,14 @@ void QgsGeoPackageConnectionItem::addTable()
472
507
QgsDebugMsg ( QStringLiteral ( " Cannot add Table: connection %1 does not exists or the path is empy!" ).arg ( connName ) );
473
508
}
474
509
}
510
+
511
+ void QgsGeoPackageCollectionItem::addConnection ()
512
+ {
513
+ QgsOgrDbConnection connection ( mName , QStringLiteral ( " GeoPackage" ) );
514
+ connection.save ();
515
+ emit connectionsChanged ();
516
+ }
517
+
475
518
#endif
476
519
477
520
#ifdef HAVE_GUI
@@ -554,7 +597,7 @@ QgsGeoPackageRasterLayerItem::QgsGeoPackageRasterLayerItem( QgsDataItem *parent,
554
597
555
598
bool QgsGeoPackageRasterLayerItem::executeDeleteLayer ( QString &errCause )
556
599
{
557
- return QgsGeoPackageConnectionItem ::deleteGeoPackageRasterLayer ( mUri , errCause );
600
+ return QgsGeoPackageCollectionItem ::deleteGeoPackageRasterLayer ( mUri , errCause );
558
601
}
559
602
560
603
0 commit comments