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 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 = saveGeonodeConnections( items );
137 doc = saveXyzTilesConnections( items );
141 QFile file( mFileName );
142 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
144 QMessageBox::warning(
this, tr(
"Saving Connections" ),
145 tr(
"Cannot write file %1:\n%2." )
147 file.errorString() ) );
151 QTextStream out( &file );
156 QFile file( mFileName );
157 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
159 QMessageBox::warning(
this, tr(
"Loading Connections" ),
160 tr(
"Cannot read file %1:\n%2." )
162 file.errorString() ) );
171 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
173 QMessageBox::warning(
this, tr(
"Loading Connections" ),
174 tr(
"Parse error at line %1, column %2:\n%3" )
181 switch ( mConnectionType )
184 loadOWSConnections( doc, items, QStringLiteral(
"WMS" ) );
187 loadWfsConnections( doc, items );
190 loadPgConnections( doc, items );
193 loadMssqlConnections( doc, items );
196 loadOWSConnections( doc, items, QStringLiteral(
"WCS" ) );
199 loadOracleConnections( doc, items );
202 loadDb2Connections( doc, items );
205 loadGeonodeConnections( doc, items );
208 loadXyzTilesConnections( doc, items );
212 listConnections->clear();
219 bool QgsManageConnectionsDialog::populateConnections()
222 if ( mDialogMode ==
Export )
225 switch ( mConnectionType )
228 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wms" ) );
231 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
234 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wcs" ) );
237 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
240 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
243 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
246 settings.
beginGroup( QStringLiteral(
"/DB2/connections" ) );
249 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
252 settings.
beginGroup( QStringLiteral(
"/qgis/connections-xyz" ) );
256 QStringList::Iterator it = keys.begin();
257 while ( it != keys.end() )
259 QListWidgetItem *item =
new QListWidgetItem();
260 item->setText( *it );
261 listConnections->addItem( item );
269 QFile file( mFileName );
270 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
272 QMessageBox::warning(
this, tr(
"Loading Connections" ),
273 tr(
"Cannot read file %1:\n%2." )
275 file.errorString() ) );
284 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
286 QMessageBox::warning(
this, tr(
"Loading Connections" ),
287 tr(
"Parse error at line %1, column %2:\n%3" )
294 QDomElement root = doc.documentElement();
295 switch ( mConnectionType )
298 if ( root.tagName() != QLatin1String(
"qgsWMSConnections" ) )
300 QMessageBox::information(
this, tr(
"Loading Connections" ),
301 tr(
"The file is not a WMS connections exchange file." ) );
307 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
309 QMessageBox::information(
this, tr(
"Loading Connections" ),
310 tr(
"The file is not a WFS connections exchange file." ) );
316 if ( root.tagName() != QLatin1String(
"qgsWCSConnections" ) )
318 QMessageBox::information(
this, tr(
"Loading Connections" ),
319 tr(
"The file is not a WCS connections exchange file." ) );
325 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
327 QMessageBox::information(
this, tr(
"Loading Connections" ),
328 tr(
"The file is not a PostGIS connections exchange file." ) );
334 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
336 QMessageBox::information(
this, tr(
"Loading Connections" ),
337 tr(
"The file is not a MSSQL connections exchange file." ) );
342 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
344 QMessageBox::information(
this, tr(
"Loading Connections" ),
345 tr(
"The file is not an Oracle connections exchange file." ) );
350 if ( root.tagName() != QLatin1String(
"qgsDb2Connections" ) )
352 QMessageBox::information(
this, tr(
"Loading Connections" ),
353 tr(
"The file is not a DB2 connections exchange file." ) );
358 if ( root.tagName() != QLatin1String(
"qgsGeoNodeConnections" ) )
360 QMessageBox::information(
this, tr(
"Loading Connections" ),
361 tr(
"The file is not a GeoNode connections exchange file." ) );
366 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
368 QMessageBox::information(
this, tr(
"Loading Connections" ),
369 tr(
"The file is not a XYZ Tiles connections exchange file." ) );
375 QDomElement child = root.firstChildElement();
376 while ( !child.isNull() )
378 QListWidgetItem *item =
new QListWidgetItem();
379 item->setText( child.attribute( QStringLiteral(
"name" ) ) );
380 listConnections->addItem( item );
381 child = child.nextSiblingElement();
387 QDomDocument QgsManageConnectionsDialog::saveOWSConnections(
const QStringList &connections,
const QString &service )
389 QDomDocument doc( QStringLiteral(
"connections" ) );
390 QDomElement root = doc.createElement(
"qgs" + service.toUpper() +
"Connections" );
391 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
392 doc.appendChild( root );
396 for (
int i = 0; i < connections.count(); ++i )
398 path =
"/qgis/connections-" + service.toLower() +
'/';
399 QDomElement el = doc.createElement( service.toLower() );
400 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
401 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url",
"" ).toString() );
403 if ( service == QLatin1String(
"WMS" ) )
405 el.setAttribute( QStringLiteral(
"ignoreGetMapURI" ), settings.
value( path + connections[i] +
"/ignoreGetMapURI",
false ).toBool() ?
"true" :
"false" );
406 el.setAttribute( QStringLiteral(
"ignoreGetFeatureInfoURI" ), settings.
value( path + connections[i] +
"/ignoreGetFeatureInfoURI",
false ).toBool() ?
"true" :
"false" );
407 el.setAttribute( QStringLiteral(
"ignoreAxisOrientation" ), settings.
value( path + connections[i] +
"/ignoreAxisOrientation",
false ).toBool() ?
"true" :
"false" );
408 el.setAttribute( QStringLiteral(
"invertAxisOrientation" ), settings.
value( path + connections[i] +
"/invertAxisOrientation",
false ).toBool() ?
"true" :
"false" );
409 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path + connections[ i ] +
"/referer",
"" ).toString() );
410 el.setAttribute( QStringLiteral(
"smoothPixmapTransform" ), settings.
value( path + connections[i] +
"/smoothPixmapTransform",
false ).toBool() ?
"true" :
"false" );
411 el.setAttribute( QStringLiteral(
"dpiMode" ), settings.
value( path + connections[i] +
"/dpiMode",
"7" ).toInt() );
414 path =
"/qgis/" + service.toUpper() +
'/';
415 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username",
"" ).toString() );
416 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password",
"" ).toString() );
417 root.appendChild( el );
423 QDomDocument QgsManageConnectionsDialog::saveWfsConnections(
const QStringList &connections )
425 QDomDocument doc( QStringLiteral(
"connections" ) );
426 QDomElement root = doc.createElement( QStringLiteral(
"qgsWFSConnections" ) );
427 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
428 doc.appendChild( root );
432 for (
int i = 0; i < connections.count(); ++i )
434 path = QStringLiteral(
"/qgis/connections-wfs/" );
435 QDomElement el = doc.createElement( QStringLiteral(
"wfs" ) );
436 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
437 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url",
"" ).toString() );
439 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path + connections[ i ] +
"/referer",
"" ).toString() );
441 path = QStringLiteral(
"/qgis/WFS/" );
442 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username",
"" ).toString() );
443 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password",
"" ).toString() );
444 root.appendChild( el );
450 QDomDocument QgsManageConnectionsDialog::savePgConnections(
const QStringList &connections )
452 QDomDocument doc( QStringLiteral(
"connections" ) );
453 QDomElement root = doc.createElement( QStringLiteral(
"qgsPgConnections" ) );
454 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
455 doc.appendChild( root );
459 for (
int i = 0; i < connections.count(); ++i )
461 path =
"/PostgreSQL/connections/" + connections[ i ];
462 QDomElement el = doc.createElement( QStringLiteral(
"postgis" ) );
463 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
464 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host",
"" ).toString() );
465 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port",
"" ).toString() );
466 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database",
"" ).toString() );
467 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service",
"" ).toString() );
468 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
469 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
471 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
473 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
475 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username",
"" ).toString() );
478 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
480 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
482 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password",
"" ).toString() );
485 root.appendChild( el );
491 QDomDocument QgsManageConnectionsDialog::saveMssqlConnections(
const QStringList &connections )
493 QDomDocument doc( QStringLiteral(
"connections" ) );
494 QDomElement root = doc.createElement( QStringLiteral(
"qgsMssqlConnections" ) );
495 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
496 doc.appendChild( root );
500 for (
int i = 0; i < connections.count(); ++i )
502 path =
"/MSSQL/connections/" + connections[ i ];
503 QDomElement el = doc.createElement( QStringLiteral(
"mssql" ) );
504 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
505 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host",
"" ).toString() );
506 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port",
"" ).toString() );
507 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database",
"" ).toString() );
508 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service",
"" ).toString() );
509 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
510 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
512 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
514 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
516 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username",
"" ).toString() );
519 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
521 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
523 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password",
"" ).toString() );
526 root.appendChild( el );
532 QDomDocument QgsManageConnectionsDialog::saveOracleConnections(
const QStringList &connections )
534 QDomDocument doc( QStringLiteral(
"connections" ) );
535 QDomElement root = doc.createElement( QStringLiteral(
"qgsOracleConnections" ) );
536 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
537 doc.appendChild( root );
541 for (
int i = 0; i < connections.count(); ++i )
543 path =
"/Oracle/connections/" + connections[ i ];
544 QDomElement el = doc.createElement( QStringLiteral(
"oracle" ) );
545 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
546 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host",
"" ).toString() );
547 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port",
"" ).toString() );
548 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database",
"" ).toString() );
549 el.setAttribute( QStringLiteral(
"dboptions" ), settings.
value( path +
"/dboptions",
"" ).toString() );
550 el.setAttribute( QStringLiteral(
"dbworkspace" ), settings.
value( path +
"/dbworkspace",
"" ).toString() );
551 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema", QString() ).toString() );
552 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
553 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly",
"0" ).toString() );
554 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
555 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
557 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
559 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
561 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username",
"" ).toString() );
564 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
566 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
568 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password",
"" ).toString() );
571 root.appendChild( el );
577 QDomDocument QgsManageConnectionsDialog::saveDb2Connections(
const QStringList &connections )
579 QDomDocument doc( QStringLiteral(
"connections" ) );
580 QDomElement root = doc.createElement( QStringLiteral(
"qgsDb2Connections" ) );
581 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
582 doc.appendChild( root );
586 for (
int i = 0; i < connections.count(); ++i )
588 path =
"/DB2/connections/" + connections[ i ];
589 QDomElement el = doc.createElement( QStringLiteral(
"db2" ) );
590 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
591 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host",
"" ).toString() );
592 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port",
"" ).toString() );
593 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database",
"" ).toString() );
594 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service",
"" ).toString() );
595 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
596 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
598 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
600 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
602 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username",
"" ).toString() );
605 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
607 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
609 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password",
"" ).toString() );
612 root.appendChild( el );
618 QDomDocument QgsManageConnectionsDialog::saveGeonodeConnections(
const QStringList &connections )
620 QDomDocument doc( QStringLiteral(
"connections" ) );
621 QDomElement root = doc.createElement( QStringLiteral(
"qgsGeoNodeConnections" ) );
622 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
623 doc.appendChild( root );
627 for (
int i = 0; i < connections.count(); ++i )
629 path = QStringLiteral(
"/qgis/connections-geonode/" );
630 QDomElement el = doc.createElement( QStringLiteral(
"geonode" ) );
631 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
632 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url",
"" ).toString() );
634 path = QStringLiteral(
"/qgis/GeoNode/" );
635 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username",
"" ).toString() );
636 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password",
"" ).toString() );
637 root.appendChild( el );
643 QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections(
const QStringList &connections )
645 QDomDocument doc( QStringLiteral(
"connections" ) );
646 QDomElement root = doc.createElement( QStringLiteral(
"qgsXYZTilesConnections" ) );
647 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
648 doc.appendChild( root );
652 for (
int i = 0; i < connections.count(); ++i )
654 path =
"qgis/connections-xyz/" + connections[ i ];
655 QDomElement el = doc.createElement( QStringLiteral(
"xyztiles" ) );
657 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
658 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path +
"/url",
"" ).toString() );
659 el.setAttribute( QStringLiteral(
"zmin" ), settings.
value( path +
"/zmin", -1 ).toInt() );
660 el.setAttribute( QStringLiteral(
"zmax" ), settings.
value( path +
"/zmax", -1 ).toInt() );
661 el.setAttribute( QStringLiteral(
"authcfg" ), settings.
value( path +
"/authcfg",
"" ).toString() );
662 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username",
"" ).toString() );
663 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password",
"" ).toString() );
664 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path +
"/referer",
"" ).toString() );
666 root.appendChild( el );
672 void QgsManageConnectionsDialog::loadOWSConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
674 QDomElement root = doc.documentElement();
675 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
677 QMessageBox::information(
this, tr(
"Loading Connections" ),
678 tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
682 QString connectionName;
684 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
687 QDomElement child = root.firstChildElement();
689 bool overwrite =
true;
691 while ( !child.isNull() )
693 connectionName = child.attribute( QStringLiteral(
"name" ) );
694 if ( !items.contains( connectionName ) )
696 child = child.nextSiblingElement();
701 if ( keys.contains( connectionName ) && prompt )
703 int res = QMessageBox::warning(
this,
704 tr(
"Loading Connections" ),
705 tr(
"Connection with name '%1' already exists. Overwrite?" )
706 .arg( connectionName ),
707 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
711 case QMessageBox::Cancel:
713 case QMessageBox::No:
714 child = child.nextSiblingElement();
716 case QMessageBox::Yes:
719 case QMessageBox::YesToAll:
723 case QMessageBox::NoToAll:
730 if ( keys.contains( connectionName ) && !overwrite )
732 child = child.nextSiblingElement();
737 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
738 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
739 settings.
setValue( QString(
'/' + connectionName +
"/ignoreGetMapURI" ), child.attribute( QStringLiteral(
"ignoreGetMapURI" ) ) == QLatin1String(
"true" ) );
740 settings.
setValue( QString(
'/' + connectionName +
"/ignoreGetFeatureInfoURI" ), child.attribute( QStringLiteral(
"ignoreGetFeatureInfoURI" ) ) == QLatin1String(
"true" ) );
741 settings.
setValue( QString(
'/' + connectionName +
"/ignoreAxisOrientation" ), child.attribute( QStringLiteral(
"ignoreAxisOrientation" ) ) == QLatin1String(
"true" ) );
742 settings.
setValue( QString(
'/' + connectionName +
"/invertAxisOrientation" ), child.attribute( QStringLiteral(
"invertAxisOrientation" ) ) == QLatin1String(
"true" ) );
743 settings.
setValue( QString(
'/' + connectionName +
"/referer" ), child.attribute( QStringLiteral(
"referer" ) ) );
744 settings.
setValue( QString(
'/' + connectionName +
"/smoothPixmapTransform" ), child.attribute( QStringLiteral(
"smoothPixmapTransform" ) ) == QLatin1String(
"true" ) );
745 settings.
setValue( QString(
'/' + connectionName +
"/dpiMode" ), child.attribute( QStringLiteral(
"dpiMode" ), QStringLiteral(
"7" ) ).toInt() );
748 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
750 settings.
beginGroup(
"/qgis/" + service.toUpper() +
'/' + connectionName );
751 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
752 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
755 child = child.nextSiblingElement();
759 void QgsManageConnectionsDialog::loadWfsConnections(
const QDomDocument &doc,
const QStringList &items )
761 QDomElement root = doc.documentElement();
762 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
764 QMessageBox::information(
this, tr(
"Loading Connections" ),
765 tr(
"The file is not a WFS connections exchange file." ) );
769 QString connectionName;
771 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
774 QDomElement child = root.firstChildElement();
776 bool overwrite =
true;
778 while ( !child.isNull() )
780 connectionName = child.attribute( QStringLiteral(
"name" ) );
781 if ( !items.contains( connectionName ) )
783 child = child.nextSiblingElement();
788 if ( keys.contains( connectionName ) && prompt )
790 int res = QMessageBox::warning(
this,
791 tr(
"Loading Connections" ),
792 tr(
"Connection with name '%1' already exists. Overwrite?" )
793 .arg( connectionName ),
794 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
798 case QMessageBox::Cancel:
800 case QMessageBox::No:
801 child = child.nextSiblingElement();
803 case QMessageBox::Yes:
806 case QMessageBox::YesToAll:
810 case QMessageBox::NoToAll:
817 if ( keys.contains( connectionName ) && !overwrite )
819 child = child.nextSiblingElement();
824 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
825 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
828 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
830 settings.
beginGroup(
"/qgis/WFS/" + connectionName );
831 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
832 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
835 child = child.nextSiblingElement();
840 void QgsManageConnectionsDialog::loadPgConnections(
const QDomDocument &doc,
const QStringList &items )
842 QDomElement root = doc.documentElement();
843 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
845 QMessageBox::information(
this,
846 tr(
"Loading Connections" ),
847 tr(
"The file is not a PostGIS connections exchange file." ) );
851 QString connectionName;
853 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
856 QDomElement child = root.firstChildElement();
858 bool overwrite =
true;
860 while ( !child.isNull() )
862 connectionName = child.attribute( QStringLiteral(
"name" ) );
863 if ( !items.contains( connectionName ) )
865 child = child.nextSiblingElement();
870 if ( keys.contains( connectionName ) && prompt )
872 int res = QMessageBox::warning(
this,
873 tr(
"Loading Connections" ),
874 tr(
"Connection with name '%1' already exists. Overwrite?" )
875 .arg( connectionName ),
876 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
879 case QMessageBox::Cancel:
881 case QMessageBox::No:
882 child = child.nextSiblingElement();
884 case QMessageBox::Yes:
887 case QMessageBox::YesToAll:
891 case QMessageBox::NoToAll:
898 if ( keys.contains( connectionName ) && !overwrite )
900 child = child.nextSiblingElement();
905 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
907 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
908 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
909 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
910 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
912 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
916 settings.
setValue( QStringLiteral(
"/service" ),
"" );
918 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
919 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
920 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
921 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
922 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
923 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
926 child = child.nextSiblingElement();
930 void QgsManageConnectionsDialog::loadMssqlConnections(
const QDomDocument &doc,
const QStringList &items )
932 QDomElement root = doc.documentElement();
933 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
935 QMessageBox::information(
this,
936 tr(
"Loading Connections" ),
937 tr(
"The file is not a MSSQL connections exchange file." ) );
941 QString connectionName;
943 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
946 QDomElement child = root.firstChildElement();
948 bool overwrite =
true;
950 while ( !child.isNull() )
952 connectionName = child.attribute( QStringLiteral(
"name" ) );
953 if ( !items.contains( connectionName ) )
955 child = child.nextSiblingElement();
960 if ( keys.contains( connectionName ) && prompt )
962 int res = QMessageBox::warning(
this,
963 tr(
"Loading Connections" ),
964 tr(
"Connection with name '%1' already exists. Overwrite?" )
965 .arg( connectionName ),
966 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
969 case QMessageBox::Cancel:
971 case QMessageBox::No:
972 child = child.nextSiblingElement();
974 case QMessageBox::Yes:
977 case QMessageBox::YesToAll:
981 case QMessageBox::NoToAll:
988 if ( keys.contains( connectionName ) && !overwrite )
990 child = child.nextSiblingElement();
995 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
997 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
998 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
999 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1000 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1002 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1006 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1008 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1009 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1010 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1011 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1012 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1013 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1016 child = child.nextSiblingElement();
1020 void QgsManageConnectionsDialog::loadOracleConnections(
const QDomDocument &doc,
const QStringList &items )
1022 QDomElement root = doc.documentElement();
1023 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
1025 QMessageBox::information(
this,
1026 tr(
"Loading Connections" ),
1027 tr(
"The file is not an Oracle connections exchange file." ) );
1031 QString connectionName;
1033 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
1036 QDomElement child = root.firstChildElement();
1038 bool overwrite =
true;
1040 while ( !child.isNull() )
1042 connectionName = child.attribute( QStringLiteral(
"name" ) );
1043 if ( !items.contains( connectionName ) )
1045 child = child.nextSiblingElement();
1050 if ( keys.contains( connectionName ) && prompt )
1052 int res = QMessageBox::warning(
this,
1053 tr(
"Loading Connections" ),
1054 tr(
"Connection with name '%1' already exists. Overwrite?" )
1055 .arg( connectionName ),
1056 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1059 case QMessageBox::Cancel:
1061 case QMessageBox::No:
1062 child = child.nextSiblingElement();
1064 case QMessageBox::Yes:
1067 case QMessageBox::YesToAll:
1071 case QMessageBox::NoToAll:
1078 if ( keys.contains( connectionName ) && !overwrite )
1080 child = child.nextSiblingElement();
1085 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
1087 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1088 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1089 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1090 settings.
setValue( QStringLiteral(
"/dboptions" ), child.attribute( QStringLiteral(
"dboptions" ) ) );
1091 settings.
setValue( QStringLiteral(
"/dbworkspace" ), child.attribute( QStringLiteral(
"dbworkspace" ) ) );
1092 settings.
setValue( QStringLiteral(
"/schema" ), child.attribute( QStringLiteral(
"schema" ) ) );
1093 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1094 settings.
setValue( QStringLiteral(
"/userTablesOnly" ), child.attribute( QStringLiteral(
"userTablesOnly" ) ) );
1095 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ) ) );
1096 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ) ) );
1097 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1098 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1099 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1100 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1103 child = child.nextSiblingElement();
1107 void QgsManageConnectionsDialog::loadDb2Connections(
const QDomDocument &doc,
const QStringList &items )
1109 QDomElement root = doc.documentElement();
1110 if ( root.tagName() != QLatin1String(
"qgsDb2Connections" ) )
1112 QMessageBox::information(
this,
1113 tr(
"Loading Connections" ),
1114 tr(
"The file is not a DB2 connections exchange file." ) );
1118 QString connectionName;
1120 settings.
beginGroup( QStringLiteral(
"/DB2/connections" ) );
1123 QDomElement child = root.firstChildElement();
1125 bool overwrite =
true;
1127 while ( !child.isNull() )
1129 connectionName = child.attribute( QStringLiteral(
"name" ) );
1130 if ( !items.contains( connectionName ) )
1132 child = child.nextSiblingElement();
1137 if ( keys.contains( connectionName ) && prompt )
1139 int res = QMessageBox::warning(
this,
1140 tr(
"Loading Connections" ),
1141 tr(
"Connection with name '%1' already exists. Overwrite?" )
1142 .arg( connectionName ),
1143 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1146 case QMessageBox::Cancel:
1148 case QMessageBox::No:
1149 child = child.nextSiblingElement();
1151 case QMessageBox::Yes:
1154 case QMessageBox::YesToAll:
1158 case QMessageBox::NoToAll:
1165 if ( keys.contains( connectionName ) && !overwrite )
1167 child = child.nextSiblingElement();
1172 settings.
beginGroup(
"/DB2/connections/" + connectionName );
1174 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1175 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1176 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1177 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1179 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1183 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1185 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1186 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1187 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1188 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1189 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1190 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1193 child = child.nextSiblingElement();
1197 void QgsManageConnectionsDialog::loadGeonodeConnections(
const QDomDocument &doc,
const QStringList &items )
1199 QDomElement root = doc.documentElement();
1200 if ( root.tagName() != QLatin1String(
"qgsGeoNodeConnections" ) )
1202 QMessageBox::information(
this, tr(
"Loading Connections" ),
1203 tr(
"The file is not a GeoNode connections exchange file." ) );
1207 QString connectionName;
1209 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
1212 QDomElement child = root.firstChildElement();
1214 bool overwrite =
true;
1216 while ( !child.isNull() )
1218 connectionName = child.attribute( QStringLiteral(
"name" ) );
1219 if ( !items.contains( connectionName ) )
1221 child = child.nextSiblingElement();
1226 if ( keys.contains( connectionName ) && prompt )
1228 int res = QMessageBox::warning(
this,
1229 tr(
"Loading Connections" ),
1230 tr(
"Connection with name '%1' already exists. Overwrite?" )
1231 .arg( connectionName ),
1232 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1236 case QMessageBox::Cancel:
1238 case QMessageBox::No:
1239 child = child.nextSiblingElement();
1241 case QMessageBox::Yes:
1244 case QMessageBox::YesToAll:
1248 case QMessageBox::NoToAll:
1255 if ( keys.contains( connectionName ) && !overwrite )
1257 child = child.nextSiblingElement();
1262 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
1263 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
1266 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
1268 settings.
beginGroup(
"/qgis/GeoNode/" + connectionName );
1269 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1270 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1273 child = child.nextSiblingElement();
1277 void QgsManageConnectionsDialog::loadXyzTilesConnections(
const QDomDocument &doc,
const QStringList &items )
1279 QDomElement root = doc.documentElement();
1280 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
1282 QMessageBox::information(
this, tr(
"Loading Connections" ),
1283 tr(
"The file is not a XYZ Tiles connections exchange file." ) );
1287 QString connectionName;
1289 settings.
beginGroup( QStringLiteral(
"/qgis/connections-xyz" ) );
1292 QDomElement child = root.firstChildElement();
1294 bool overwrite =
true;
1296 while ( !child.isNull() )
1298 connectionName = child.attribute( QStringLiteral(
"name" ) );
1299 if ( !items.contains( connectionName ) )
1301 child = child.nextSiblingElement();
1306 if ( keys.contains( connectionName ) && prompt )
1308 int res = QMessageBox::warning(
this,
1309 tr(
"Loading Connections" ),
1310 tr(
"Connection with name '%1' already exists. Overwrite?" )
1311 .arg( connectionName ),
1312 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1316 case QMessageBox::Cancel:
1318 case QMessageBox::No:
1319 child = child.nextSiblingElement();
1321 case QMessageBox::Yes:
1324 case QMessageBox::YesToAll:
1328 case QMessageBox::NoToAll:
1335 if ( keys.contains( connectionName ) && !overwrite )
1337 child = child.nextSiblingElement();
1341 settings.
beginGroup(
"qgis/connections-xyz/" + connectionName );
1342 settings.
setValue( QStringLiteral(
"url" ), child.attribute( QStringLiteral(
"url" ) ) );
1343 settings.
setValue( QStringLiteral(
"zmin" ), child.attribute( QStringLiteral(
"zmin" ) ) );
1344 settings.
setValue( QStringLiteral(
"zmax" ), child.attribute( QStringLiteral(
"zmax" ) ) );
1345 settings.
setValue( QStringLiteral(
"authcfg" ), child.attribute( QStringLiteral(
"authcfg" ) ) );
1346 settings.
setValue( QStringLiteral(
"username" ), child.attribute( QStringLiteral(
"username" ) ) );
1347 settings.
setValue( QStringLiteral(
"password" ), child.attribute( QStringLiteral(
"password" ) ) );
1348 settings.
setValue( QStringLiteral(
"referer" ), child.attribute( QStringLiteral(
"referer" ) ) );
1351 child = child.nextSiblingElement();
1358 listConnections->selectAll();
1359 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
1364 listConnections->clearSelection();
1365 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
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.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QgsManageConnectionsDialog(QWidget *parent=nullptr, Mode mode=Export, Type type=WMS, const QString &fileName=QString())
Constructor for QgsManageConnectionsDialog.
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.