17 #include <QCloseEvent>
18 #include <QFileDialog>
19 #include <QMessageBox>
20 #include <QPushButton>
21 #include <QTextStream>
29 , mFileName( fileName )
31 , mConnectionType( type )
36 QPushButton *pb =
nullptr;
37 pb =
new QPushButton( tr(
"Select all" ) );
38 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
41 pb =
new QPushButton( tr(
"Clear selection" ) );
42 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
45 if ( mDialogMode ==
Import )
47 label->setText( tr(
"Select connections to import" ) );
48 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Import" ) );
49 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
54 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Export" ) );
55 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
58 if ( !populateConnections() )
60 QApplication::postEvent(
this,
new QCloseEvent() );
64 disconnect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
72 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
77 const QList<QListWidgetItem *> selection = listConnections->selectedItems();
78 if ( selection.isEmpty() )
80 QMessageBox::warning(
this, tr(
"Export/Import Error" ),
81 tr(
"You should select at least one connection from list." ) );
86 items.reserve( selection.size() );
87 for (
int i = 0; i < selection.size(); ++i )
89 items.append( selection.at( i )->text() );
92 if ( mDialogMode ==
Export )
94 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save Connections" ), QDir::homePath(),
95 tr(
"XML files (*.xml *.XML)" ) );
96 if ( fileName.isEmpty() )
102 if ( !fileName.endsWith( QLatin1String(
".xml" ), Qt::CaseInsensitive ) )
104 fileName += QLatin1String(
".xml" );
107 mFileName = fileName;
110 switch ( mConnectionType )
113 doc = saveOWSConnections( items, QStringLiteral(
"WMS" ) );
116 doc = saveWfsConnections( items );
119 doc = savePgConnections( items );
122 doc = saveMssqlConnections( items );
125 doc = saveOWSConnections( items, QStringLiteral(
"WCS" ) );
128 doc = saveOracleConnections( items );
131 doc = saveDb2Connections( items );
134 doc = saveHanaConnections( items );
137 doc = saveGeonodeConnections( items );
140 doc = saveXyzTilesConnections( items );
143 doc = saveArcgisConnections( items, QStringLiteral(
"ARCGISMAPSERVER" ) );
146 doc = saveArcgisConnections( items, QStringLiteral(
"ARCGISFEATURESERVER" ) );
149 doc = saveVectorTileConnections( items );
153 QFile file( mFileName );
154 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
156 QMessageBox::warning(
this, tr(
"Saving Connections" ),
157 tr(
"Cannot write file %1:\n%2." )
159 file.errorString() ) );
163 QTextStream out( &file );
168 QFile file( mFileName );
169 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
171 QMessageBox::warning(
this, tr(
"Loading Connections" ),
172 tr(
"Cannot read file %1:\n%2." )
174 file.errorString() ) );
183 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
185 QMessageBox::warning(
this, tr(
"Loading Connections" ),
186 tr(
"Parse error at line %1, column %2:\n%3" )
193 switch ( mConnectionType )
196 loadOWSConnections( doc, items, QStringLiteral(
"WMS" ) );
199 loadWfsConnections( doc, items );
202 loadPgConnections( doc, items );
205 loadMssqlConnections( doc, items );
208 loadOWSConnections( doc, items, QStringLiteral(
"WCS" ) );
211 loadOracleConnections( doc, items );
214 loadDb2Connections( doc, items );
217 loadHanaConnections( doc, items );
220 loadGeonodeConnections( doc, items );
223 loadXyzTilesConnections( doc, items );
226 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISMAPSERVER" ) );
229 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISFEATURESERVER" ) );
232 loadVectorTileConnections( doc, items );
236 listConnections->clear();
243 bool QgsManageConnectionsDialog::populateConnections()
246 if ( mDialogMode ==
Export )
249 switch ( mConnectionType )
252 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wms" ) );
255 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
258 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wcs" ) );
261 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
264 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
267 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
270 settings.
beginGroup( QStringLiteral(
"/DB2/connections" ) );
273 settings.
beginGroup( QStringLiteral(
"/HANA/connections" ) );
276 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
279 settings.
beginGroup( QStringLiteral(
"/qgis/connections-xyz" ) );
282 settings.
beginGroup( QStringLiteral(
"/qgis/connections-arcgismapserver" ) );
285 settings.
beginGroup( QStringLiteral(
"/qgis/connections-arcgisfeatureserver" ) );
288 settings.
beginGroup( QStringLiteral(
"/qgis/connections-vector-tile" ) );
292 QStringList::Iterator it = keys.begin();
293 while ( it != keys.end() )
295 QListWidgetItem *item =
new QListWidgetItem();
296 item->setText( *it );
297 listConnections->addItem( item );
305 QFile file( mFileName );
306 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
308 QMessageBox::warning(
this, tr(
"Loading Connections" ),
309 tr(
"Cannot read file %1:\n%2." )
311 file.errorString() ) );
320 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
322 QMessageBox::warning(
this, tr(
"Loading Connections" ),
323 tr(
"Parse error at line %1, column %2:\n%3" )
330 const QDomElement root = doc.documentElement();
331 switch ( mConnectionType )
334 if ( root.tagName() != QLatin1String(
"qgsWMSConnections" ) )
336 QMessageBox::information(
this, tr(
"Loading Connections" ),
337 tr(
"The file is not a WMS connections exchange file." ) );
343 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
345 QMessageBox::information(
this, tr(
"Loading Connections" ),
346 tr(
"The file is not a WFS connections exchange file." ) );
352 if ( root.tagName() != QLatin1String(
"qgsWCSConnections" ) )
354 QMessageBox::information(
this, tr(
"Loading Connections" ),
355 tr(
"The file is not a WCS connections exchange file." ) );
361 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
363 QMessageBox::information(
this, tr(
"Loading Connections" ),
364 tr(
"The file is not a PostGIS connections exchange file." ) );
370 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
372 QMessageBox::information(
this, tr(
"Loading Connections" ),
373 tr(
"The file is not a MSSQL connections exchange file." ) );
378 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
380 QMessageBox::information(
this, tr(
"Loading Connections" ),
381 tr(
"The file is not an Oracle connections exchange file." ) );
386 if ( root.tagName() != QLatin1String(
"qgsDb2Connections" ) )
388 QMessageBox::information(
this, tr(
"Loading Connections" ),
389 tr(
"The file is not a DB2 connections exchange file." ) );
394 if ( root.tagName() != QLatin1String(
"qgsHanaConnections" ) )
396 QMessageBox::warning(
this, tr(
"Loading Connections" ),
397 tr(
"The file is not a HANA connections exchange file." ) );
402 if ( root.tagName() != QLatin1String(
"qgsGeoNodeConnections" ) )
404 QMessageBox::information(
this, tr(
"Loading Connections" ),
405 tr(
"The file is not a GeoNode 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." ) );
443 QDomElement child = root.firstChildElement();
444 while ( !child.isNull() )
446 QListWidgetItem *item =
new QListWidgetItem();
447 item->setText( child.attribute( QStringLiteral(
"name" ) ) );
448 listConnections->addItem( item );
449 child = child.nextSiblingElement();
455 QDomDocument QgsManageConnectionsDialog::saveOWSConnections(
const QStringList &connections,
const QString &service )
457 QDomDocument doc( QStringLiteral(
"connections" ) );
458 QDomElement root = doc.createElement(
"qgs" + service.toUpper() +
"Connections" );
459 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
460 doc.appendChild( root );
464 for (
int i = 0; i < connections.count(); ++i )
466 path =
"/qgis/connections-" + service.toLower() +
'/';
467 QDomElement el = doc.createElement( service.toLower() );
468 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
469 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url" ).toString() );
471 if ( service == QLatin1String(
"WMS" ) )
473 el.setAttribute( QStringLiteral(
"ignoreGetMapURI" ), settings.
value( path + connections[i] +
"/ignoreGetMapURI",
false ).toBool() ?
"true" :
"false" );
474 el.setAttribute( QStringLiteral(
"ignoreGetFeatureInfoURI" ), settings.
value( path + connections[i] +
"/ignoreGetFeatureInfoURI",
false ).toBool() ?
"true" :
"false" );
475 el.setAttribute( QStringLiteral(
"ignoreAxisOrientation" ), settings.
value( path + connections[i] +
"/ignoreAxisOrientation",
false ).toBool() ?
"true" :
"false" );
476 el.setAttribute( QStringLiteral(
"invertAxisOrientation" ), settings.
value( path + connections[i] +
"/invertAxisOrientation",
false ).toBool() ?
"true" :
"false" );
477 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path + connections[ i ] +
"/referer" ).toString() );
478 el.setAttribute( QStringLiteral(
"smoothPixmapTransform" ), settings.
value( path + connections[i] +
"/smoothPixmapTransform",
false ).toBool() ?
"true" :
"false" );
479 el.setAttribute( QStringLiteral(
"dpiMode" ), settings.
value( path + connections[i] +
"/dpiMode",
"7" ).toInt() );
482 path =
"/qgis/" + service.toUpper() +
'/';
483 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username" ).toString() );
484 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password" ).toString() );
485 root.appendChild( el );
491 QDomDocument QgsManageConnectionsDialog::saveWfsConnections(
const QStringList &connections )
493 QDomDocument doc( QStringLiteral(
"connections" ) );
494 QDomElement root = doc.createElement( QStringLiteral(
"qgsWFSConnections" ) );
495 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.1" ) );
496 doc.appendChild( root );
500 for (
int i = 0; i < connections.count(); ++i )
502 path = QStringLiteral(
"/qgis/connections-wfs/" );
503 QDomElement el = doc.createElement( QStringLiteral(
"wfs" ) );
504 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
505 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url" ).toString() );
507 el.setAttribute( QStringLiteral(
"version" ), settings.
value( path + connections[ i ] +
"/version" ).toString() );
508 el.setAttribute( QStringLiteral(
"maxnumfeatures" ), settings.
value( path + connections[ i ] +
"/maxnumfeatures" ).toString() );
509 el.setAttribute( QStringLiteral(
"pagesize" ), settings.
value( path + connections[ i ] +
"/pagesize" ).toString() );
510 el.setAttribute( QStringLiteral(
"pagingenabled" ), settings.
value( path + connections[ i ] +
"/pagingenabled",
false ).toString() );
511 el.setAttribute( QStringLiteral(
"ignoreAxisOrientation" ), settings.
value( path + connections[ i ] +
"/ignoreAxisOrientation",
false ).toString() );
512 el.setAttribute( QStringLiteral(
"invertAxisOrientation" ), settings.
value( path + connections[ i ] +
"/invertAxisOrientation",
false ).toString() );
514 path = QStringLiteral(
"/qgis/WFS/" );
515 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username" ).toString() );
516 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password" ).toString() );
517 root.appendChild( el );
523 QDomDocument QgsManageConnectionsDialog::savePgConnections(
const QStringList &connections )
525 QDomDocument doc( QStringLiteral(
"connections" ) );
526 QDomElement root = doc.createElement( QStringLiteral(
"qgsPgConnections" ) );
527 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
528 doc.appendChild( root );
532 for (
int i = 0; i < connections.count(); ++i )
534 path =
"/PostgreSQL/connections/" + connections[ i ];
535 QDomElement el = doc.createElement( QStringLiteral(
"postgis" ) );
536 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
537 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
538 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
539 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
540 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
541 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
542 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
543 el.setAttribute( QStringLiteral(
"projectsInDatabase" ), settings.
value( path +
"/projectsInDatabase",
"0" ).toString() );
545 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
547 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
549 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
552 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
554 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
556 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
559 root.appendChild( el );
565 QDomDocument QgsManageConnectionsDialog::saveMssqlConnections(
const QStringList &connections )
567 QDomDocument doc( QStringLiteral(
"connections" ) );
568 QDomElement root = doc.createElement( QStringLiteral(
"qgsMssqlConnections" ) );
569 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
570 doc.appendChild( root );
574 for (
int i = 0; i < connections.count(); ++i )
576 path =
"/MSSQL/connections/" + connections[ i ];
577 QDomElement el = doc.createElement( QStringLiteral(
"mssql" ) );
578 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
579 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
580 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
581 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
582 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
583 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
584 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
586 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
588 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
590 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
593 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
595 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
597 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
600 root.appendChild( el );
606 QDomDocument QgsManageConnectionsDialog::saveOracleConnections(
const QStringList &connections )
608 QDomDocument doc( QStringLiteral(
"connections" ) );
609 QDomElement root = doc.createElement( QStringLiteral(
"qgsOracleConnections" ) );
610 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
611 doc.appendChild( root );
615 for (
int i = 0; i < connections.count(); ++i )
617 path =
"/Oracle/connections/" + connections[ i ];
618 QDomElement el = doc.createElement( QStringLiteral(
"oracle" ) );
619 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
620 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
621 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
622 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
623 el.setAttribute( QStringLiteral(
"dboptions" ), settings.
value( path +
"/dboptions" ).toString() );
624 el.setAttribute( QStringLiteral(
"dbworkspace" ), settings.
value( path +
"/dbworkspace" ).toString() );
625 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema" ).toString() );
626 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
627 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly",
"0" ).toString() );
628 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
629 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
631 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
633 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
635 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
638 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
640 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
642 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
645 root.appendChild( el );
651 QDomDocument QgsManageConnectionsDialog::saveDb2Connections(
const QStringList &connections )
653 QDomDocument doc( QStringLiteral(
"connections" ) );
654 QDomElement root = doc.createElement( QStringLiteral(
"qgsDb2Connections" ) );
655 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
656 doc.appendChild( root );
660 for (
int i = 0; i < connections.count(); ++i )
662 path =
"/DB2/connections/" + connections[ i ];
663 QDomElement el = doc.createElement( QStringLiteral(
"db2" ) );
664 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
665 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
666 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
667 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
668 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
669 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
670 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
672 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
674 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
676 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
679 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
681 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
683 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
686 root.appendChild( el );
692 QDomDocument QgsManageConnectionsDialog::saveHanaConnections(
const QStringList &connections )
694 QDomDocument doc( QStringLiteral(
"connections" ) );
695 QDomElement root = doc.createElement( QStringLiteral(
"qgsHanaConnections" ) );
696 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
697 doc.appendChild( root );
701 for (
int i = 0; i < connections.count(); ++i )
703 path =
"/HANA/connections/" + connections[i];
704 QDomElement el = doc.createElement( QStringLiteral(
"hana" ) );
705 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
706 el.setAttribute( QStringLiteral(
"driver" ), settings.
value( path +
"/driver", QString() ).toString() );
707 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host", QString() ).toString() );
708 el.setAttribute( QStringLiteral(
"identifierType" ), settings.
value( path +
"/identifierType", QString() ).toString() );
709 el.setAttribute( QStringLiteral(
"identifier" ), settings.
value( path +
"/identifier", QString() ).toString() );
710 el.setAttribute( QStringLiteral(
"multitenant" ), settings.
value( path +
"/multitenant", QString() ).toString() );
711 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database", QString() ).toString() );
712 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema", QString() ).toString() );
713 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly", QStringLiteral(
"0" ) ).toString() );
714 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables", QStringLiteral(
"0" ) ).toString() );
716 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername", QStringLiteral(
"false" ) ).toString() );
717 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
719 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username", QString() ).toString() );
722 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword", QStringLiteral(
"false" ) ).toString() );
723 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
725 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password", QString() ).toString() );
728 el.setAttribute( QStringLiteral(
"sslEnabled" ), settings.
value( path +
"/sslEnabled", QStringLiteral(
"false" ) ).toString() );
729 el.setAttribute( QStringLiteral(
"sslCryptoProvider" ), settings.
value( path +
"/sslCryptoProvider", QStringLiteral(
"openssl" ) ).toString() );
730 el.setAttribute( QStringLiteral(
"sslKeyStore" ), settings.
value( path +
"/sslKeyStore", QString() ).toString() );
731 el.setAttribute( QStringLiteral(
"sslTrustStore" ), settings.
value( path +
"/sslTrustStore", QString() ).toString() );
732 el.setAttribute( QStringLiteral(
"sslValidateCertificate" ), settings.
value( path +
"/sslValidateCertificate", QStringLiteral(
"false" ) ).toString() );
733 el.setAttribute( QStringLiteral(
"sslHostNameInCertificate" ), settings.
value( path +
"/sslHostNameInCertificate", QString() ).toString() );
735 root.appendChild( el );
741 QDomDocument QgsManageConnectionsDialog::saveGeonodeConnections(
const QStringList &connections )
743 QDomDocument doc( QStringLiteral(
"connections" ) );
744 QDomElement root = doc.createElement( QStringLiteral(
"qgsGeoNodeConnections" ) );
745 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
746 doc.appendChild( root );
750 for (
int i = 0; i < connections.count(); ++i )
752 path = QStringLiteral(
"/qgis/connections-geonode/" );
753 QDomElement el = doc.createElement( QStringLiteral(
"geonode" ) );
754 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
755 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url" ).toString() );
757 path = QStringLiteral(
"/qgis/GeoNode/" );
758 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username" ).toString() );
759 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password" ).toString() );
760 root.appendChild( el );
766 QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections(
const QStringList &connections )
768 QDomDocument doc( QStringLiteral(
"connections" ) );
769 QDomElement root = doc.createElement( QStringLiteral(
"qgsXYZTilesConnections" ) );
770 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
771 doc.appendChild( root );
775 for (
int i = 0; i < connections.count(); ++i )
777 path =
"qgis/connections-xyz/" + connections[ i ];
778 QDomElement el = doc.createElement( QStringLiteral(
"xyztiles" ) );
780 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
781 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path +
"/url" ).toString() );
782 el.setAttribute( QStringLiteral(
"zmin" ), settings.
value( path +
"/zmin", -1 ).toInt() );
783 el.setAttribute( QStringLiteral(
"zmax" ), settings.
value( path +
"/zmax", -1 ).toInt() );
784 el.setAttribute( QStringLiteral(
"authcfg" ), settings.
value( path +
"/authcfg" ).toString() );
785 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
786 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
787 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path +
"/referer" ).toString() );
788 el.setAttribute( QStringLiteral(
"tilePixelRatio" ), settings.
value( path +
"/tilePixelRatio", 0 ).toDouble() );
790 root.appendChild( el );
796 QDomDocument QgsManageConnectionsDialog::saveArcgisConnections(
const QStringList &connections,
const QString &service )
798 QDomDocument doc( QStringLiteral(
"connections" ) );
799 QDomElement root = doc.createElement(
"qgs" + service.toUpper() +
"Connections" );
800 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
801 doc.appendChild( root );
805 for (
int i = 0; i < connections.count(); ++i )
807 path =
"/qgis/connections-" + service.toLower() +
'/';
808 QDomElement el = doc.createElement( service.toLower() );
809 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
810 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url" ).toString() );
811 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path + connections[ i ] +
"/referer" ).toString() );
813 path =
"/qgis/" + service.toUpper() +
'/';
814 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username" ).toString() );
815 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password" ).toString() );
816 el.setAttribute( QStringLiteral(
"authcfg" ), settings.
value( path + connections[ i ] +
"/authcfg" ).toString() );
817 root.appendChild( el );
823 QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections(
const QStringList &connections )
825 QDomDocument doc( QStringLiteral(
"connections" ) );
826 QDomElement root = doc.createElement( QStringLiteral(
"qgsVectorTileConnections" ) );
827 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
828 doc.appendChild( root );
832 for (
int i = 0; i < connections.count(); ++i )
834 path =
"qgis/connections-vector-tile/" + connections[ i ];
835 QDomElement el = doc.createElement( QStringLiteral(
"vectortile" ) );
837 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
838 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path +
"/url" ).toString() );
839 el.setAttribute( QStringLiteral(
"zmin" ), settings.
value( path +
"/zmin", -1 ).toInt() );
840 el.setAttribute( QStringLiteral(
"zmax" ), settings.
value( path +
"/zmax", -1 ).toInt() );
841 el.setAttribute( QStringLiteral(
"serviceType" ), settings.
value( path +
"/serviceType", QString() ).toString() );
842 el.setAttribute( QStringLiteral(
"authcfg" ), settings.
value( path +
"/authcfg" ).toString() );
843 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
844 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
845 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path +
"/referer" ).toString() );
846 el.setAttribute( QStringLiteral(
"styleUrl" ), settings.
value( path +
"/styleUrl" ).toString() );
848 root.appendChild( el );
854 void QgsManageConnectionsDialog::loadOWSConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
856 const QDomElement root = doc.documentElement();
857 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
859 QMessageBox::information(
this, tr(
"Loading Connections" ),
860 tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
864 QString connectionName;
866 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
869 QDomElement child = root.firstChildElement();
871 bool overwrite =
true;
873 while ( !child.isNull() )
875 connectionName = child.attribute( QStringLiteral(
"name" ) );
876 if ( !items.contains( connectionName ) )
878 child = child.nextSiblingElement();
883 if ( keys.contains( connectionName ) && prompt )
885 const int res = QMessageBox::warning(
this,
886 tr(
"Loading Connections" ),
887 tr(
"Connection with name '%1' already exists. Overwrite?" )
888 .arg( connectionName ),
889 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
893 case QMessageBox::Cancel:
895 case QMessageBox::No:
896 child = child.nextSiblingElement();
898 case QMessageBox::Yes:
901 case QMessageBox::YesToAll:
905 case QMessageBox::NoToAll:
912 if ( keys.contains( connectionName ) )
916 child = child.nextSiblingElement();
922 keys << connectionName;
926 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
927 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
928 settings.
setValue( QString(
'/' + connectionName +
"/ignoreGetMapURI" ), child.attribute( QStringLiteral(
"ignoreGetMapURI" ) ) == QLatin1String(
"true" ) );
929 settings.
setValue( QString(
'/' + connectionName +
"/ignoreGetFeatureInfoURI" ), child.attribute( QStringLiteral(
"ignoreGetFeatureInfoURI" ) ) == QLatin1String(
"true" ) );
930 settings.
setValue( QString(
'/' + connectionName +
"/ignoreAxisOrientation" ), child.attribute( QStringLiteral(
"ignoreAxisOrientation" ) ) == QLatin1String(
"true" ) );
931 settings.
setValue( QString(
'/' + connectionName +
"/invertAxisOrientation" ), child.attribute( QStringLiteral(
"invertAxisOrientation" ) ) == QLatin1String(
"true" ) );
932 settings.
setValue( QString(
'/' + connectionName +
"/referer" ), child.attribute( QStringLiteral(
"referer" ) ) );
933 settings.
setValue( QString(
'/' + connectionName +
"/smoothPixmapTransform" ), child.attribute( QStringLiteral(
"smoothPixmapTransform" ) ) == QLatin1String(
"true" ) );
934 settings.
setValue( QString(
'/' + connectionName +
"/dpiMode" ), child.attribute( QStringLiteral(
"dpiMode" ), QStringLiteral(
"7" ) ).toInt() );
937 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
939 settings.
beginGroup(
"/qgis/" + service.toUpper() +
'/' + connectionName );
940 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
941 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
944 child = child.nextSiblingElement();
948 void QgsManageConnectionsDialog::loadWfsConnections(
const QDomDocument &doc,
const QStringList &items )
950 const QDomElement root = doc.documentElement();
951 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
953 QMessageBox::information(
this, tr(
"Loading Connections" ),
954 tr(
"The file is not a WFS connections exchange file." ) );
958 QString connectionName;
960 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
963 QDomElement child = root.firstChildElement();
965 bool overwrite =
true;
967 while ( !child.isNull() )
969 connectionName = child.attribute( QStringLiteral(
"name" ) );
970 if ( !items.contains( connectionName ) )
972 child = child.nextSiblingElement();
977 if ( keys.contains( connectionName ) && prompt )
979 const int res = QMessageBox::warning(
this,
980 tr(
"Loading Connections" ),
981 tr(
"Connection with name '%1' already exists. Overwrite?" )
982 .arg( connectionName ),
983 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
987 case QMessageBox::Cancel:
989 case QMessageBox::No:
990 child = child.nextSiblingElement();
992 case QMessageBox::Yes:
995 case QMessageBox::YesToAll:
999 case QMessageBox::NoToAll:
1006 if ( keys.contains( connectionName ) )
1010 child = child.nextSiblingElement();
1016 keys << connectionName;
1020 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
1021 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
1023 settings.
setValue( QString(
'/' + connectionName +
"/version" ), child.attribute( QStringLiteral(
"version" ) ) );
1024 settings.
setValue( QString(
'/' + connectionName +
"/maxnumfeatures" ), child.attribute( QStringLiteral(
"maxnumfeatures" ) ) );
1025 settings.
setValue( QString(
'/' + connectionName +
"/pagesize" ), child.attribute( QStringLiteral(
"pagesize" ) ) );
1026 settings.
setValue( QString(
'/' + connectionName +
"/pagingenabled" ), child.attribute( QStringLiteral(
"pagingenabled" ) ) );
1027 settings.
setValue( QString(
'/' + connectionName +
"/ignoreAxisOrientation" ), child.attribute( QStringLiteral(
"ignoreAxisOrientation" ) ) );
1028 settings.
setValue( QString(
'/' + connectionName +
"/invertAxisOrientation" ), child.attribute( QStringLiteral(
"invertAxisOrientation" ) ) );
1031 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
1033 settings.
beginGroup(
"/qgis/WFS/" + connectionName );
1034 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1035 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1038 child = child.nextSiblingElement();
1042 void QgsManageConnectionsDialog::loadPgConnections(
const QDomDocument &doc,
const QStringList &items )
1044 const QDomElement root = doc.documentElement();
1045 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
1047 QMessageBox::information(
this,
1048 tr(
"Loading Connections" ),
1049 tr(
"The file is not a PostGIS connections exchange file." ) );
1053 QString connectionName;
1055 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
1058 QDomElement child = root.firstChildElement();
1060 bool overwrite =
true;
1062 while ( !child.isNull() )
1064 connectionName = child.attribute( QStringLiteral(
"name" ) );
1065 if ( !items.contains( connectionName ) )
1067 child = child.nextSiblingElement();
1072 if ( keys.contains( connectionName ) && prompt )
1074 const int res = QMessageBox::warning(
this,
1075 tr(
"Loading Connections" ),
1076 tr(
"Connection with name '%1' already exists. Overwrite?" )
1077 .arg( connectionName ),
1078 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1081 case QMessageBox::Cancel:
1083 case QMessageBox::No:
1084 child = child.nextSiblingElement();
1086 case QMessageBox::Yes:
1089 case QMessageBox::YesToAll:
1093 case QMessageBox::NoToAll:
1100 if ( keys.contains( connectionName ) )
1104 child = child.nextSiblingElement();
1110 keys << connectionName;
1114 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
1116 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1117 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1118 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1119 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1121 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1125 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1127 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1128 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1129 settings.
setValue( QStringLiteral(
"/projectsInDatabase" ), child.attribute( QStringLiteral(
"projectsInDatabase" ), 0 ) );
1130 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1131 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1132 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1133 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1136 child = child.nextSiblingElement();
1140 void QgsManageConnectionsDialog::loadMssqlConnections(
const QDomDocument &doc,
const QStringList &items )
1142 const QDomElement root = doc.documentElement();
1143 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
1145 QMessageBox::information(
this,
1146 tr(
"Loading Connections" ),
1147 tr(
"The file is not a MSSQL connections exchange file." ) );
1151 QString connectionName;
1153 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
1156 QDomElement child = root.firstChildElement();
1158 bool overwrite =
true;
1160 while ( !child.isNull() )
1162 connectionName = child.attribute( QStringLiteral(
"name" ) );
1163 if ( !items.contains( connectionName ) )
1165 child = child.nextSiblingElement();
1170 if ( keys.contains( connectionName ) && prompt )
1172 const int res = QMessageBox::warning(
this,
1173 tr(
"Loading Connections" ),
1174 tr(
"Connection with name '%1' already exists. Overwrite?" )
1175 .arg( connectionName ),
1176 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1179 case QMessageBox::Cancel:
1181 case QMessageBox::No:
1182 child = child.nextSiblingElement();
1184 case QMessageBox::Yes:
1187 case QMessageBox::YesToAll:
1191 case QMessageBox::NoToAll:
1198 if ( keys.contains( connectionName ) )
1202 child = child.nextSiblingElement();
1208 keys << connectionName;
1212 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
1214 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1215 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1216 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1217 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1219 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1223 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1225 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1226 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1227 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1228 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1229 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1230 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1233 child = child.nextSiblingElement();
1237 void QgsManageConnectionsDialog::loadOracleConnections(
const QDomDocument &doc,
const QStringList &items )
1239 const QDomElement root = doc.documentElement();
1240 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
1242 QMessageBox::information(
this,
1243 tr(
"Loading Connections" ),
1244 tr(
"The file is not an Oracle connections exchange file." ) );
1248 QString connectionName;
1250 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
1253 QDomElement child = root.firstChildElement();
1255 bool overwrite =
true;
1257 while ( !child.isNull() )
1259 connectionName = child.attribute( QStringLiteral(
"name" ) );
1260 if ( !items.contains( connectionName ) )
1262 child = child.nextSiblingElement();
1267 if ( keys.contains( connectionName ) && prompt )
1269 const int res = QMessageBox::warning(
this,
1270 tr(
"Loading Connections" ),
1271 tr(
"Connection with name '%1' already exists. Overwrite?" )
1272 .arg( connectionName ),
1273 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1276 case QMessageBox::Cancel:
1278 case QMessageBox::No:
1279 child = child.nextSiblingElement();
1281 case QMessageBox::Yes:
1284 case QMessageBox::YesToAll:
1288 case QMessageBox::NoToAll:
1295 if ( keys.contains( connectionName ) )
1299 child = child.nextSiblingElement();
1305 keys << connectionName;
1309 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
1311 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1312 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1313 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1314 settings.
setValue( QStringLiteral(
"/dboptions" ), child.attribute( QStringLiteral(
"dboptions" ) ) );
1315 settings.
setValue( QStringLiteral(
"/dbworkspace" ), child.attribute( QStringLiteral(
"dbworkspace" ) ) );
1316 settings.
setValue( QStringLiteral(
"/schema" ), child.attribute( QStringLiteral(
"schema" ) ) );
1317 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1318 settings.
setValue( QStringLiteral(
"/userTablesOnly" ), child.attribute( QStringLiteral(
"userTablesOnly" ) ) );
1319 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ) ) );
1320 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ) ) );
1321 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1322 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1323 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1324 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1327 child = child.nextSiblingElement();
1331 void QgsManageConnectionsDialog::loadDb2Connections(
const QDomDocument &doc,
const QStringList &items )
1333 const QDomElement root = doc.documentElement();
1334 if ( root.tagName() != QLatin1String(
"qgsDb2Connections" ) )
1336 QMessageBox::information(
this,
1337 tr(
"Loading Connections" ),
1338 tr(
"The file is not a DB2 connections exchange file." ) );
1342 QString connectionName;
1344 settings.
beginGroup( QStringLiteral(
"/DB2/connections" ) );
1347 QDomElement child = root.firstChildElement();
1349 bool overwrite =
true;
1351 while ( !child.isNull() )
1353 connectionName = child.attribute( QStringLiteral(
"name" ) );
1354 if ( !items.contains( connectionName ) )
1356 child = child.nextSiblingElement();
1361 if ( keys.contains( connectionName ) && prompt )
1363 const int res = QMessageBox::warning(
this,
1364 tr(
"Loading Connections" ),
1365 tr(
"Connection with name '%1' already exists. Overwrite?" )
1366 .arg( connectionName ),
1367 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1370 case QMessageBox::Cancel:
1372 case QMessageBox::No:
1373 child = child.nextSiblingElement();
1375 case QMessageBox::Yes:
1378 case QMessageBox::YesToAll:
1382 case QMessageBox::NoToAll:
1389 if ( keys.contains( connectionName ) )
1393 child = child.nextSiblingElement();
1399 keys << connectionName;
1403 settings.
beginGroup(
"/DB2/connections/" + connectionName );
1405 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1406 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1407 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1408 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1410 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1414 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1416 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1417 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1418 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1419 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1420 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1421 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1424 child = child.nextSiblingElement();
1428 void QgsManageConnectionsDialog::loadHanaConnections(
const QDomDocument &doc,
const QStringList &items )
1430 QDomElement root = doc.documentElement();
1431 if ( root.tagName() != QLatin1String(
"qgsHanaConnections" ) )
1433 QMessageBox::warning(
this,
1434 tr(
"Loading Connections" ),
1435 tr(
"The file is not a HANA connections exchange file." ) );
1439 const QDomAttr version = root.attributeNode(
"version" );
1440 if ( version.value() != QLatin1String(
"1.0" ) )
1442 QMessageBox::warning(
this,
1443 tr(
"Loading Connections" ),
1444 tr(
"The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1449 settings.
beginGroup( QStringLiteral(
"/HANA/connections" ) );
1452 QDomElement child = root.firstChildElement();
1454 bool overwrite =
true;
1456 while ( !child.isNull() )
1458 const QString connectionName = child.attribute( QStringLiteral(
"name" ) );
1459 if ( !items.contains( connectionName ) )
1461 child = child.nextSiblingElement();
1466 if ( keys.contains( connectionName ) && prompt )
1468 const int res = QMessageBox::warning(
this,
1469 tr(
"Loading Connections" ),
1470 tr(
"Connection with name '%1' already exists. Overwrite?" )
1471 .arg( connectionName ),
1472 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1475 case QMessageBox::Cancel:
1477 case QMessageBox::No:
1478 child = child.nextSiblingElement();
1480 case QMessageBox::Yes:
1483 case QMessageBox::YesToAll:
1487 case QMessageBox::NoToAll:
1494 if ( keys.contains( connectionName ) )
1498 child = child.nextSiblingElement();
1504 keys << connectionName;
1508 settings.
beginGroup(
"/HANA/connections/" + connectionName );
1510 for (
const QString param :
1511 {
"driver",
"host",
"database",
"identifierType",
"identifier",
"multitenant",
"schema",
"userTablesOnly",
1512 "allowGeometrylessTables",
"saveUsername",
"username",
"savePassword",
"password",
"sslEnabled",
1513 "sslCryptoProvider",
"sslKeyStore",
"sslTrustStore",
"sslValidateCertificate",
"sslHostNameInCertificate"
1515 settings.
setValue( QStringLiteral(
"/" ) + param, child.attribute( param ) );
1519 child = child.nextSiblingElement();
1523 void QgsManageConnectionsDialog::loadGeonodeConnections(
const QDomDocument &doc,
const QStringList &items )
1525 const QDomElement root = doc.documentElement();
1526 if ( root.tagName() != QLatin1String(
"qgsGeoNodeConnections" ) )
1528 QMessageBox::information(
this, tr(
"Loading Connections" ),
1529 tr(
"The file is not a GeoNode connections exchange file." ) );
1533 QString connectionName;
1535 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
1538 QDomElement child = root.firstChildElement();
1540 bool overwrite =
true;
1542 while ( !child.isNull() )
1544 connectionName = child.attribute( QStringLiteral(
"name" ) );
1545 if ( !items.contains( connectionName ) )
1547 child = child.nextSiblingElement();
1552 if ( keys.contains( connectionName ) && prompt )
1554 const int res = QMessageBox::warning(
this,
1555 tr(
"Loading Connections" ),
1556 tr(
"Connection with name '%1' already exists. Overwrite?" )
1557 .arg( connectionName ),
1558 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1562 case QMessageBox::Cancel:
1564 case QMessageBox::No:
1565 child = child.nextSiblingElement();
1567 case QMessageBox::Yes:
1570 case QMessageBox::YesToAll:
1574 case QMessageBox::NoToAll:
1581 if ( keys.contains( connectionName ) )
1585 child = child.nextSiblingElement();
1591 keys << connectionName;
1595 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
1596 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
1599 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
1601 settings.
beginGroup(
"/qgis/GeoNode/" + connectionName );
1602 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1603 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1606 child = child.nextSiblingElement();
1610 void QgsManageConnectionsDialog::loadXyzTilesConnections(
const QDomDocument &doc,
const QStringList &items )
1612 const QDomElement root = doc.documentElement();
1613 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
1615 QMessageBox::information(
this, tr(
"Loading Connections" ),
1616 tr(
"The file is not a XYZ Tiles connections exchange file." ) );
1620 QString connectionName;
1622 settings.
beginGroup( QStringLiteral(
"/qgis/connections-xyz" ) );
1625 QDomElement child = root.firstChildElement();
1627 bool overwrite =
true;
1629 while ( !child.isNull() )
1631 connectionName = child.attribute( QStringLiteral(
"name" ) );
1632 if ( !items.contains( connectionName ) )
1634 child = child.nextSiblingElement();
1639 if ( keys.contains( connectionName ) && prompt )
1641 const int res = QMessageBox::warning(
this,
1642 tr(
"Loading Connections" ),
1643 tr(
"Connection with name '%1' already exists. Overwrite?" )
1644 .arg( connectionName ),
1645 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1649 case QMessageBox::Cancel:
1651 case QMessageBox::No:
1652 child = child.nextSiblingElement();
1654 case QMessageBox::Yes:
1657 case QMessageBox::YesToAll:
1661 case QMessageBox::NoToAll:
1668 if ( keys.contains( connectionName ) )
1672 child = child.nextSiblingElement();
1678 keys << connectionName;
1681 settings.
beginGroup(
"qgis/connections-xyz/" + connectionName );
1682 settings.
setValue( QStringLiteral(
"url" ), child.attribute( QStringLiteral(
"url" ) ) );
1683 settings.
setValue( QStringLiteral(
"zmin" ), child.attribute( QStringLiteral(
"zmin" ) ) );
1684 settings.
setValue( QStringLiteral(
"zmax" ), child.attribute( QStringLiteral(
"zmax" ) ) );
1685 settings.
setValue( QStringLiteral(
"authcfg" ), child.attribute( QStringLiteral(
"authcfg" ) ) );
1686 settings.
setValue( QStringLiteral(
"username" ), child.attribute( QStringLiteral(
"username" ) ) );
1687 settings.
setValue( QStringLiteral(
"password" ), child.attribute( QStringLiteral(
"password" ) ) );
1688 settings.
setValue( QStringLiteral(
"referer" ), child.attribute( QStringLiteral(
"referer" ) ) );
1689 settings.
setValue( QStringLiteral(
"tilePixelRatio" ), child.attribute( QStringLiteral(
"tilePixelRatio" ) ) );
1692 child = child.nextSiblingElement();
1696 void QgsManageConnectionsDialog::loadArcgisConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
1698 const QDomElement root = doc.documentElement();
1699 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
1701 QMessageBox::information(
this, tr(
"Loading Connections" ),
1702 tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
1706 QString connectionName;
1708 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
1711 QDomElement child = root.firstChildElement();
1713 bool overwrite =
true;
1715 while ( !child.isNull() )
1717 connectionName = child.attribute( QStringLiteral(
"name" ) );
1718 if ( !items.contains( connectionName ) )
1720 child = child.nextSiblingElement();
1725 if ( keys.contains( connectionName ) && prompt )
1727 const int res = QMessageBox::warning(
this,
1728 tr(
"Loading Connections" ),
1729 tr(
"Connection with name '%1' already exists. Overwrite?" )
1730 .arg( connectionName ),
1731 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1735 case QMessageBox::Cancel:
1737 case QMessageBox::No:
1738 child = child.nextSiblingElement();
1740 case QMessageBox::Yes:
1743 case QMessageBox::YesToAll:
1747 case QMessageBox::NoToAll:
1754 if ( keys.contains( connectionName ) )
1758 child = child.nextSiblingElement();
1764 keys << connectionName;
1768 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
1769 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
1770 settings.
setValue( QString(
'/' + connectionName +
"/referer" ), child.attribute( QStringLiteral(
"referer" ) ) );
1773 settings.
beginGroup(
"/qgis/" + service.toUpper() +
'/' + connectionName );
1774 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1775 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1776 settings.
setValue( QStringLiteral(
"/authcfg" ), child.attribute( QStringLiteral(
"authcfg" ) ) );
1779 child = child.nextSiblingElement();
1783 void QgsManageConnectionsDialog::loadVectorTileConnections(
const QDomDocument &doc,
const QStringList &items )
1785 const QDomElement root = doc.documentElement();
1786 if ( root.tagName() != QLatin1String(
"qgsVectorTileConnections" ) )
1788 QMessageBox::information(
this, tr(
"Loading Connections" ),
1789 tr(
"The file is not a Vector Tile connections exchange file." ) );
1793 QString connectionName;
1795 settings.
beginGroup( QStringLiteral(
"/qgis/connections-vector-tile" ) );
1798 QDomElement child = root.firstChildElement();
1800 bool overwrite =
true;
1802 while ( !child.isNull() )
1804 connectionName = child.attribute( QStringLiteral(
"name" ) );
1805 if ( !items.contains( connectionName ) )
1807 child = child.nextSiblingElement();
1812 if ( keys.contains( connectionName ) && prompt )
1814 const int res = QMessageBox::warning(
this,
1815 tr(
"Loading Connections" ),
1816 tr(
"Connection with name '%1' already exists. Overwrite?" )
1817 .arg( connectionName ),
1818 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1822 case QMessageBox::Cancel:
1824 case QMessageBox::No:
1825 child = child.nextSiblingElement();
1827 case QMessageBox::Yes:
1830 case QMessageBox::YesToAll:
1834 case QMessageBox::NoToAll:
1841 if ( keys.contains( connectionName ) )
1845 child = child.nextSiblingElement();
1851 keys << connectionName;
1854 settings.
beginGroup(
"qgis/connections-vector-tile/" + connectionName );
1855 settings.
setValue( QStringLiteral(
"url" ), child.attribute( QStringLiteral(
"url" ) ) );
1856 settings.
setValue( QStringLiteral(
"zmin" ), child.attribute( QStringLiteral(
"zmin" ) ) );
1857 settings.
setValue( QStringLiteral(
"zmax" ), child.attribute( QStringLiteral(
"zmax" ) ) );
1858 settings.
setValue( QStringLiteral(
"serviceType" ), child.attribute( QStringLiteral(
"serviceType" ) ) );
1859 settings.
setValue( QStringLiteral(
"authcfg" ), child.attribute( QStringLiteral(
"authcfg" ) ) );
1860 settings.
setValue( QStringLiteral(
"username" ), child.attribute( QStringLiteral(
"username" ) ) );
1861 settings.
setValue( QStringLiteral(
"password" ), child.attribute( QStringLiteral(
"password" ) ) );
1862 settings.
setValue( QStringLiteral(
"referer" ), child.attribute( QStringLiteral(
"referer" ) ) );
1863 settings.
setValue( QStringLiteral(
"styleUrl" ), child.attribute( QStringLiteral(
"styleUrl" ) ) );
1867 child = child.nextSiblingElement();
1873 listConnections->selectAll();
1874 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
1879 listConnections->clearSelection();
1880 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
QgsManageConnectionsDialog(QWidget *parent=nullptr, Mode mode=Export, Type type=WMS, const QString &fileName=QString())
Constructor for QgsManageConnectionsDialog.
This class is a composition of two QSettings instances:
QStringList childGroups() 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.