32#include "qgsgdalcloudconnection.h"
36 , mFileName( fileName )
38 , mConnectionType( type )
43 QPushButton *pb =
nullptr;
44 pb =
new QPushButton( tr(
"Select All" ) );
45 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
48 pb =
new QPushButton( tr(
"Clear Selection" ) );
49 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
52 if ( mDialogMode ==
Import )
54 label->setText( tr(
"Select connections to import" ) );
55 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Import" ) );
56 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
61 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Export" ) );
62 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
65 if ( !populateConnections() )
67 QApplication::postEvent(
this,
new QCloseEvent() );
71 disconnect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
79 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
84 const QList<QListWidgetItem *> selection = listConnections->selectedItems();
85 if ( selection.isEmpty() )
87 QMessageBox::warning(
this, tr(
"Export/Import Error" ),
88 tr(
"You should select at least one connection from list." ) );
93 items.reserve( selection.size() );
94 for (
int i = 0; i < selection.size(); ++i )
96 items.append( selection.at( i )->text() );
99 if ( mDialogMode ==
Export )
101 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save Connections" ), QDir::homePath(),
102 tr(
"XML files (*.xml *.XML)" ) );
106 if ( fileName.isEmpty() )
112 if ( !fileName.endsWith( QLatin1String(
".xml" ), Qt::CaseInsensitive ) )
114 fileName += QLatin1String(
".xml" );
117 mFileName = fileName;
120 switch ( mConnectionType )
123 doc = saveOWSConnections( items, QStringLiteral(
"WMS" ) );
126 doc = saveWfsConnections( items );
129 doc = savePgConnections( items );
132 doc = saveMssqlConnections( items );
135 doc = saveOWSConnections( items, QStringLiteral(
"WCS" ) );
138 doc = saveOracleConnections( items );
141 doc = saveHanaConnections( items );
144 doc = saveXyzTilesConnections( items );
148 doc = saveArcgisConnections( items );
151 doc = saveVectorTileConnections( items );
154 doc = saveTiledSceneConnections( items );
157 doc = saveSensorThingsConnections( items );
160 doc = saveCloudStorageConnections( items );
164 QFile file( mFileName );
165 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
167 QMessageBox::warning(
this, tr(
"Saving Connections" ),
168 tr(
"Cannot write file %1:\n%2." )
170 file.errorString() ) );
174 QTextStream out( &file );
179 QFile file( mFileName );
180 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
182 QMessageBox::warning(
this, tr(
"Loading Connections" ),
183 tr(
"Cannot read file %1:\n%2." )
185 file.errorString() ) );
194 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
196 QMessageBox::warning(
this, tr(
"Loading Connections" ),
197 tr(
"Parse error at line %1, column %2:\n%3" )
204 switch ( mConnectionType )
207 loadOWSConnections( doc, items, QStringLiteral(
"WMS" ) );
210 loadWfsConnections( doc, items );
213 loadPgConnections( doc, items );
216 loadMssqlConnections( doc, items );
219 loadOWSConnections( doc, items, QStringLiteral(
"WCS" ) );
222 loadOracleConnections( doc, items );
225 loadHanaConnections( doc, items );
228 loadXyzTilesConnections( doc, items );
231 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISMAPSERVER" ) );
234 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISFEATURESERVER" ) );
237 loadVectorTileConnections( doc, items );
240 loadTiledSceneConnections( doc, items );
243 loadSensorThingsConnections( doc, items );
246 loadCloudStorageConnections( doc, items );
250 listConnections->clear();
257bool QgsManageConnectionsDialog::populateConnections()
260 if ( mDialogMode ==
Export )
262 QStringList connections;
264 switch ( mConnectionType )
276 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
280 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
284 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
288 settings.
beginGroup( QStringLiteral(
"/HANA/connections" ) );
299 connections = QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
302 connections = QgsTiledSceneProviderConnection::sTreeConnectionTiledScene->items();
305 connections = QgsSensorThingsProviderConnection::sTreeSensorThingsConnections->items();
308 connections = QgsGdalCloudProviderConnection::sTreeConnectionCloud->items();
311 for (
const QString &connection : std::as_const( connections ) )
313 QListWidgetItem *item =
new QListWidgetItem();
314 item->setText( connection );
315 listConnections->addItem( item );
321 QFile file( mFileName );
322 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
324 QMessageBox::warning(
this, tr(
"Loading Connections" ),
325 tr(
"Cannot read file %1:\n%2." )
327 file.errorString() ) );
336 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
338 QMessageBox::warning(
this, tr(
"Loading Connections" ),
339 tr(
"Parse error at line %1, column %2:\n%3" )
346 const QDomElement root = doc.documentElement();
347 switch ( mConnectionType )
350 if ( root.tagName() != QLatin1String(
"qgsWMSConnections" ) )
352 QMessageBox::information(
this, tr(
"Loading Connections" ),
353 tr(
"The file is not a WMS connections exchange file." ) );
359 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
361 QMessageBox::information(
this, tr(
"Loading Connections" ),
362 tr(
"The file is not a WFS connections exchange file." ) );
368 if ( root.tagName() != QLatin1String(
"qgsWCSConnections" ) )
370 QMessageBox::information(
this, tr(
"Loading Connections" ),
371 tr(
"The file is not a WCS connections exchange file." ) );
377 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
379 QMessageBox::information(
this, tr(
"Loading Connections" ),
380 tr(
"The file is not a PostGIS connections exchange file." ) );
386 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
388 QMessageBox::information(
this, tr(
"Loading Connections" ),
389 tr(
"The file is not a MS SQL Server connections exchange file." ) );
394 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
396 QMessageBox::information(
this, tr(
"Loading Connections" ),
397 tr(
"The file is not an Oracle connections exchange file." ) );
402 if ( root.tagName() != QLatin1String(
"qgsHanaConnections" ) )
404 QMessageBox::warning(
this, tr(
"Loading Connections" ),
405 tr(
"The file is not a HANA connections exchange file." ) );
410 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
412 QMessageBox::information(
this, tr(
"Loading Connections" ),
413 tr(
"The file is not a XYZ Tiles connections exchange file." ) );
418 if ( root.tagName() != QLatin1String(
"qgsARCGISMAPSERVERConnections" ) )
420 QMessageBox::information(
this, tr(
"Loading Connections" ),
421 tr(
"The file is not a ArcGIS Map Service connections exchange file." ) );
426 if ( root.tagName() != QLatin1String(
"qgsARCGISFEATURESERVERConnections" ) )
428 QMessageBox::information(
this, tr(
"Loading Connections" ),
429 tr(
"The file is not a ArcGIS Feature Service connections exchange file." ) );
434 if ( root.tagName() != QLatin1String(
"qgsVectorTileConnections" ) )
436 QMessageBox::information(
this, tr(
"Loading Connections" ),
437 tr(
"The file is not a Vector Tile connections exchange file." ) );
442 if ( root.tagName() != QLatin1String(
"qgsTiledSceneConnections" ) )
444 QMessageBox::information(
this, tr(
"Loading Connections" ),
445 tr(
"The file is not a tiled scene connections exchange file." ) );
450 if ( root.tagName() != QLatin1String(
"qgsSensorThingsConnections" ) )
452 QMessageBox::information(
this, tr(
"Loading Connections" ),
453 tr(
"The file is not a SensorThings connections exchange file." ) );
458 if ( root.tagName() != QLatin1String(
"qgsCloudStorageConnections" ) )
460 QMessageBox::information(
this, tr(
"Loading Connections" ),
461 tr(
"The file is not a cloud storage connections exchange file." ) );
467 QDomElement child = root.firstChildElement();
468 while ( !child.isNull() )
470 QListWidgetItem *item =
new QListWidgetItem();
471 item->setText( child.attribute( QStringLiteral(
"name" ) ) );
472 listConnections->addItem( item );
473 child = child.nextSiblingElement();
479QDomDocument QgsManageConnectionsDialog::saveOWSConnections(
const QStringList &connections,
const QString &service )
481 QDomDocument doc( QStringLiteral(
"connections" ) );
482 QDomElement root = doc.createElement(
"qgs" + service.toUpper() +
"Connections" );
483 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
484 doc.appendChild( root );
486 for (
int i = 0; i < connections.count(); ++i )
488 QDomElement el = doc.createElement( service.toLower() );
489 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
492 if ( service == QLatin1String(
"WMS" ) )
502 httpHeader.updateDomElement( el );
507 root.appendChild( el );
513QDomDocument QgsManageConnectionsDialog::saveWfsConnections(
const QStringList &connections )
515 QDomDocument doc( QStringLiteral(
"connections" ) );
516 QDomElement root = doc.createElement( QStringLiteral(
"qgsWFSConnections" ) );
517 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.1" ) );
518 doc.appendChild( root );
520 for (
int i = 0; i < connections.count(); ++i )
522 QDomElement el = doc.createElement( QStringLiteral(
"wfs" ) );
523 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
534 root.appendChild( el );
540QDomDocument QgsManageConnectionsDialog::savePgConnections(
const QStringList &connections )
542 QDomDocument doc( QStringLiteral(
"connections" ) );
543 QDomElement root = doc.createElement( QStringLiteral(
"qgsPgConnections" ) );
544 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
545 doc.appendChild( root );
549 for (
int i = 0; i < connections.count(); ++i )
551 path =
"/PostgreSQL/connections/" + connections[ i ];
552 QDomElement el = doc.createElement( QStringLiteral(
"postgis" ) );
553 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
554 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
555 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
556 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
557 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
558 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
559 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
560 el.setAttribute( QStringLiteral(
"projectsInDatabase" ), settings.
value( path +
"/projectsInDatabase",
"0" ).toString() );
561 el.setAttribute( QStringLiteral(
"dontResolveType" ), settings.
value( path +
"/dontResolveType",
"0" ).toString() );
562 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
563 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
564 el.setAttribute( QStringLiteral(
"publicOnly" ), settings.
value( path +
"/publicOnly",
"0" ).toString() );
566 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
568 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
570 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
573 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
575 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
577 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
580 root.appendChild( el );
586QDomDocument QgsManageConnectionsDialog::saveMssqlConnections(
const QStringList &connections )
588 QDomDocument doc( QStringLiteral(
"connections" ) );
589 QDomElement root = doc.createElement( QStringLiteral(
"qgsMssqlConnections" ) );
590 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
591 doc.appendChild( root );
595 for (
int i = 0; i < connections.count(); ++i )
597 path =
"/MSSQL/connections/" + connections[ i ];
598 QDomElement el = doc.createElement( QStringLiteral(
"mssql" ) );
599 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
600 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
601 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
602 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
603 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
604 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
605 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
607 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
609 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
611 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
614 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
616 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
618 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
621 root.appendChild( el );
627QDomDocument QgsManageConnectionsDialog::saveOracleConnections(
const QStringList &connections )
629 QDomDocument doc( QStringLiteral(
"connections" ) );
630 QDomElement root = doc.createElement( QStringLiteral(
"qgsOracleConnections" ) );
631 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
632 doc.appendChild( root );
636 for (
int i = 0; i < connections.count(); ++i )
638 path =
"/Oracle/connections/" + connections[ i ];
639 QDomElement el = doc.createElement( QStringLiteral(
"oracle" ) );
640 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
641 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
642 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
643 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
644 el.setAttribute( QStringLiteral(
"dboptions" ), settings.
value( path +
"/dboptions" ).toString() );
645 el.setAttribute( QStringLiteral(
"dbworkspace" ), settings.
value( path +
"/dbworkspace" ).toString() );
646 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema" ).toString() );
647 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
648 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly",
"0" ).toString() );
649 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
650 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
652 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
654 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
656 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
659 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
661 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
663 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
666 root.appendChild( el );
672QDomDocument QgsManageConnectionsDialog::saveHanaConnections(
const QStringList &connections )
674 QDomDocument doc( QStringLiteral(
"connections" ) );
675 QDomElement root = doc.createElement( QStringLiteral(
"qgsHanaConnections" ) );
676 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
677 doc.appendChild( root );
681 for (
int i = 0; i < connections.count(); ++i )
683 path =
"/HANA/connections/" + connections[i];
684 QDomElement el = doc.createElement( QStringLiteral(
"hana" ) );
685 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
686 el.setAttribute( QStringLiteral(
"driver" ), settings.
value( path +
"/driver", QString() ).toString() );
687 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host", QString() ).toString() );
688 el.setAttribute( QStringLiteral(
"identifierType" ), settings.
value( path +
"/identifierType", QString() ).toString() );
689 el.setAttribute( QStringLiteral(
"identifier" ), settings.
value( path +
"/identifier", QString() ).toString() );
690 el.setAttribute( QStringLiteral(
"multitenant" ), settings.
value( path +
"/multitenant", QString() ).toString() );
691 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database", QString() ).toString() );
692 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema", QString() ).toString() );
693 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly", QStringLiteral(
"0" ) ).toString() );
694 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables", QStringLiteral(
"0" ) ).toString() );
696 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername", QStringLiteral(
"false" ) ).toString() );
697 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
699 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username", QString() ).toString() );
702 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword", QStringLiteral(
"false" ) ).toString() );
703 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
705 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password", QString() ).toString() );
708 el.setAttribute( QStringLiteral(
"sslEnabled" ), settings.
value( path +
"/sslEnabled", QStringLiteral(
"false" ) ).toString() );
709 el.setAttribute( QStringLiteral(
"sslCryptoProvider" ), settings.
value( path +
"/sslCryptoProvider", QStringLiteral(
"openssl" ) ).toString() );
710 el.setAttribute( QStringLiteral(
"sslKeyStore" ), settings.
value( path +
"/sslKeyStore", QString() ).toString() );
711 el.setAttribute( QStringLiteral(
"sslTrustStore" ), settings.
value( path +
"/sslTrustStore", QString() ).toString() );
712 el.setAttribute( QStringLiteral(
"sslValidateCertificate" ), settings.
value( path +
"/sslValidateCertificate", QStringLiteral(
"false" ) ).toString() );
713 el.setAttribute( QStringLiteral(
"sslHostNameInCertificate" ), settings.
value( path +
"/sslHostNameInCertificate", QString() ).toString() );
715 root.appendChild( el );
721QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections(
const QStringList &connections )
723 QDomDocument doc( QStringLiteral(
"connections" ) );
724 QDomElement root = doc.createElement( QStringLiteral(
"qgsXYZTilesConnections" ) );
725 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
726 doc.appendChild( root );
728 for (
int i = 0; i < connections.count(); ++i )
731 QDomElement el = doc.createElement( QStringLiteral(
"xyztiles" ) );
733 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
743 httpHeader.updateDomElement( el );
745 root.appendChild( el );
751QDomDocument QgsManageConnectionsDialog::saveArcgisConnections(
const QStringList &connections )
753 QDomDocument doc( QStringLiteral(
"connections" ) );
754 QDomElement root = doc.createElement(
"qgsARCGISFEATURESERVERConnections" );
755 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
756 doc.appendChild( root );
758 for (
const QString &connection : connections )
760 QDomElement el = doc.createElement( QStringLiteral(
"arcgisfeatureserver" ) );
761 el.setAttribute( QStringLiteral(
"name" ), connection );
765 httpHeader.updateDomElement( el );
771 root.appendChild( el );
777QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections(
const QStringList &connections )
779 QDomDocument doc( QStringLiteral(
"connections" ) );
780 QDomElement root = doc.createElement( QStringLiteral(
"qgsVectorTileConnections" ) );
781 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
782 doc.appendChild( root );
784 for (
int i = 0; i < connections.count(); ++i )
786 QDomElement el = doc.createElement( QStringLiteral(
"vectortile" ) );
788 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
789 el.setAttribute( QStringLiteral(
"url" ), QgsVectorTileProviderConnection::settingsUrl->value( connections[ i ] ) );
790 el.setAttribute( QStringLiteral(
"zmin" ), QgsVectorTileProviderConnection::settingsZmin->value( connections[ i ] ) );
791 el.setAttribute( QStringLiteral(
"zmax" ), QgsVectorTileProviderConnection::settingsZmax->value( connections[ i ] ) );
792 el.setAttribute( QStringLiteral(
"serviceType" ), QgsVectorTileProviderConnection::settingsServiceType->value( connections[ i ] ) );
793 el.setAttribute( QStringLiteral(
"authcfg" ), QgsVectorTileProviderConnection::settingsAuthcfg->value( connections[ i ] ) );
794 el.setAttribute( QStringLiteral(
"username" ), QgsVectorTileProviderConnection::settingsUsername->value( connections[ i ] ) );
795 el.setAttribute( QStringLiteral(
"password" ), QgsVectorTileProviderConnection::settingsPassword->value( connections[ i ] ) );
796 el.setAttribute( QStringLiteral(
"styleUrl" ), QgsVectorTileProviderConnection::settingsStyleUrl->value( connections[ i ] ) );
798 QgsHttpHeaders httpHeader( QgsVectorTileProviderConnection::settingsHeaders->value( connections[ i ] ) );
799 httpHeader.updateDomElement( el );
801 root.appendChild( el );
807QDomDocument QgsManageConnectionsDialog::saveTiledSceneConnections(
const QStringList &connections )
809 QDomDocument doc( QStringLiteral(
"connections" ) );
810 QDomElement root = doc.createElement( QStringLiteral(
"qgsTiledSceneConnections" ) );
811 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
812 doc.appendChild( root );
814 for (
int i = 0; i < connections.count(); ++i )
816 QDomElement el = doc.createElement( QStringLiteral(
"tiledscene" ) );
818 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
819 el.setAttribute( QStringLiteral(
"provider" ), QgsTiledSceneProviderConnection::settingsProvider->value( connections[ i ] ) );
820 el.setAttribute( QStringLiteral(
"url" ), QgsTiledSceneProviderConnection::settingsUrl->value( connections[ i ] ) );
821 el.setAttribute( QStringLiteral(
"authcfg" ), QgsTiledSceneProviderConnection::settingsAuthcfg->value( connections[ i ] ) );
822 el.setAttribute( QStringLiteral(
"username" ), QgsTiledSceneProviderConnection::settingsUsername->value( connections[ i ] ) );
823 el.setAttribute( QStringLiteral(
"password" ), QgsTiledSceneProviderConnection::settingsPassword->value( connections[ i ] ) );
825 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[ i ] ) );
826 httpHeader.updateDomElement( el );
828 root.appendChild( el );
834QDomDocument QgsManageConnectionsDialog::saveSensorThingsConnections(
const QStringList &connections )
836 QDomDocument doc( QStringLiteral(
"connections" ) );
837 QDomElement root = doc.createElement( QStringLiteral(
"qgsSensorThingsConnections" ) );
838 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
839 doc.appendChild( root );
841 for (
int i = 0; i < connections.count(); ++i )
843 QDomElement el = doc.createElement( QStringLiteral(
"sensorthings" ) );
845 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
846 el.setAttribute( QStringLiteral(
"url" ), QgsSensorThingsProviderConnection::settingsUrl->value( connections[ i ] ) );
847 el.setAttribute( QStringLiteral(
"authcfg" ), QgsSensorThingsProviderConnection::settingsAuthcfg->value( connections[ i ] ) );
848 el.setAttribute( QStringLiteral(
"username" ), QgsSensorThingsProviderConnection::settingsUsername->value( connections[ i ] ) );
849 el.setAttribute( QStringLiteral(
"password" ), QgsSensorThingsProviderConnection::settingsPassword->value( connections[ i ] ) );
851 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[ i ] ) );
852 httpHeader.updateDomElement( el );
854 root.appendChild( el );
861QDomDocument QgsManageConnectionsDialog::saveCloudStorageConnections(
const QStringList &connections )
863 QDomDocument doc( QStringLiteral(
"connections" ) );
864 QDomElement root = doc.createElement( QStringLiteral(
"qgsCloudStorageConnections" ) );
865 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
866 doc.appendChild( root );
868 for (
int i = 0; i < connections.count(); ++i )
870 QDomElement el = doc.createElement( QStringLiteral(
"cloudstorage" ) );
872 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
873 el.setAttribute( QStringLiteral(
"handler" ), QgsGdalCloudProviderConnection::settingsVsiHandler->value( connections[ i ] ) );
874 el.setAttribute( QStringLiteral(
"container" ), QgsGdalCloudProviderConnection::settingsContainer->value( connections[ i ] ) );
875 el.setAttribute( QStringLiteral(
"path" ), QgsGdalCloudProviderConnection::settingsPath->value( connections[ i ] ) );
877 const QVariantMap credentialOptions = QgsGdalCloudProviderConnection::settingsCredentialOptions->value( connections[ i ] );
878 QString credentialString;
879 for (
auto it = credentialOptions.constBegin(); it != credentialOptions.constEnd(); ++it )
881 if ( !it.value().toString().isEmpty() )
883 credentialString += QStringLiteral(
"|credential:%1=%2" ).arg( it.key(), it.value().toString() );
886 el.setAttribute( QStringLiteral(
"credentials" ), credentialString );
888 root.appendChild( el );
894void QgsManageConnectionsDialog::loadOWSConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
896 const QDomElement root = doc.documentElement();
897 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
899 QMessageBox::information(
this, tr(
"Loading Connections" ),
900 tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
904 QString connectionName;
906 QDomElement child = root.firstChildElement();
908 bool overwrite =
true;
910 while ( !child.isNull() )
912 connectionName = child.attribute( QStringLiteral(
"name" ) );
913 if ( !items.contains( connectionName ) )
915 child = child.nextSiblingElement();
922 const int res = QMessageBox::warning(
this,
923 tr(
"Loading Connections" ),
924 tr(
"Connection with name '%1' already exists. Overwrite?" )
925 .arg( connectionName ),
926 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
930 case QMessageBox::Cancel:
932 case QMessageBox::No:
933 child = child.nextSiblingElement();
935 case QMessageBox::Yes:
938 case QMessageBox::YesToAll:
942 case QMessageBox::NoToAll:
951 child = child.nextSiblingElement();
967 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
972 child = child.nextSiblingElement();
976void QgsManageConnectionsDialog::loadWfsConnections(
const QDomDocument &doc,
const QStringList &items )
978 const QDomElement root = doc.documentElement();
979 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
981 QMessageBox::information(
this, tr(
"Loading Connections" ),
982 tr(
"The file is not a WFS connections exchange file." ) );
986 QString connectionName;
989 QDomElement child = root.firstChildElement();
991 bool overwrite =
true;
993 while ( !child.isNull() )
995 connectionName = child.attribute( QStringLiteral(
"name" ) );
996 if ( !items.contains( connectionName ) )
998 child = child.nextSiblingElement();
1003 if ( keys.contains( connectionName ) && prompt )
1005 const int res = QMessageBox::warning(
this,
1006 tr(
"Loading Connections" ),
1007 tr(
"Connection with name '%1' already exists. Overwrite?" )
1008 .arg( connectionName ),
1009 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1013 case QMessageBox::Cancel:
1015 case QMessageBox::No:
1016 child = child.nextSiblingElement();
1018 case QMessageBox::Yes:
1021 case QMessageBox::YesToAll:
1025 case QMessageBox::NoToAll:
1032 if ( keys.contains( connectionName ) )
1036 child = child.nextSiblingElement();
1042 keys << connectionName;
1055 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
1060 child = child.nextSiblingElement();
1064void QgsManageConnectionsDialog::loadPgConnections(
const QDomDocument &doc,
const QStringList &items )
1066 const QDomElement root = doc.documentElement();
1067 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
1069 QMessageBox::information(
this,
1070 tr(
"Loading Connections" ),
1071 tr(
"The file is not a PostGIS connections exchange file." ) );
1075 QString connectionName;
1077 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
1080 QDomElement child = root.firstChildElement();
1082 bool overwrite =
true;
1084 while ( !child.isNull() )
1086 connectionName = child.attribute( QStringLiteral(
"name" ) );
1087 if ( !items.contains( connectionName ) )
1089 child = child.nextSiblingElement();
1094 if ( keys.contains( connectionName ) && prompt )
1096 const int res = QMessageBox::warning(
this,
1097 tr(
"Loading Connections" ),
1098 tr(
"Connection with name '%1' already exists. Overwrite?" )
1099 .arg( connectionName ),
1100 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1103 case QMessageBox::Cancel:
1105 case QMessageBox::No:
1106 child = child.nextSiblingElement();
1108 case QMessageBox::Yes:
1111 case QMessageBox::YesToAll:
1115 case QMessageBox::NoToAll:
1122 if ( keys.contains( connectionName ) )
1126 child = child.nextSiblingElement();
1132 keys << connectionName;
1136 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
1138 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1139 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1140 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1141 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1143 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1147 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1149 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1150 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1151 settings.
setValue( QStringLiteral(
"/projectsInDatabase" ), child.attribute( QStringLiteral(
"projectsInDatabase" ), 0 ) );
1152 settings.
setValue( QStringLiteral(
"/dontResolveType" ), child.attribute( QStringLiteral(
"dontResolveType" ), 0 ) );
1153 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ), 0 ) );
1154 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ), 0 ) );
1155 settings.
setValue( QStringLiteral(
"/publicOnly" ), child.attribute( QStringLiteral(
"publicOnly" ), 0 ) );
1156 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1157 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1158 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1159 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1162 child = child.nextSiblingElement();
1166void QgsManageConnectionsDialog::loadMssqlConnections(
const QDomDocument &doc,
const QStringList &items )
1168 const QDomElement root = doc.documentElement();
1169 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
1171 QMessageBox::information(
this,
1172 tr(
"Loading Connections" ),
1173 tr(
"The file is not a MS SQL Server connections exchange file." ) );
1177 QString connectionName;
1179 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
1182 QDomElement child = root.firstChildElement();
1184 bool overwrite =
true;
1186 while ( !child.isNull() )
1188 connectionName = child.attribute( QStringLiteral(
"name" ) );
1189 if ( !items.contains( connectionName ) )
1191 child = child.nextSiblingElement();
1196 if ( keys.contains( connectionName ) && prompt )
1198 const int res = QMessageBox::warning(
this,
1199 tr(
"Loading Connections" ),
1200 tr(
"Connection with name '%1' already exists. Overwrite?" )
1201 .arg( connectionName ),
1202 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1205 case QMessageBox::Cancel:
1207 case QMessageBox::No:
1208 child = child.nextSiblingElement();
1210 case QMessageBox::Yes:
1213 case QMessageBox::YesToAll:
1217 case QMessageBox::NoToAll:
1224 if ( keys.contains( connectionName ) )
1228 child = child.nextSiblingElement();
1234 keys << connectionName;
1238 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
1240 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1241 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1242 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1243 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1245 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1249 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1251 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1252 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1253 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1254 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1255 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1256 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1259 child = child.nextSiblingElement();
1263void QgsManageConnectionsDialog::loadOracleConnections(
const QDomDocument &doc,
const QStringList &items )
1265 const QDomElement root = doc.documentElement();
1266 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
1268 QMessageBox::information(
this,
1269 tr(
"Loading Connections" ),
1270 tr(
"The file is not an Oracle connections exchange file." ) );
1274 QString connectionName;
1276 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
1279 QDomElement child = root.firstChildElement();
1281 bool overwrite =
true;
1283 while ( !child.isNull() )
1285 connectionName = child.attribute( QStringLiteral(
"name" ) );
1286 if ( !items.contains( connectionName ) )
1288 child = child.nextSiblingElement();
1293 if ( keys.contains( connectionName ) && prompt )
1295 const int res = QMessageBox::warning(
this,
1296 tr(
"Loading Connections" ),
1297 tr(
"Connection with name '%1' already exists. Overwrite?" )
1298 .arg( connectionName ),
1299 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1302 case QMessageBox::Cancel:
1304 case QMessageBox::No:
1305 child = child.nextSiblingElement();
1307 case QMessageBox::Yes:
1310 case QMessageBox::YesToAll:
1314 case QMessageBox::NoToAll:
1321 if ( keys.contains( connectionName ) )
1325 child = child.nextSiblingElement();
1331 keys << connectionName;
1335 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
1337 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1338 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1339 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1340 settings.
setValue( QStringLiteral(
"/dboptions" ), child.attribute( QStringLiteral(
"dboptions" ) ) );
1341 settings.
setValue( QStringLiteral(
"/dbworkspace" ), child.attribute( QStringLiteral(
"dbworkspace" ) ) );
1342 settings.
setValue( QStringLiteral(
"/schema" ), child.attribute( QStringLiteral(
"schema" ) ) );
1343 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1344 settings.
setValue( QStringLiteral(
"/userTablesOnly" ), child.attribute( QStringLiteral(
"userTablesOnly" ) ) );
1345 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ) ) );
1346 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ) ) );
1347 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1348 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1349 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1350 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1353 child = child.nextSiblingElement();
1357void QgsManageConnectionsDialog::loadHanaConnections(
const QDomDocument &doc,
const QStringList &items )
1359 QDomElement root = doc.documentElement();
1360 if ( root.tagName() != QLatin1String(
"qgsHanaConnections" ) )
1362 QMessageBox::warning(
this,
1363 tr(
"Loading Connections" ),
1364 tr(
"The file is not a HANA connections exchange file." ) );
1368 const QDomAttr version = root.attributeNode(
"version" );
1369 if ( version.value() != QLatin1String(
"1.0" ) )
1371 QMessageBox::warning(
this,
1372 tr(
"Loading Connections" ),
1373 tr(
"The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1378 settings.
beginGroup( QStringLiteral(
"/HANA/connections" ) );
1381 QDomElement child = root.firstChildElement();
1383 bool overwrite =
true;
1385 while ( !child.isNull() )
1387 const QString connectionName = child.attribute( QStringLiteral(
"name" ) );
1388 if ( !items.contains( connectionName ) )
1390 child = child.nextSiblingElement();
1395 if ( keys.contains( connectionName ) && prompt )
1397 const int res = QMessageBox::warning(
this,
1398 tr(
"Loading Connections" ),
1399 tr(
"Connection with name '%1' already exists. Overwrite?" )
1400 .arg( connectionName ),
1401 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1404 case QMessageBox::Cancel:
1406 case QMessageBox::No:
1407 child = child.nextSiblingElement();
1409 case QMessageBox::Yes:
1412 case QMessageBox::YesToAll:
1416 case QMessageBox::NoToAll:
1423 if ( keys.contains( connectionName ) )
1427 child = child.nextSiblingElement();
1433 keys << connectionName;
1437 settings.
beginGroup(
"/HANA/connections/" + connectionName );
1439 for (
const QString param :
1440 {
"driver",
"host",
"database",
"identifierType",
"identifier",
"multitenant",
"schema",
"userTablesOnly",
1441 "allowGeometrylessTables",
"saveUsername",
"username",
"savePassword",
"password",
"sslEnabled",
1442 "sslCryptoProvider",
"sslKeyStore",
"sslTrustStore",
"sslValidateCertificate",
"sslHostNameInCertificate"
1444 settings.
setValue( QStringLiteral(
"/" ) + param, child.attribute( param ) );
1448 child = child.nextSiblingElement();
1452void QgsManageConnectionsDialog::loadXyzTilesConnections(
const QDomDocument &doc,
const QStringList &items )
1454 const QDomElement root = doc.documentElement();
1455 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
1457 QMessageBox::information(
this, tr(
"Loading Connections" ),
1458 tr(
"The file is not a XYZ Tiles connections exchange file." ) );
1462 QString connectionName;
1464 QDomElement child = root.firstChildElement();
1466 bool overwrite =
true;
1468 while ( !child.isNull() )
1470 connectionName = child.attribute( QStringLiteral(
"name" ) );
1471 if ( !items.contains( connectionName ) )
1473 child = child.nextSiblingElement();
1478 if ( keys.contains( connectionName ) && prompt )
1480 const int res = QMessageBox::warning(
this,
1481 tr(
"Loading Connections" ),
1482 tr(
"Connection with name '%1' already exists. Overwrite?" )
1483 .arg( connectionName ),
1484 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1488 case QMessageBox::Cancel:
1490 case QMessageBox::No:
1491 child = child.nextSiblingElement();
1493 case QMessageBox::Yes:
1496 case QMessageBox::YesToAll:
1500 case QMessageBox::NoToAll:
1507 if ( keys.contains( connectionName ) )
1511 child = child.nextSiblingElement();
1517 keys << connectionName;
1532 child = child.nextSiblingElement();
1536void QgsManageConnectionsDialog::loadArcgisConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
1538 const QDomElement root = doc.documentElement();
1539 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
1541 QMessageBox::information(
this, tr(
"Loading Connections" ),
1542 tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
1546 QString connectionName;
1548 QDomElement child = root.firstChildElement();
1550 bool overwrite =
true;
1552 while ( !child.isNull() )
1554 connectionName = child.attribute( QStringLiteral(
"name" ) );
1555 if ( !items.contains( connectionName ) )
1557 child = child.nextSiblingElement();
1562 if ( keys.contains( connectionName ) && prompt )
1564 const int res = QMessageBox::warning(
this,
1565 tr(
"Loading Connections" ),
1566 tr(
"Connection with name '%1' already exists. Overwrite?" )
1567 .arg( connectionName ),
1568 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1572 case QMessageBox::Cancel:
1574 case QMessageBox::No:
1575 child = child.nextSiblingElement();
1577 case QMessageBox::Yes:
1580 case QMessageBox::YesToAll:
1584 case QMessageBox::NoToAll:
1591 if ( keys.contains( connectionName ) )
1595 child = child.nextSiblingElement();
1601 keys << connectionName;
1614 child = child.nextSiblingElement();
1618void QgsManageConnectionsDialog::loadVectorTileConnections(
const QDomDocument &doc,
const QStringList &items )
1620 const QDomElement root = doc.documentElement();
1621 if ( root.tagName() != QLatin1String(
"qgsVectorTileConnections" ) )
1623 QMessageBox::information(
this, tr(
"Loading Connections" ),
1624 tr(
"The file is not a Vector Tile connections exchange file." ) );
1628 QString connectionName;
1630 settings.
beginGroup( QStringLiteral(
"/qgis/connections-vector-tile" ) );
1633 QDomElement child = root.firstChildElement();
1635 bool overwrite =
true;
1637 while ( !child.isNull() )
1639 connectionName = child.attribute( QStringLiteral(
"name" ) );
1640 if ( !items.contains( connectionName ) )
1642 child = child.nextSiblingElement();
1647 if ( keys.contains( connectionName ) && prompt )
1649 const int res = QMessageBox::warning(
this,
1650 tr(
"Loading Connections" ),
1651 tr(
"Connection with name '%1' already exists. Overwrite?" )
1652 .arg( connectionName ),
1653 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1657 case QMessageBox::Cancel:
1659 case QMessageBox::No:
1660 child = child.nextSiblingElement();
1662 case QMessageBox::Yes:
1665 case QMessageBox::YesToAll:
1669 case QMessageBox::NoToAll:
1676 if ( keys.contains( connectionName ) )
1680 child = child.nextSiblingElement();
1686 keys << connectionName;
1689 QgsVectorTileProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1690 QgsVectorTileProviderConnection::settingsZmin->setValue( child.attribute( QStringLiteral(
"zmin" ) ).toInt(), connectionName );
1691 QgsVectorTileProviderConnection::settingsZmax->setValue( child.attribute( QStringLiteral(
"zmax" ) ).toInt(), connectionName );
1692 QgsVectorTileProviderConnection::settingsServiceType->setValue( child.attribute( QStringLiteral(
"serviceType" ) ), connectionName );
1693 QgsVectorTileProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1694 QgsVectorTileProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1695 QgsVectorTileProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1696 QgsVectorTileProviderConnection::settingsStyleUrl->setValue( child.attribute( QStringLiteral(
"styleUrl" ) ), connectionName );
1699 QgsVectorTileProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1701 child = child.nextSiblingElement();
1705void QgsManageConnectionsDialog::loadTiledSceneConnections(
const QDomDocument &doc,
const QStringList &items )
1707 const QDomElement root = doc.documentElement();
1708 if ( root.tagName() != QLatin1String(
"qgsTiledSceneConnections" ) )
1710 QMessageBox::information(
this, tr(
"Loading Connections" ),
1711 tr(
"The file is not a tiled scene connections exchange file." ) );
1715 QString connectionName;
1717 settings.
beginGroup( QStringLiteral(
"/qgis/connections-tiled-scene" ) );
1720 QDomElement child = root.firstChildElement();
1722 bool overwrite =
true;
1724 while ( !child.isNull() )
1726 connectionName = child.attribute( QStringLiteral(
"name" ) );
1727 if ( !items.contains( connectionName ) )
1729 child = child.nextSiblingElement();
1734 if ( keys.contains( connectionName ) && prompt )
1736 const int res = QMessageBox::warning(
this,
1737 tr(
"Loading Connections" ),
1738 tr(
"Connection with name '%1' already exists. Overwrite?" )
1739 .arg( connectionName ),
1740 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1744 case QMessageBox::Cancel:
1746 case QMessageBox::No:
1747 child = child.nextSiblingElement();
1749 case QMessageBox::Yes:
1752 case QMessageBox::YesToAll:
1756 case QMessageBox::NoToAll:
1763 if ( keys.contains( connectionName ) )
1767 child = child.nextSiblingElement();
1773 keys << connectionName;
1776 QgsTiledSceneProviderConnection::settingsProvider->setValue( child.attribute( QStringLiteral(
"provider" ) ), connectionName );
1777 QgsTiledSceneProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1778 QgsTiledSceneProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1779 QgsTiledSceneProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1780 QgsTiledSceneProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1783 QgsTiledSceneProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1785 child = child.nextSiblingElement();
1789void QgsManageConnectionsDialog::loadSensorThingsConnections(
const QDomDocument &doc,
const QStringList &items )
1791 const QDomElement root = doc.documentElement();
1792 if ( root.tagName() != QLatin1String(
"qgsSensorThingsConnections" ) )
1794 QMessageBox::information(
this, tr(
"Loading Connections" ),
1795 tr(
"The file is not a SensorThings connections exchange file." ) );
1799 QString connectionName;
1801 settings.
beginGroup( QStringLiteral(
"/connections/sensorthings/items" ) );
1804 QDomElement child = root.firstChildElement();
1806 bool overwrite =
true;
1808 while ( !child.isNull() )
1810 connectionName = child.attribute( QStringLiteral(
"name" ) );
1811 if ( !items.contains( connectionName ) )
1813 child = child.nextSiblingElement();
1818 if ( keys.contains( connectionName ) && prompt )
1820 const int res = QMessageBox::warning(
this,
1821 tr(
"Loading Connections" ),
1822 tr(
"Connection with name '%1' already exists. Overwrite?" )
1823 .arg( connectionName ),
1824 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1828 case QMessageBox::Cancel:
1830 case QMessageBox::No:
1831 child = child.nextSiblingElement();
1833 case QMessageBox::Yes:
1836 case QMessageBox::YesToAll:
1840 case QMessageBox::NoToAll:
1847 if ( keys.contains( connectionName ) )
1851 child = child.nextSiblingElement();
1857 keys << connectionName;
1860 QgsSensorThingsProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1861 QgsSensorThingsProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1862 QgsSensorThingsProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1863 QgsSensorThingsProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1866 QgsSensorThingsProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1868 child = child.nextSiblingElement();
1872void QgsManageConnectionsDialog::loadCloudStorageConnections(
const QDomDocument &doc,
const QStringList &items )
1874 const QDomElement root = doc.documentElement();
1875 if ( root.tagName() != QLatin1String(
"qgsCloudStorageConnections" ) )
1877 QMessageBox::information(
this, tr(
"Loading Connections" ),
1878 tr(
"The file is not a cloud storage connections exchange file." ) );
1882 QString connectionName;
1884 settings.
beginGroup( QStringLiteral(
"/connections/cloud/items" ) );
1887 QDomElement child = root.firstChildElement();
1889 bool overwrite =
true;
1891 while ( !child.isNull() )
1893 connectionName = child.attribute( QStringLiteral(
"name" ) );
1894 if ( !items.contains( connectionName ) )
1896 child = child.nextSiblingElement();
1901 if ( keys.contains( connectionName ) && prompt )
1903 const int res = QMessageBox::warning(
this,
1904 tr(
"Loading Connections" ),
1905 tr(
"Connection with name '%1' already exists. Overwrite?" )
1906 .arg( connectionName ),
1907 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1911 case QMessageBox::Cancel:
1913 case QMessageBox::No:
1914 child = child.nextSiblingElement();
1916 case QMessageBox::Yes:
1919 case QMessageBox::YesToAll:
1923 case QMessageBox::NoToAll:
1930 if ( keys.contains( connectionName ) )
1934 child = child.nextSiblingElement();
1940 keys << connectionName;
1943 QgsGdalCloudProviderConnection::settingsVsiHandler->setValue( child.attribute( QStringLiteral(
"handler" ) ), connectionName );
1944 QgsGdalCloudProviderConnection::settingsContainer->setValue( child.attribute( QStringLiteral(
"container" ) ), connectionName );
1945 QgsGdalCloudProviderConnection::settingsPath->setValue( child.attribute( QStringLiteral(
"path" ) ), connectionName );
1947 QString credentialString = child.attribute( QStringLiteral(
"credentials" ) );
1949 QVariantMap credentialOptions;
1952 const thread_local QRegularExpression credentialOptionRegex( QStringLiteral(
"\\|credential:([^|]*)" ) );
1953 const thread_local QRegularExpression credentialOptionKeyValueRegex( QStringLiteral(
"(.*?)=(.*)" ) );
1955 const QRegularExpressionMatch match = credentialOptionRegex.match( credentialString );
1956 if ( match.hasMatch() )
1958 const QRegularExpressionMatch keyValueMatch = credentialOptionKeyValueRegex.match( match.captured( 1 ) );
1959 if ( keyValueMatch.hasMatch() )
1961 credentialOptions.insert( keyValueMatch.captured( 1 ), keyValueMatch.captured( 2 ) );
1963 credentialString = credentialString.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) );
1971 QgsGdalCloudProviderConnection::settingsCredentialOptions->setValue( credentialOptions, connectionName );
1973 child = child.nextSiblingElement();
1979 listConnections->selectAll();
1980 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
1985 listConnections->clearSelection();
1986 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.
@ 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