32#include "qgsgdalcloudconnection.h"
33#include "qgsstacconnection.h"
37 , mFileName( fileName )
39 , mConnectionType( type )
44 QPushButton *pb =
nullptr;
45 pb =
new QPushButton( tr(
"Select All" ) );
46 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
49 pb =
new QPushButton( tr(
"Clear Selection" ) );
50 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
53 if ( mDialogMode ==
Import )
55 label->setText( tr(
"Select connections to import" ) );
56 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Import" ) );
57 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
62 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Export" ) );
63 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
66 if ( !populateConnections() )
68 QApplication::postEvent(
this,
new QCloseEvent() );
72 disconnect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
80 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
85 const QList<QListWidgetItem *> selection = listConnections->selectedItems();
86 if ( selection.isEmpty() )
88 QMessageBox::warning(
this, tr(
"Export/Import Error" ),
89 tr(
"You should select at least one connection from list." ) );
94 items.reserve( selection.size() );
95 for (
int i = 0; i < selection.size(); ++i )
97 items.append( selection.at( i )->text() );
100 if ( mDialogMode ==
Export )
102 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save Connections" ), QDir::homePath(),
103 tr(
"XML files (*.xml *.XML)" ) );
107 if ( fileName.isEmpty() )
113 if ( !fileName.endsWith( QLatin1String(
".xml" ), Qt::CaseInsensitive ) )
115 fileName += QLatin1String(
".xml" );
118 mFileName = fileName;
121 switch ( mConnectionType )
124 doc = saveOWSConnections( items, QStringLiteral(
"WMS" ) );
127 doc = saveWfsConnections( items );
130 doc = savePgConnections( items );
133 doc = saveMssqlConnections( items );
136 doc = saveOWSConnections( items, QStringLiteral(
"WCS" ) );
139 doc = saveOracleConnections( items );
142 doc = saveHanaConnections( items );
145 doc = saveXyzTilesConnections( items );
149 doc = saveArcgisConnections( items );
152 doc = saveVectorTileConnections( items );
155 doc = saveTiledSceneConnections( items );
158 doc = saveSensorThingsConnections( items );
161 doc = saveCloudStorageConnections( items );
164 doc = saveStacConnections( items );
168 QFile file( mFileName );
169 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
171 QMessageBox::warning(
this, tr(
"Saving Connections" ),
172 tr(
"Cannot write file %1:\n%2." )
174 file.errorString() ) );
178 QTextStream out( &file );
183 QFile file( mFileName );
184 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
186 QMessageBox::warning(
this, tr(
"Loading Connections" ),
187 tr(
"Cannot read file %1:\n%2." )
189 file.errorString() ) );
198 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
200 QMessageBox::warning(
this, tr(
"Loading Connections" ),
201 tr(
"Parse error at line %1, column %2:\n%3" )
208 switch ( mConnectionType )
211 loadOWSConnections( doc, items, QStringLiteral(
"WMS" ) );
214 loadWfsConnections( doc, items );
217 loadPgConnections( doc, items );
220 loadMssqlConnections( doc, items );
223 loadOWSConnections( doc, items, QStringLiteral(
"WCS" ) );
226 loadOracleConnections( doc, items );
229 loadHanaConnections( doc, items );
232 loadXyzTilesConnections( doc, items );
235 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISMAPSERVER" ) );
238 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISFEATURESERVER" ) );
241 loadVectorTileConnections( doc, items );
244 loadTiledSceneConnections( doc, items );
247 loadSensorThingsConnections( doc, items );
250 loadCloudStorageConnections( doc, items );
253 loadStacConnections( doc, items );
257 listConnections->clear();
264bool QgsManageConnectionsDialog::populateConnections()
267 if ( mDialogMode ==
Export )
269 QStringList connections;
271 switch ( mConnectionType )
283 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
287 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
291 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
295 settings.
beginGroup( QStringLiteral(
"/HANA/connections" ) );
306 connections = QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
309 connections = QgsTiledSceneProviderConnection::sTreeConnectionTiledScene->items();
312 connections = QgsSensorThingsProviderConnection::sTreeSensorThingsConnections->items();
315 connections = QgsGdalCloudProviderConnection::sTreeConnectionCloud->items();
318 connections = QgsStacConnection::sTreeConnectionStac->items();
321 for (
const QString &connection : std::as_const( connections ) )
323 QListWidgetItem *item =
new QListWidgetItem();
324 item->setText( connection );
325 listConnections->addItem( item );
331 QFile file( mFileName );
332 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
334 QMessageBox::warning(
this, tr(
"Loading Connections" ),
335 tr(
"Cannot read file %1:\n%2." )
337 file.errorString() ) );
346 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
348 QMessageBox::warning(
this, tr(
"Loading Connections" ),
349 tr(
"Parse error at line %1, column %2:\n%3" )
356 const QDomElement root = doc.documentElement();
357 switch ( mConnectionType )
360 if ( root.tagName() != QLatin1String(
"qgsWMSConnections" ) )
362 QMessageBox::information(
this, tr(
"Loading Connections" ),
363 tr(
"The file is not a WMS connections exchange file." ) );
369 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
371 QMessageBox::information(
this, tr(
"Loading Connections" ),
372 tr(
"The file is not a WFS connections exchange file." ) );
378 if ( root.tagName() != QLatin1String(
"qgsWCSConnections" ) )
380 QMessageBox::information(
this, tr(
"Loading Connections" ),
381 tr(
"The file is not a WCS connections exchange file." ) );
387 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
389 QMessageBox::information(
this, tr(
"Loading Connections" ),
390 tr(
"The file is not a PostGIS connections exchange file." ) );
396 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
398 QMessageBox::information(
this, tr(
"Loading Connections" ),
399 tr(
"The file is not a MS SQL Server connections exchange file." ) );
404 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
406 QMessageBox::information(
this, tr(
"Loading Connections" ),
407 tr(
"The file is not an Oracle connections exchange file." ) );
412 if ( root.tagName() != QLatin1String(
"qgsHanaConnections" ) )
414 QMessageBox::warning(
this, tr(
"Loading Connections" ),
415 tr(
"The file is not a HANA connections exchange file." ) );
420 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
422 QMessageBox::information(
this, tr(
"Loading Connections" ),
423 tr(
"The file is not a XYZ Tiles connections exchange file." ) );
428 if ( root.tagName() != QLatin1String(
"qgsARCGISMAPSERVERConnections" ) )
430 QMessageBox::information(
this, tr(
"Loading Connections" ),
431 tr(
"The file is not a ArcGIS Map Service connections exchange file." ) );
436 if ( root.tagName() != QLatin1String(
"qgsARCGISFEATURESERVERConnections" ) )
438 QMessageBox::information(
this, tr(
"Loading Connections" ),
439 tr(
"The file is not a ArcGIS Feature Service connections exchange file." ) );
444 if ( root.tagName() != QLatin1String(
"qgsVectorTileConnections" ) )
446 QMessageBox::information(
this, tr(
"Loading Connections" ),
447 tr(
"The file is not a Vector Tile connections exchange file." ) );
452 if ( root.tagName() != QLatin1String(
"qgsTiledSceneConnections" ) )
454 QMessageBox::information(
this, tr(
"Loading Connections" ),
455 tr(
"The file is not a tiled scene connections exchange file." ) );
460 if ( root.tagName() != QLatin1String(
"qgsSensorThingsConnections" ) )
462 QMessageBox::information(
this, tr(
"Loading Connections" ),
463 tr(
"The file is not a SensorThings connections exchange file." ) );
468 if ( root.tagName() != QLatin1String(
"qgsCloudStorageConnections" ) )
470 QMessageBox::information(
this, tr(
"Loading Connections" ),
471 tr(
"The file is not a cloud storage connections exchange file." ) );
476 if ( root.tagName() != QLatin1String(
"qgsStacConnections" ) )
478 QMessageBox::information(
this, tr(
"Loading Connections" ),
479 tr(
"The file is not a STAC connections exchange file." ) );
485 QDomElement child = root.firstChildElement();
486 while ( !child.isNull() )
488 QListWidgetItem *item =
new QListWidgetItem();
489 item->setText( child.attribute( QStringLiteral(
"name" ) ) );
490 listConnections->addItem( item );
491 child = child.nextSiblingElement();
497QDomDocument QgsManageConnectionsDialog::saveOWSConnections(
const QStringList &connections,
const QString &service )
499 QDomDocument doc( QStringLiteral(
"connections" ) );
500 QDomElement root = doc.createElement(
"qgs" + service.toUpper() +
"Connections" );
501 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
502 doc.appendChild( root );
504 for (
int i = 0; i < connections.count(); ++i )
506 QDomElement el = doc.createElement( service.toLower() );
507 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
510 if ( service == QLatin1String(
"WMS" ) )
520 httpHeader.updateDomElement( el );
525 root.appendChild( el );
531QDomDocument QgsManageConnectionsDialog::saveWfsConnections(
const QStringList &connections )
533 QDomDocument doc( QStringLiteral(
"connections" ) );
534 QDomElement root = doc.createElement( QStringLiteral(
"qgsWFSConnections" ) );
535 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.1" ) );
536 doc.appendChild( root );
538 for (
int i = 0; i < connections.count(); ++i )
540 QDomElement el = doc.createElement( QStringLiteral(
"wfs" ) );
541 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
552 root.appendChild( el );
558QDomDocument QgsManageConnectionsDialog::savePgConnections(
const QStringList &connections )
560 QDomDocument doc( QStringLiteral(
"connections" ) );
561 QDomElement root = doc.createElement( QStringLiteral(
"qgsPgConnections" ) );
562 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
563 doc.appendChild( root );
567 for (
int i = 0; i < connections.count(); ++i )
569 path =
"/PostgreSQL/connections/" + connections[ i ];
570 QDomElement el = doc.createElement( QStringLiteral(
"postgis" ) );
571 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
572 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
573 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
574 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
575 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
576 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
577 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
578 el.setAttribute( QStringLiteral(
"projectsInDatabase" ), settings.
value( path +
"/projectsInDatabase",
"0" ).toString() );
579 el.setAttribute( QStringLiteral(
"dontResolveType" ), settings.
value( path +
"/dontResolveType",
"0" ).toString() );
580 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
581 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
582 el.setAttribute( QStringLiteral(
"publicOnly" ), settings.
value( path +
"/publicOnly",
"0" ).toString() );
584 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
586 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
588 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
591 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
593 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
595 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
598 root.appendChild( el );
604QDomDocument QgsManageConnectionsDialog::saveMssqlConnections(
const QStringList &connections )
606 QDomDocument doc( QStringLiteral(
"connections" ) );
607 QDomElement root = doc.createElement( QStringLiteral(
"qgsMssqlConnections" ) );
608 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
609 doc.appendChild( root );
613 for (
int i = 0; i < connections.count(); ++i )
615 path =
"/MSSQL/connections/" + connections[ i ];
616 QDomElement el = doc.createElement( QStringLiteral(
"mssql" ) );
617 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
618 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
619 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
620 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
621 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
622 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
623 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
625 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
627 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
629 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
632 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
634 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
636 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
639 root.appendChild( el );
645QDomDocument QgsManageConnectionsDialog::saveOracleConnections(
const QStringList &connections )
647 QDomDocument doc( QStringLiteral(
"connections" ) );
648 QDomElement root = doc.createElement( QStringLiteral(
"qgsOracleConnections" ) );
649 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
650 doc.appendChild( root );
654 for (
int i = 0; i < connections.count(); ++i )
656 path =
"/Oracle/connections/" + connections[ i ];
657 QDomElement el = doc.createElement( QStringLiteral(
"oracle" ) );
658 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
659 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
660 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
661 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
662 el.setAttribute( QStringLiteral(
"dboptions" ), settings.
value( path +
"/dboptions" ).toString() );
663 el.setAttribute( QStringLiteral(
"dbworkspace" ), settings.
value( path +
"/dbworkspace" ).toString() );
664 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema" ).toString() );
665 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
666 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly",
"0" ).toString() );
667 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
668 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
670 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
672 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
674 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
677 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
679 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
681 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
684 root.appendChild( el );
690QDomDocument QgsManageConnectionsDialog::saveHanaConnections(
const QStringList &connections )
692 QDomDocument doc( QStringLiteral(
"connections" ) );
693 QDomElement root = doc.createElement( QStringLiteral(
"qgsHanaConnections" ) );
694 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
695 doc.appendChild( root );
699 for (
int i = 0; i < connections.count(); ++i )
701 path =
"/HANA/connections/" + connections[i];
702 QDomElement el = doc.createElement( QStringLiteral(
"hana" ) );
703 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
704 el.setAttribute( QStringLiteral(
"driver" ), settings.
value( path +
"/driver", QString() ).toString() );
705 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host", QString() ).toString() );
706 el.setAttribute( QStringLiteral(
"identifierType" ), settings.
value( path +
"/identifierType", QString() ).toString() );
707 el.setAttribute( QStringLiteral(
"identifier" ), settings.
value( path +
"/identifier", QString() ).toString() );
708 el.setAttribute( QStringLiteral(
"multitenant" ), settings.
value( path +
"/multitenant", QString() ).toString() );
709 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database", QString() ).toString() );
710 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema", QString() ).toString() );
711 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly", QStringLiteral(
"0" ) ).toString() );
712 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables", QStringLiteral(
"0" ) ).toString() );
714 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername", QStringLiteral(
"false" ) ).toString() );
715 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
717 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username", QString() ).toString() );
720 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword", QStringLiteral(
"false" ) ).toString() );
721 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
723 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password", QString() ).toString() );
726 el.setAttribute( QStringLiteral(
"sslEnabled" ), settings.
value( path +
"/sslEnabled", QStringLiteral(
"false" ) ).toString() );
727 el.setAttribute( QStringLiteral(
"sslCryptoProvider" ), settings.
value( path +
"/sslCryptoProvider", QStringLiteral(
"openssl" ) ).toString() );
728 el.setAttribute( QStringLiteral(
"sslKeyStore" ), settings.
value( path +
"/sslKeyStore", QString() ).toString() );
729 el.setAttribute( QStringLiteral(
"sslTrustStore" ), settings.
value( path +
"/sslTrustStore", QString() ).toString() );
730 el.setAttribute( QStringLiteral(
"sslValidateCertificate" ), settings.
value( path +
"/sslValidateCertificate", QStringLiteral(
"false" ) ).toString() );
731 el.setAttribute( QStringLiteral(
"sslHostNameInCertificate" ), settings.
value( path +
"/sslHostNameInCertificate", QString() ).toString() );
733 root.appendChild( el );
739QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections(
const QStringList &connections )
741 QDomDocument doc( QStringLiteral(
"connections" ) );
742 QDomElement root = doc.createElement( QStringLiteral(
"qgsXYZTilesConnections" ) );
743 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
744 doc.appendChild( root );
746 for (
int i = 0; i < connections.count(); ++i )
749 QDomElement el = doc.createElement( QStringLiteral(
"xyztiles" ) );
751 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
761 httpHeader.updateDomElement( el );
763 root.appendChild( el );
769QDomDocument QgsManageConnectionsDialog::saveArcgisConnections(
const QStringList &connections )
771 QDomDocument doc( QStringLiteral(
"connections" ) );
772 QDomElement root = doc.createElement(
"qgsARCGISFEATURESERVERConnections" );
773 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
774 doc.appendChild( root );
776 for (
const QString &connection : connections )
778 QDomElement el = doc.createElement( QStringLiteral(
"arcgisfeatureserver" ) );
779 el.setAttribute( QStringLiteral(
"name" ), connection );
783 httpHeader.updateDomElement( el );
789 root.appendChild( el );
795QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections(
const QStringList &connections )
797 QDomDocument doc( QStringLiteral(
"connections" ) );
798 QDomElement root = doc.createElement( QStringLiteral(
"qgsVectorTileConnections" ) );
799 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
800 doc.appendChild( root );
802 for (
int i = 0; i < connections.count(); ++i )
804 QDomElement el = doc.createElement( QStringLiteral(
"vectortile" ) );
806 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
807 el.setAttribute( QStringLiteral(
"url" ), QgsVectorTileProviderConnection::settingsUrl->value( connections[ i ] ) );
808 el.setAttribute( QStringLiteral(
"zmin" ), QgsVectorTileProviderConnection::settingsZmin->value( connections[ i ] ) );
809 el.setAttribute( QStringLiteral(
"zmax" ), QgsVectorTileProviderConnection::settingsZmax->value( connections[ i ] ) );
810 el.setAttribute( QStringLiteral(
"serviceType" ), QgsVectorTileProviderConnection::settingsServiceType->value( connections[ i ] ) );
811 el.setAttribute( QStringLiteral(
"authcfg" ), QgsVectorTileProviderConnection::settingsAuthcfg->value( connections[ i ] ) );
812 el.setAttribute( QStringLiteral(
"username" ), QgsVectorTileProviderConnection::settingsUsername->value( connections[ i ] ) );
813 el.setAttribute( QStringLiteral(
"password" ), QgsVectorTileProviderConnection::settingsPassword->value( connections[ i ] ) );
814 el.setAttribute( QStringLiteral(
"styleUrl" ), QgsVectorTileProviderConnection::settingsStyleUrl->value( connections[ i ] ) );
816 QgsHttpHeaders httpHeader( QgsVectorTileProviderConnection::settingsHeaders->value( connections[ i ] ) );
817 httpHeader.updateDomElement( el );
819 root.appendChild( el );
825QDomDocument QgsManageConnectionsDialog::saveTiledSceneConnections(
const QStringList &connections )
827 QDomDocument doc( QStringLiteral(
"connections" ) );
828 QDomElement root = doc.createElement( QStringLiteral(
"qgsTiledSceneConnections" ) );
829 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
830 doc.appendChild( root );
832 for (
int i = 0; i < connections.count(); ++i )
834 QDomElement el = doc.createElement( QStringLiteral(
"tiledscene" ) );
836 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
837 el.setAttribute( QStringLiteral(
"provider" ), QgsTiledSceneProviderConnection::settingsProvider->value( connections[ i ] ) );
838 el.setAttribute( QStringLiteral(
"url" ), QgsTiledSceneProviderConnection::settingsUrl->value( connections[ i ] ) );
839 el.setAttribute( QStringLiteral(
"authcfg" ), QgsTiledSceneProviderConnection::settingsAuthcfg->value( connections[ i ] ) );
840 el.setAttribute( QStringLiteral(
"username" ), QgsTiledSceneProviderConnection::settingsUsername->value( connections[ i ] ) );
841 el.setAttribute( QStringLiteral(
"password" ), QgsTiledSceneProviderConnection::settingsPassword->value( connections[ i ] ) );
843 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[ i ] ) );
844 httpHeader.updateDomElement( el );
846 root.appendChild( el );
852QDomDocument QgsManageConnectionsDialog::saveSensorThingsConnections(
const QStringList &connections )
854 QDomDocument doc( QStringLiteral(
"connections" ) );
855 QDomElement root = doc.createElement( QStringLiteral(
"qgsSensorThingsConnections" ) );
856 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
857 doc.appendChild( root );
859 for (
int i = 0; i < connections.count(); ++i )
861 QDomElement el = doc.createElement( QStringLiteral(
"sensorthings" ) );
863 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
864 el.setAttribute( QStringLiteral(
"url" ), QgsSensorThingsProviderConnection::settingsUrl->value( connections[ i ] ) );
865 el.setAttribute( QStringLiteral(
"authcfg" ), QgsSensorThingsProviderConnection::settingsAuthcfg->value( connections[ i ] ) );
866 el.setAttribute( QStringLiteral(
"username" ), QgsSensorThingsProviderConnection::settingsUsername->value( connections[ i ] ) );
867 el.setAttribute( QStringLiteral(
"password" ), QgsSensorThingsProviderConnection::settingsPassword->value( connections[ i ] ) );
869 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[ i ] ) );
870 httpHeader.updateDomElement( el );
872 root.appendChild( el );
879QDomDocument QgsManageConnectionsDialog::saveCloudStorageConnections(
const QStringList &connections )
881 QDomDocument doc( QStringLiteral(
"connections" ) );
882 QDomElement root = doc.createElement( QStringLiteral(
"qgsCloudStorageConnections" ) );
883 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
884 doc.appendChild( root );
886 for (
int i = 0; i < connections.count(); ++i )
888 QDomElement el = doc.createElement( QStringLiteral(
"cloudstorage" ) );
890 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
891 el.setAttribute( QStringLiteral(
"handler" ), QgsGdalCloudProviderConnection::settingsVsiHandler->value( connections[ i ] ) );
892 el.setAttribute( QStringLiteral(
"container" ), QgsGdalCloudProviderConnection::settingsContainer->value( connections[ i ] ) );
893 el.setAttribute( QStringLiteral(
"path" ), QgsGdalCloudProviderConnection::settingsPath->value( connections[ i ] ) );
895 const QVariantMap credentialOptions = QgsGdalCloudProviderConnection::settingsCredentialOptions->value( connections[ i ] );
896 QString credentialString;
897 for (
auto it = credentialOptions.constBegin(); it != credentialOptions.constEnd(); ++it )
899 if ( !it.value().toString().isEmpty() )
901 credentialString += QStringLiteral(
"|credential:%1=%2" ).arg( it.key(), it.value().toString() );
904 el.setAttribute( QStringLiteral(
"credentials" ), credentialString );
906 root.appendChild( el );
912QDomDocument QgsManageConnectionsDialog::saveStacConnections(
const QStringList &connections )
914 QDomDocument doc( QStringLiteral(
"connections" ) );
915 QDomElement root = doc.createElement( QStringLiteral(
"qgsStacConnections" ) );
916 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
917 doc.appendChild( root );
919 for (
int i = 0; i < connections.count(); ++i )
921 QDomElement el = doc.createElement( QStringLiteral(
"stac" ) );
923 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
924 el.setAttribute( QStringLiteral(
"url" ), QgsStacConnection::settingsUrl->value( connections[ i ] ) );
925 el.setAttribute( QStringLiteral(
"authcfg" ), QgsStacConnection::settingsAuthcfg->value( connections[ i ] ) );
926 el.setAttribute( QStringLiteral(
"username" ), QgsStacConnection::settingsUsername->value( connections[ i ] ) );
927 el.setAttribute( QStringLiteral(
"password" ), QgsStacConnection::settingsPassword->value( connections[ i ] ) );
929 QgsHttpHeaders httpHeader( QgsStacConnection::settingsHeaders->value( connections[ i ] ) );
930 httpHeader.updateDomElement( el );
932 root.appendChild( el );
938void QgsManageConnectionsDialog::loadOWSConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
940 const QDomElement root = doc.documentElement();
941 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
943 QMessageBox::information(
this, tr(
"Loading Connections" ),
944 tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
948 QString connectionName;
950 QDomElement child = root.firstChildElement();
952 bool overwrite =
true;
954 while ( !child.isNull() )
956 connectionName = child.attribute( QStringLiteral(
"name" ) );
957 if ( !items.contains( connectionName ) )
959 child = child.nextSiblingElement();
966 const int res = QMessageBox::warning(
this,
967 tr(
"Loading Connections" ),
968 tr(
"Connection with name '%1' already exists. Overwrite?" )
969 .arg( connectionName ),
970 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
974 case QMessageBox::Cancel:
976 case QMessageBox::No:
977 child = child.nextSiblingElement();
979 case QMessageBox::Yes:
982 case QMessageBox::YesToAll:
986 case QMessageBox::NoToAll:
995 child = child.nextSiblingElement();
1011 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
1016 child = child.nextSiblingElement();
1020void QgsManageConnectionsDialog::loadWfsConnections(
const QDomDocument &doc,
const QStringList &items )
1022 const QDomElement root = doc.documentElement();
1023 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
1025 QMessageBox::information(
this, tr(
"Loading Connections" ),
1026 tr(
"The file is not a WFS connections exchange file." ) );
1030 QString connectionName;
1033 QDomElement child = root.firstChildElement();
1035 bool overwrite =
true;
1037 while ( !child.isNull() )
1039 connectionName = child.attribute( QStringLiteral(
"name" ) );
1040 if ( !items.contains( connectionName ) )
1042 child = child.nextSiblingElement();
1047 if ( keys.contains( connectionName ) && prompt )
1049 const int res = QMessageBox::warning(
this,
1050 tr(
"Loading Connections" ),
1051 tr(
"Connection with name '%1' already exists. Overwrite?" )
1052 .arg( connectionName ),
1053 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1057 case QMessageBox::Cancel:
1059 case QMessageBox::No:
1060 child = child.nextSiblingElement();
1062 case QMessageBox::Yes:
1065 case QMessageBox::YesToAll:
1069 case QMessageBox::NoToAll:
1076 if ( keys.contains( connectionName ) )
1080 child = child.nextSiblingElement();
1086 keys << connectionName;
1099 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
1104 child = child.nextSiblingElement();
1108void QgsManageConnectionsDialog::loadPgConnections(
const QDomDocument &doc,
const QStringList &items )
1110 const QDomElement root = doc.documentElement();
1111 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
1113 QMessageBox::information(
this,
1114 tr(
"Loading Connections" ),
1115 tr(
"The file is not a PostGIS connections exchange file." ) );
1119 QString connectionName;
1121 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
1124 QDomElement child = root.firstChildElement();
1126 bool overwrite =
true;
1128 while ( !child.isNull() )
1130 connectionName = child.attribute( QStringLiteral(
"name" ) );
1131 if ( !items.contains( connectionName ) )
1133 child = child.nextSiblingElement();
1138 if ( keys.contains( connectionName ) && prompt )
1140 const int res = QMessageBox::warning(
this,
1141 tr(
"Loading Connections" ),
1142 tr(
"Connection with name '%1' already exists. Overwrite?" )
1143 .arg( connectionName ),
1144 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1147 case QMessageBox::Cancel:
1149 case QMessageBox::No:
1150 child = child.nextSiblingElement();
1152 case QMessageBox::Yes:
1155 case QMessageBox::YesToAll:
1159 case QMessageBox::NoToAll:
1166 if ( keys.contains( connectionName ) )
1170 child = child.nextSiblingElement();
1176 keys << connectionName;
1180 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
1182 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1183 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1184 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1185 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1187 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1191 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1193 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1194 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1195 settings.
setValue( QStringLiteral(
"/projectsInDatabase" ), child.attribute( QStringLiteral(
"projectsInDatabase" ), 0 ) );
1196 settings.
setValue( QStringLiteral(
"/dontResolveType" ), child.attribute( QStringLiteral(
"dontResolveType" ), 0 ) );
1197 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ), 0 ) );
1198 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ), 0 ) );
1199 settings.
setValue( QStringLiteral(
"/publicOnly" ), child.attribute( QStringLiteral(
"publicOnly" ), 0 ) );
1200 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1201 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1202 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1203 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1206 child = child.nextSiblingElement();
1210void QgsManageConnectionsDialog::loadMssqlConnections(
const QDomDocument &doc,
const QStringList &items )
1212 const QDomElement root = doc.documentElement();
1213 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
1215 QMessageBox::information(
this,
1216 tr(
"Loading Connections" ),
1217 tr(
"The file is not a MS SQL Server connections exchange file." ) );
1221 QString connectionName;
1223 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
1226 QDomElement child = root.firstChildElement();
1228 bool overwrite =
true;
1230 while ( !child.isNull() )
1232 connectionName = child.attribute( QStringLiteral(
"name" ) );
1233 if ( !items.contains( connectionName ) )
1235 child = child.nextSiblingElement();
1240 if ( keys.contains( connectionName ) && prompt )
1242 const int res = QMessageBox::warning(
this,
1243 tr(
"Loading Connections" ),
1244 tr(
"Connection with name '%1' already exists. Overwrite?" )
1245 .arg( connectionName ),
1246 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1249 case QMessageBox::Cancel:
1251 case QMessageBox::No:
1252 child = child.nextSiblingElement();
1254 case QMessageBox::Yes:
1257 case QMessageBox::YesToAll:
1261 case QMessageBox::NoToAll:
1268 if ( keys.contains( connectionName ) )
1272 child = child.nextSiblingElement();
1278 keys << connectionName;
1282 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
1284 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1285 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1286 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1287 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1289 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1293 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1295 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1296 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1297 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1298 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1299 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1300 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1303 child = child.nextSiblingElement();
1307void QgsManageConnectionsDialog::loadOracleConnections(
const QDomDocument &doc,
const QStringList &items )
1309 const QDomElement root = doc.documentElement();
1310 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
1312 QMessageBox::information(
this,
1313 tr(
"Loading Connections" ),
1314 tr(
"The file is not an Oracle connections exchange file." ) );
1318 QString connectionName;
1320 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
1323 QDomElement child = root.firstChildElement();
1325 bool overwrite =
true;
1327 while ( !child.isNull() )
1329 connectionName = child.attribute( QStringLiteral(
"name" ) );
1330 if ( !items.contains( connectionName ) )
1332 child = child.nextSiblingElement();
1337 if ( keys.contains( connectionName ) && prompt )
1339 const int res = QMessageBox::warning(
this,
1340 tr(
"Loading Connections" ),
1341 tr(
"Connection with name '%1' already exists. Overwrite?" )
1342 .arg( connectionName ),
1343 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1346 case QMessageBox::Cancel:
1348 case QMessageBox::No:
1349 child = child.nextSiblingElement();
1351 case QMessageBox::Yes:
1354 case QMessageBox::YesToAll:
1358 case QMessageBox::NoToAll:
1365 if ( keys.contains( connectionName ) )
1369 child = child.nextSiblingElement();
1375 keys << connectionName;
1379 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
1381 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1382 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1383 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1384 settings.
setValue( QStringLiteral(
"/dboptions" ), child.attribute( QStringLiteral(
"dboptions" ) ) );
1385 settings.
setValue( QStringLiteral(
"/dbworkspace" ), child.attribute( QStringLiteral(
"dbworkspace" ) ) );
1386 settings.
setValue( QStringLiteral(
"/schema" ), child.attribute( QStringLiteral(
"schema" ) ) );
1387 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1388 settings.
setValue( QStringLiteral(
"/userTablesOnly" ), child.attribute( QStringLiteral(
"userTablesOnly" ) ) );
1389 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ) ) );
1390 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ) ) );
1391 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1392 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1393 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1394 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1397 child = child.nextSiblingElement();
1401void QgsManageConnectionsDialog::loadHanaConnections(
const QDomDocument &doc,
const QStringList &items )
1403 QDomElement root = doc.documentElement();
1404 if ( root.tagName() != QLatin1String(
"qgsHanaConnections" ) )
1406 QMessageBox::warning(
this,
1407 tr(
"Loading Connections" ),
1408 tr(
"The file is not a HANA connections exchange file." ) );
1412 const QDomAttr version = root.attributeNode(
"version" );
1413 if ( version.value() != QLatin1String(
"1.0" ) )
1415 QMessageBox::warning(
this,
1416 tr(
"Loading Connections" ),
1417 tr(
"The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1422 settings.
beginGroup( QStringLiteral(
"/HANA/connections" ) );
1425 QDomElement child = root.firstChildElement();
1427 bool overwrite =
true;
1429 while ( !child.isNull() )
1431 const QString connectionName = child.attribute( QStringLiteral(
"name" ) );
1432 if ( !items.contains( connectionName ) )
1434 child = child.nextSiblingElement();
1439 if ( keys.contains( connectionName ) && prompt )
1441 const int res = QMessageBox::warning(
this,
1442 tr(
"Loading Connections" ),
1443 tr(
"Connection with name '%1' already exists. Overwrite?" )
1444 .arg( connectionName ),
1445 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1448 case QMessageBox::Cancel:
1450 case QMessageBox::No:
1451 child = child.nextSiblingElement();
1453 case QMessageBox::Yes:
1456 case QMessageBox::YesToAll:
1460 case QMessageBox::NoToAll:
1467 if ( keys.contains( connectionName ) )
1471 child = child.nextSiblingElement();
1477 keys << connectionName;
1481 settings.
beginGroup(
"/HANA/connections/" + connectionName );
1483 for (
const QString param :
1484 {
"driver",
"host",
"database",
"identifierType",
"identifier",
"multitenant",
"schema",
"userTablesOnly",
1485 "allowGeometrylessTables",
"saveUsername",
"username",
"savePassword",
"password",
"sslEnabled",
1486 "sslCryptoProvider",
"sslKeyStore",
"sslTrustStore",
"sslValidateCertificate",
"sslHostNameInCertificate"
1488 settings.
setValue( QStringLiteral(
"/" ) + param, child.attribute( param ) );
1492 child = child.nextSiblingElement();
1496void QgsManageConnectionsDialog::loadXyzTilesConnections(
const QDomDocument &doc,
const QStringList &items )
1498 const QDomElement root = doc.documentElement();
1499 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
1501 QMessageBox::information(
this, tr(
"Loading Connections" ),
1502 tr(
"The file is not a XYZ Tiles connections exchange file." ) );
1506 QString connectionName;
1508 QDomElement child = root.firstChildElement();
1510 bool overwrite =
true;
1512 while ( !child.isNull() )
1514 connectionName = child.attribute( QStringLiteral(
"name" ) );
1515 if ( !items.contains( connectionName ) )
1517 child = child.nextSiblingElement();
1522 if ( keys.contains( connectionName ) && prompt )
1524 const int res = QMessageBox::warning(
this,
1525 tr(
"Loading Connections" ),
1526 tr(
"Connection with name '%1' already exists. Overwrite?" )
1527 .arg( connectionName ),
1528 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1532 case QMessageBox::Cancel:
1534 case QMessageBox::No:
1535 child = child.nextSiblingElement();
1537 case QMessageBox::Yes:
1540 case QMessageBox::YesToAll:
1544 case QMessageBox::NoToAll:
1551 if ( keys.contains( connectionName ) )
1555 child = child.nextSiblingElement();
1561 keys << connectionName;
1576 child = child.nextSiblingElement();
1580void QgsManageConnectionsDialog::loadArcgisConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
1582 const QDomElement root = doc.documentElement();
1583 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
1585 QMessageBox::information(
this, tr(
"Loading Connections" ),
1586 tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
1590 QString connectionName;
1592 QDomElement child = root.firstChildElement();
1594 bool overwrite =
true;
1596 while ( !child.isNull() )
1598 connectionName = child.attribute( QStringLiteral(
"name" ) );
1599 if ( !items.contains( connectionName ) )
1601 child = child.nextSiblingElement();
1606 if ( keys.contains( connectionName ) && prompt )
1608 const int res = QMessageBox::warning(
this,
1609 tr(
"Loading Connections" ),
1610 tr(
"Connection with name '%1' already exists. Overwrite?" )
1611 .arg( connectionName ),
1612 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1616 case QMessageBox::Cancel:
1618 case QMessageBox::No:
1619 child = child.nextSiblingElement();
1621 case QMessageBox::Yes:
1624 case QMessageBox::YesToAll:
1628 case QMessageBox::NoToAll:
1635 if ( keys.contains( connectionName ) )
1639 child = child.nextSiblingElement();
1645 keys << connectionName;
1658 child = child.nextSiblingElement();
1662void QgsManageConnectionsDialog::loadVectorTileConnections(
const QDomDocument &doc,
const QStringList &items )
1664 const QDomElement root = doc.documentElement();
1665 if ( root.tagName() != QLatin1String(
"qgsVectorTileConnections" ) )
1667 QMessageBox::information(
this, tr(
"Loading Connections" ),
1668 tr(
"The file is not a Vector Tile connections exchange file." ) );
1672 QString connectionName;
1674 settings.
beginGroup( QStringLiteral(
"/qgis/connections-vector-tile" ) );
1677 QDomElement child = root.firstChildElement();
1679 bool overwrite =
true;
1681 while ( !child.isNull() )
1683 connectionName = child.attribute( QStringLiteral(
"name" ) );
1684 if ( !items.contains( connectionName ) )
1686 child = child.nextSiblingElement();
1691 if ( keys.contains( connectionName ) && prompt )
1693 const int res = QMessageBox::warning(
this,
1694 tr(
"Loading Connections" ),
1695 tr(
"Connection with name '%1' already exists. Overwrite?" )
1696 .arg( connectionName ),
1697 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1701 case QMessageBox::Cancel:
1703 case QMessageBox::No:
1704 child = child.nextSiblingElement();
1706 case QMessageBox::Yes:
1709 case QMessageBox::YesToAll:
1713 case QMessageBox::NoToAll:
1720 if ( keys.contains( connectionName ) )
1724 child = child.nextSiblingElement();
1730 keys << connectionName;
1733 QgsVectorTileProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1734 QgsVectorTileProviderConnection::settingsZmin->setValue( child.attribute( QStringLiteral(
"zmin" ) ).toInt(), connectionName );
1735 QgsVectorTileProviderConnection::settingsZmax->setValue( child.attribute( QStringLiteral(
"zmax" ) ).toInt(), connectionName );
1736 QgsVectorTileProviderConnection::settingsServiceType->setValue( child.attribute( QStringLiteral(
"serviceType" ) ), connectionName );
1737 QgsVectorTileProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1738 QgsVectorTileProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1739 QgsVectorTileProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1740 QgsVectorTileProviderConnection::settingsStyleUrl->setValue( child.attribute( QStringLiteral(
"styleUrl" ) ), connectionName );
1743 QgsVectorTileProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1745 child = child.nextSiblingElement();
1749void QgsManageConnectionsDialog::loadTiledSceneConnections(
const QDomDocument &doc,
const QStringList &items )
1751 const QDomElement root = doc.documentElement();
1752 if ( root.tagName() != QLatin1String(
"qgsTiledSceneConnections" ) )
1754 QMessageBox::information(
this, tr(
"Loading Connections" ),
1755 tr(
"The file is not a tiled scene connections exchange file." ) );
1759 QString connectionName;
1761 settings.
beginGroup( QStringLiteral(
"/qgis/connections-tiled-scene" ) );
1764 QDomElement child = root.firstChildElement();
1766 bool overwrite =
true;
1768 while ( !child.isNull() )
1770 connectionName = child.attribute( QStringLiteral(
"name" ) );
1771 if ( !items.contains( connectionName ) )
1773 child = child.nextSiblingElement();
1778 if ( keys.contains( connectionName ) && prompt )
1780 const int res = QMessageBox::warning(
this,
1781 tr(
"Loading Connections" ),
1782 tr(
"Connection with name '%1' already exists. Overwrite?" )
1783 .arg( connectionName ),
1784 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1788 case QMessageBox::Cancel:
1790 case QMessageBox::No:
1791 child = child.nextSiblingElement();
1793 case QMessageBox::Yes:
1796 case QMessageBox::YesToAll:
1800 case QMessageBox::NoToAll:
1807 if ( keys.contains( connectionName ) )
1811 child = child.nextSiblingElement();
1817 keys << connectionName;
1820 QgsTiledSceneProviderConnection::settingsProvider->setValue( child.attribute( QStringLiteral(
"provider" ) ), connectionName );
1821 QgsTiledSceneProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1822 QgsTiledSceneProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1823 QgsTiledSceneProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1824 QgsTiledSceneProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1827 QgsTiledSceneProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1829 child = child.nextSiblingElement();
1833void QgsManageConnectionsDialog::loadSensorThingsConnections(
const QDomDocument &doc,
const QStringList &items )
1835 const QDomElement root = doc.documentElement();
1836 if ( root.tagName() != QLatin1String(
"qgsSensorThingsConnections" ) )
1838 QMessageBox::information(
this, tr(
"Loading Connections" ),
1839 tr(
"The file is not a SensorThings connections exchange file." ) );
1843 QString connectionName;
1845 settings.
beginGroup( QStringLiteral(
"/connections/sensorthings/items" ) );
1848 QDomElement child = root.firstChildElement();
1850 bool overwrite =
true;
1852 while ( !child.isNull() )
1854 connectionName = child.attribute( QStringLiteral(
"name" ) );
1855 if ( !items.contains( connectionName ) )
1857 child = child.nextSiblingElement();
1862 if ( keys.contains( connectionName ) && prompt )
1864 const int res = QMessageBox::warning(
this,
1865 tr(
"Loading Connections" ),
1866 tr(
"Connection with name '%1' already exists. Overwrite?" )
1867 .arg( connectionName ),
1868 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1872 case QMessageBox::Cancel:
1874 case QMessageBox::No:
1875 child = child.nextSiblingElement();
1877 case QMessageBox::Yes:
1880 case QMessageBox::YesToAll:
1884 case QMessageBox::NoToAll:
1891 if ( keys.contains( connectionName ) )
1895 child = child.nextSiblingElement();
1901 keys << connectionName;
1904 QgsSensorThingsProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1905 QgsSensorThingsProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1906 QgsSensorThingsProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1907 QgsSensorThingsProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1910 QgsSensorThingsProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1912 child = child.nextSiblingElement();
1916void QgsManageConnectionsDialog::loadCloudStorageConnections(
const QDomDocument &doc,
const QStringList &items )
1918 const QDomElement root = doc.documentElement();
1919 if ( root.tagName() != QLatin1String(
"qgsCloudStorageConnections" ) )
1921 QMessageBox::information(
this, tr(
"Loading Connections" ),
1922 tr(
"The file is not a cloud storage connections exchange file." ) );
1926 QString connectionName;
1928 settings.
beginGroup( QStringLiteral(
"/connections/cloud/items" ) );
1931 QDomElement child = root.firstChildElement();
1933 bool overwrite =
true;
1935 while ( !child.isNull() )
1937 connectionName = child.attribute( QStringLiteral(
"name" ) );
1938 if ( !items.contains( connectionName ) )
1940 child = child.nextSiblingElement();
1945 if ( keys.contains( connectionName ) && prompt )
1947 const int res = QMessageBox::warning(
this,
1948 tr(
"Loading Connections" ),
1949 tr(
"Connection with name '%1' already exists. Overwrite?" )
1950 .arg( connectionName ),
1951 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1955 case QMessageBox::Cancel:
1957 case QMessageBox::No:
1958 child = child.nextSiblingElement();
1960 case QMessageBox::Yes:
1963 case QMessageBox::YesToAll:
1967 case QMessageBox::NoToAll:
1974 if ( keys.contains( connectionName ) )
1978 child = child.nextSiblingElement();
1984 keys << connectionName;
1987 QgsGdalCloudProviderConnection::settingsVsiHandler->setValue( child.attribute( QStringLiteral(
"handler" ) ), connectionName );
1988 QgsGdalCloudProviderConnection::settingsContainer->setValue( child.attribute( QStringLiteral(
"container" ) ), connectionName );
1989 QgsGdalCloudProviderConnection::settingsPath->setValue( child.attribute( QStringLiteral(
"path" ) ), connectionName );
1991 QString credentialString = child.attribute( QStringLiteral(
"credentials" ) );
1993 QVariantMap credentialOptions;
1996 const thread_local QRegularExpression credentialOptionRegex( QStringLiteral(
"\\|credential:([^|]*)" ) );
1997 const thread_local QRegularExpression credentialOptionKeyValueRegex( QStringLiteral(
"(.*?)=(.*)" ) );
1999 const QRegularExpressionMatch match = credentialOptionRegex.match( credentialString );
2000 if ( match.hasMatch() )
2002 const QRegularExpressionMatch keyValueMatch = credentialOptionKeyValueRegex.match( match.captured( 1 ) );
2003 if ( keyValueMatch.hasMatch() )
2005 credentialOptions.insert( keyValueMatch.captured( 1 ), keyValueMatch.captured( 2 ) );
2007 credentialString = credentialString.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) );
2015 QgsGdalCloudProviderConnection::settingsCredentialOptions->setValue( credentialOptions, connectionName );
2017 child = child.nextSiblingElement();
2021void QgsManageConnectionsDialog::loadStacConnections(
const QDomDocument &doc,
const QStringList &items )
2023 const QDomElement root = doc.documentElement();
2024 if ( root.tagName() != QLatin1String(
"qgsStacConnections" ) )
2026 QMessageBox::information(
this, tr(
"Loading Connections" ),
2027 tr(
"The file is not a STAC connections exchange file." ) );
2031 QString connectionName;
2033 settings.
beginGroup( QStringLiteral(
"/qgis/connections-stac" ) );
2036 QDomElement child = root.firstChildElement();
2038 bool overwrite =
true;
2040 while ( !child.isNull() )
2042 connectionName = child.attribute( QStringLiteral(
"name" ) );
2043 if ( !items.contains( connectionName ) )
2045 child = child.nextSiblingElement();
2050 if ( keys.contains( connectionName ) && prompt )
2052 const int res = QMessageBox::warning(
this,
2053 tr(
"Loading Connections" ),
2054 tr(
"Connection with name '%1' already exists. Overwrite?" )
2055 .arg( connectionName ),
2056 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
2060 case QMessageBox::Cancel:
2062 case QMessageBox::No:
2063 child = child.nextSiblingElement();
2065 case QMessageBox::Yes:
2068 case QMessageBox::YesToAll:
2072 case QMessageBox::NoToAll:
2079 if ( keys.contains( connectionName ) )
2083 child = child.nextSiblingElement();
2089 keys << connectionName;
2092 QgsStacConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
2093 QgsStacConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
2094 QgsStacConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
2095 QgsStacConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
2098 QgsStacConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
2100 child = child.nextSiblingElement();
2106 listConnections->selectAll();
2107 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
2112 listConnections->clearSelection();
2113 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryVariantMap * settingsHeaders
static QgsSettingsTreeNamedListNode * sTreeConnectionArcgis
static const QgsSettingsEntryString * settingsAuthcfg
QgsManageConnectionsDialog(QWidget *parent=nullptr, Mode mode=Export, Type type=WMS, const QString &fileName=QString())
Constructor for QgsManageConnectionsDialog.
@ STAC
SpatioTemporal Asset Catalog connections.
@ SensorThings
SensorThings connections.
@ TiledScene
Tiled scene connection.
@ CloudStorage
Cloud storage connections.
static const QgsSettingsEntryString * settingsPagingEnabled
static const QgsSettingsEntryString * settingsMaxNumFeatures
static QgsSettingsTreeNamedListNode * sTreeOwsConnections
static const QgsSettingsEntryBool * settingsIgnoreGetFeatureInfoURI
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryEnumFlag< Qgis::DpiMode > * settingsDpiMode
static const QgsSettingsEntryBool * settingsIgnoreAxisOrientation
static const QgsSettingsEntryBool * settingsInvertAxisOrientation
static const QgsSettingsEntryString * settingsVersion
static const QgsSettingsEntryString * settingsPagesize
static const QgsSettingsEntryVariantMap * settingsHeaders
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryBool * settingsSmoothPixmapTransform
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryBool * settingsIgnoreGetMapURI
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
QStringList items(const QStringList &parentsNamedItems=QStringList()) const
Returns the list of items.
This class is a composition of two QSettings instances:
QStringList childGroups(Qgis::SettingsOrigin origin=Qgis::SettingsOrigin::Any) const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
void endGroup()
Resets the group to what it was before the corresponding beginGroup() call.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static QgsSettingsTreeNamedListNode * sTreeXyzConnections
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryDouble * settingsTilePixelRatio
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryString * settingsAuthcfg
static const QgsSettingsEntryInteger * settingsZmin
static const QgsSettingsEntryInteger * settingsZmax
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryVariantMap * settingsHeaders