@@ -133,6 +133,9 @@ void QgsManageConnectionsDialog::doExportImport()
133
133
case GeoNode:
134
134
doc = saveGeonodeConnections ( items );
135
135
break ;
136
+ case XyzTiles:
137
+ doc = saveXyzTilesConnections ( items );
138
+ break ;
136
139
}
137
140
138
141
QFile file ( mFileName );
@@ -201,6 +204,9 @@ void QgsManageConnectionsDialog::doExportImport()
201
204
case GeoNode:
202
205
loadGeonodeConnections ( doc, items );
203
206
break ;
207
+ case XyzTiles:
208
+ loadXyzTilesConnections ( doc, items );
209
+ break ;
204
210
}
205
211
// clear connections list and close window
206
212
listConnections->clear ();
@@ -242,6 +248,9 @@ bool QgsManageConnectionsDialog::populateConnections()
242
248
case GeoNode:
243
249
settings.beginGroup ( QStringLiteral ( " /qgis/connections-geonode" ) );
244
250
break ;
251
+ case XyzTiles:
252
+ settings.beginGroup ( QStringLiteral ( " /qgis/connections-xyz" ) );
253
+ break ;
245
254
}
246
255
QStringList keys = settings.childGroups ();
247
256
QStringList::Iterator it = keys.begin ();
@@ -353,6 +362,14 @@ bool QgsManageConnectionsDialog::populateConnections()
353
362
return false ;
354
363
}
355
364
break ;
365
+ case XyzTiles:
366
+ if ( root.tagName () != QLatin1String ( " qgsXYZTilesConnections" ) )
367
+ {
368
+ QMessageBox::information ( this , tr ( " Loading Connections" ),
369
+ tr ( " The file is not a XYZ Tiles connections exchange file." ) );
370
+ return false ;
371
+ }
372
+ break ;
356
373
}
357
374
358
375
QDomElement child = root.firstChildElement ();
@@ -622,6 +639,35 @@ QDomDocument QgsManageConnectionsDialog::saveGeonodeConnections( const QStringLi
622
639
return doc;
623
640
}
624
641
642
+ QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections ( const QStringList &connections )
643
+ {
644
+ QDomDocument doc ( QStringLiteral ( " connections" ) );
645
+ QDomElement root = doc.createElement ( QStringLiteral ( " qgsXYZTilesConnections" ) );
646
+ root.setAttribute ( QStringLiteral ( " version" ), QStringLiteral ( " 1.0" ) );
647
+ doc.appendChild ( root );
648
+
649
+ QgsSettings settings;
650
+ QString path;
651
+ for ( int i = 0 ; i < connections.count (); ++i )
652
+ {
653
+ path = " qgis/connections-xyz/" + connections[ i ];
654
+ QDomElement el = doc.createElement ( QStringLiteral ( " xyztiles" ) );
655
+
656
+ el.setAttribute ( QStringLiteral ( " name" ), connections[ i ] );
657
+ el.setAttribute ( QStringLiteral ( " url" ), settings.value ( path + " /url" , " " ).toString () );
658
+ el.setAttribute ( QStringLiteral ( " zmin" ), settings.value ( path + " /zmin" , -1 ).toInt () );
659
+ el.setAttribute ( QStringLiteral ( " zmax" ), settings.value ( path + " /zmax" , -1 ).toInt () );
660
+ el.setAttribute ( QStringLiteral ( " authcfg" ), settings.value ( path + " /authcfg" , " " ).toString () );
661
+ el.setAttribute ( QStringLiteral ( " username" ), settings.value ( path + " /username" , " " ).toString () );
662
+ el.setAttribute ( QStringLiteral ( " password" ), settings.value ( path + " /password" , " " ).toString () );
663
+ el.setAttribute ( QStringLiteral ( " referer" ), settings.value ( path + " /referer" , " " ).toString () );
664
+
665
+ root.appendChild ( el );
666
+ }
667
+
668
+ return doc;
669
+ }
670
+
625
671
void QgsManageConnectionsDialog::loadOWSConnections ( const QDomDocument &doc, const QStringList &items, const QString &service )
626
672
{
627
673
QDomElement root = doc.documentElement ();
@@ -1226,6 +1272,85 @@ void QgsManageConnectionsDialog::loadGeonodeConnections( const QDomDocument &doc
1226
1272
}
1227
1273
}
1228
1274
1275
+ void QgsManageConnectionsDialog::loadXyzTilesConnections ( const QDomDocument &doc, const QStringList &items )
1276
+ {
1277
+ QDomElement root = doc.documentElement ();
1278
+ if ( root.tagName () != QLatin1String ( " qgsXYZTilesConnections" ) )
1279
+ {
1280
+ QMessageBox::information ( this , tr ( " Loading Connections" ),
1281
+ tr ( " The file is not a XYZ Tiles connections exchange file." ) );
1282
+ return ;
1283
+ }
1284
+
1285
+ QString connectionName;
1286
+ QgsSettings settings;
1287
+ settings.beginGroup ( QStringLiteral ( " /qgis/connections-xyz" ) );
1288
+ QStringList keys = settings.childGroups ();
1289
+ settings.endGroup ();
1290
+ QDomElement child = root.firstChildElement ();
1291
+ bool prompt = true ;
1292
+ bool overwrite = true ;
1293
+
1294
+ while ( !child.isNull () )
1295
+ {
1296
+ connectionName = child.attribute ( QStringLiteral ( " name" ) );
1297
+ if ( !items.contains ( connectionName ) )
1298
+ {
1299
+ child = child.nextSiblingElement ();
1300
+ continue ;
1301
+ }
1302
+
1303
+ // check for duplicates
1304
+ if ( keys.contains ( connectionName ) && prompt )
1305
+ {
1306
+ int res = QMessageBox::warning ( this ,
1307
+ tr ( " Loading Connections" ),
1308
+ tr ( " Connection with name '%1' already exists. Overwrite?" )
1309
+ .arg ( connectionName ),
1310
+ QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1311
+
1312
+ switch ( res )
1313
+ {
1314
+ case QMessageBox::Cancel:
1315
+ return ;
1316
+ case QMessageBox::No:
1317
+ child = child.nextSiblingElement ();
1318
+ continue ;
1319
+ case QMessageBox::Yes:
1320
+ overwrite = true ;
1321
+ break ;
1322
+ case QMessageBox::YesToAll:
1323
+ prompt = false ;
1324
+ overwrite = true ;
1325
+ break ;
1326
+ case QMessageBox::NoToAll:
1327
+ prompt = false ;
1328
+ overwrite = false ;
1329
+ break ;
1330
+ }
1331
+ }
1332
+
1333
+ if ( keys.contains ( connectionName ) && !overwrite )
1334
+ {
1335
+ child = child.nextSiblingElement ();
1336
+ continue ;
1337
+ }
1338
+
1339
+ settings.beginGroup ( " qgis/connections-xyz/" + connectionName );
1340
+ settings.setValue ( QStringLiteral ( " url" ), child.attribute ( QStringLiteral ( " url" ) ) );
1341
+ settings.setValue ( QStringLiteral ( " zmin" ), child.attribute ( QStringLiteral ( " zmin" ) ) );
1342
+ settings.setValue ( QStringLiteral ( " zmax" ), child.attribute ( QStringLiteral ( " zmax" ) ) );
1343
+ settings.setValue ( QStringLiteral ( " authcfg" ), child.attribute ( QStringLiteral ( " authcfg" ) ) );
1344
+ settings.setValue ( QStringLiteral ( " username" ), child.attribute ( QStringLiteral ( " username" ) ) );
1345
+ settings.setValue ( QStringLiteral ( " password" ), child.attribute ( QStringLiteral ( " password" ) ) );
1346
+ settings.setValue ( QStringLiteral ( " referer" ), child.attribute ( QStringLiteral ( " referer" ) ) );
1347
+ settings.endGroup ();
1348
+
1349
+ child = child.nextSiblingElement ();
1350
+ }
1351
+ }
1352
+
1353
+
1229
1354
void QgsManageConnectionsDialog::selectAll ()
1230
1355
{
1231
1356
listConnections->selectAll ();
0 commit comments