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 );
138 QFile file( mFileName );
139 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
141 QMessageBox::warning(
this, tr(
"Saving Connections" ),
142 tr(
"Cannot write file %1:\n%2." )
144 file.errorString() ) );
148 QTextStream out( &file );
153 QFile file( mFileName );
154 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
156 QMessageBox::warning(
this, tr(
"Loading Connections" ),
157 tr(
"Cannot read file %1:\n%2." )
159 file.errorString() ) );
168 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
170 QMessageBox::warning(
this, tr(
"Loading Connections" ),
171 tr(
"Parse error at line %1, column %2:\n%3" )
178 switch ( mConnectionType )
181 loadOWSConnections( doc, items, QStringLiteral(
"WMS" ) );
184 loadWfsConnections( doc, items );
187 loadPgConnections( doc, items );
190 loadMssqlConnections( doc, items );
193 loadOWSConnections( doc, items, QStringLiteral(
"WCS" ) );
196 loadOracleConnections( doc, items );
199 loadDb2Connections( doc, items );
202 loadGeonodeConnections( doc, items );
206 listConnections->clear();
213 bool QgsManageConnectionsDialog::populateConnections()
216 if ( mDialogMode ==
Export )
219 switch ( mConnectionType )
222 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wms" ) );
225 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
228 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wcs" ) );
231 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
234 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
237 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
240 settings.
beginGroup( QStringLiteral(
"/DB2/connections" ) );
243 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
247 QStringList::Iterator it = keys.begin();
248 while ( it != keys.end() )
250 QListWidgetItem *item =
new QListWidgetItem();
251 item->setText( *it );
252 listConnections->addItem( item );
260 QFile file( mFileName );
261 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
263 QMessageBox::warning(
this, tr(
"Loading Connections" ),
264 tr(
"Cannot read file %1:\n%2." )
266 file.errorString() ) );
275 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
277 QMessageBox::warning(
this, tr(
"Loading Connections" ),
278 tr(
"Parse error at line %1, column %2:\n%3" )
285 QDomElement root = doc.documentElement();
286 switch ( mConnectionType )
289 if ( root.tagName() != QLatin1String(
"qgsWMSConnections" ) )
291 QMessageBox::information(
this, tr(
"Loading Connections" ),
292 tr(
"The file is not a WMS connections exchange file." ) );
298 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
300 QMessageBox::information(
this, tr(
"Loading Connections" ),
301 tr(
"The file is not a WFS connections exchange file." ) );
307 if ( root.tagName() != QLatin1String(
"qgsWCSConnections" ) )
309 QMessageBox::information(
this, tr(
"Loading Connections" ),
310 tr(
"The file is not a WCS connections exchange file." ) );
316 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
318 QMessageBox::information(
this, tr(
"Loading Connections" ),
319 tr(
"The file is not a PostGIS connections exchange file." ) );
325 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
327 QMessageBox::information(
this, tr(
"Loading Connections" ),
328 tr(
"The file is not a MSSQL connections exchange file." ) );
333 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
335 QMessageBox::information(
this, tr(
"Loading Connections" ),
336 tr(
"The file is not an Oracle connections exchange file." ) );
341 if ( root.tagName() != QLatin1String(
"qgsDb2Connections" ) )
343 QMessageBox::information(
this, tr(
"Loading Connections" ),
344 tr(
"The file is not a DB2 connections exchange file." ) );
349 if ( root.tagName() != QLatin1String(
"qgsGeoNodeConnections" ) )
351 QMessageBox::information(
this, tr(
"Loading Connections" ),
352 tr(
"The file is not a GeoNode connections exchange file." ) );
358 QDomElement child = root.firstChildElement();
359 while ( !child.isNull() )
361 QListWidgetItem *item =
new QListWidgetItem();
362 item->setText( child.attribute( QStringLiteral(
"name" ) ) );
363 listConnections->addItem( item );
364 child = child.nextSiblingElement();
370 QDomDocument QgsManageConnectionsDialog::saveOWSConnections(
const QStringList &connections,
const QString &service )
372 QDomDocument doc( QStringLiteral(
"connections" ) );
373 QDomElement root = doc.createElement(
"qgs" + service.toUpper() +
"Connections" );
374 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
375 doc.appendChild( root );
379 for (
int i = 0; i < connections.count(); ++i )
381 path =
"/qgis/connections-" + service.toLower() +
'/';
382 QDomElement el = doc.createElement( service.toLower() );
383 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
384 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url",
"" ).toString() );
386 if ( service == QLatin1String(
"WMS" ) )
388 el.setAttribute( QStringLiteral(
"ignoreGetMapURI" ), settings.
value( path + connections[i] +
"/ignoreGetMapURI",
false ).toBool() ?
"true" :
"false" );
389 el.setAttribute( QStringLiteral(
"ignoreGetFeatureInfoURI" ), settings.
value( path + connections[i] +
"/ignoreGetFeatureInfoURI",
false ).toBool() ?
"true" :
"false" );
390 el.setAttribute( QStringLiteral(
"ignoreAxisOrientation" ), settings.
value( path + connections[i] +
"/ignoreAxisOrientation",
false ).toBool() ?
"true" :
"false" );
391 el.setAttribute( QStringLiteral(
"invertAxisOrientation" ), settings.
value( path + connections[i] +
"/invertAxisOrientation",
false ).toBool() ?
"true" :
"false" );
392 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path + connections[ i ] +
"/referer",
"" ).toString() );
393 el.setAttribute( QStringLiteral(
"smoothPixmapTransform" ), settings.
value( path + connections[i] +
"/smoothPixmapTransform",
false ).toBool() ?
"true" :
"false" );
394 el.setAttribute( QStringLiteral(
"dpiMode" ), settings.
value( path + connections[i] +
"/dpiMode",
"7" ).toInt() );
397 path =
"/qgis/" + service.toUpper() +
'/';
398 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username",
"" ).toString() );
399 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password",
"" ).toString() );
400 root.appendChild( el );
406 QDomDocument QgsManageConnectionsDialog::saveWfsConnections(
const QStringList &connections )
408 QDomDocument doc( QStringLiteral(
"connections" ) );
409 QDomElement root = doc.createElement( QStringLiteral(
"qgsWFSConnections" ) );
410 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
411 doc.appendChild( root );
415 for (
int i = 0; i < connections.count(); ++i )
417 path = QStringLiteral(
"/qgis/connections-wfs/" );
418 QDomElement el = doc.createElement( QStringLiteral(
"wfs" ) );
419 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
420 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url",
"" ).toString() );
422 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path + connections[ i ] +
"/referer",
"" ).toString() );
424 path = QStringLiteral(
"/qgis/WFS/" );
425 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username",
"" ).toString() );
426 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password",
"" ).toString() );
427 root.appendChild( el );
433 QDomDocument QgsManageConnectionsDialog::savePgConnections(
const QStringList &connections )
435 QDomDocument doc( QStringLiteral(
"connections" ) );
436 QDomElement root = doc.createElement( QStringLiteral(
"qgsPgConnections" ) );
437 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
438 doc.appendChild( root );
442 for (
int i = 0; i < connections.count(); ++i )
444 path =
"/PostgreSQL/connections/" + connections[ i ];
445 QDomElement el = doc.createElement( QStringLiteral(
"postgis" ) );
446 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
447 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host",
"" ).toString() );
448 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port",
"" ).toString() );
449 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database",
"" ).toString() );
450 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service",
"" ).toString() );
451 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
452 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
454 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
456 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
458 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username",
"" ).toString() );
461 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
463 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
465 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password",
"" ).toString() );
468 root.appendChild( el );
474 QDomDocument QgsManageConnectionsDialog::saveMssqlConnections(
const QStringList &connections )
476 QDomDocument doc( QStringLiteral(
"connections" ) );
477 QDomElement root = doc.createElement( QStringLiteral(
"qgsMssqlConnections" ) );
478 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
479 doc.appendChild( root );
483 for (
int i = 0; i < connections.count(); ++i )
485 path =
"/MSSQL/connections/" + connections[ i ];
486 QDomElement el = doc.createElement( QStringLiteral(
"mssql" ) );
487 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
488 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host",
"" ).toString() );
489 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port",
"" ).toString() );
490 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database",
"" ).toString() );
491 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service",
"" ).toString() );
492 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
493 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
495 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
497 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
499 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username",
"" ).toString() );
502 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
504 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
506 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password",
"" ).toString() );
509 root.appendChild( el );
515 QDomDocument QgsManageConnectionsDialog::saveOracleConnections(
const QStringList &connections )
517 QDomDocument doc( QStringLiteral(
"connections" ) );
518 QDomElement root = doc.createElement( QStringLiteral(
"qgsOracleConnections" ) );
519 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
520 doc.appendChild( root );
524 for (
int i = 0; i < connections.count(); ++i )
526 path =
"/Oracle/connections/" + connections[ i ];
527 QDomElement el = doc.createElement( QStringLiteral(
"oracle" ) );
528 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
529 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host",
"" ).toString() );
530 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port",
"" ).toString() );
531 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database",
"" ).toString() );
532 el.setAttribute( QStringLiteral(
"dboptions" ), settings.
value( path +
"/dboptions",
"" ).toString() );
533 el.setAttribute( QStringLiteral(
"dbworkspace" ), settings.
value( path +
"/dbworkspace",
"" ).toString() );
534 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
535 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly",
"0" ).toString() );
536 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
537 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
539 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
541 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
543 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username",
"" ).toString() );
546 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
548 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
550 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password",
"" ).toString() );
553 root.appendChild( el );
559 QDomDocument QgsManageConnectionsDialog::saveDb2Connections(
const QStringList &connections )
561 QDomDocument doc( QStringLiteral(
"connections" ) );
562 QDomElement root = doc.createElement( QStringLiteral(
"qgsDb2Connections" ) );
563 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
564 doc.appendChild( root );
568 for (
int i = 0; i < connections.count(); ++i )
570 path =
"/DB2/connections/" + connections[ i ];
571 QDomElement el = doc.createElement( QStringLiteral(
"db2" ) );
572 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
573 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host",
"" ).toString() );
574 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port",
"" ).toString() );
575 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database",
"" ).toString() );
576 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service",
"" ).toString() );
577 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
578 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
580 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
582 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
584 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username",
"" ).toString() );
587 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
589 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
591 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password",
"" ).toString() );
594 root.appendChild( el );
600 QDomDocument QgsManageConnectionsDialog::saveGeonodeConnections(
const QStringList &connections )
602 QDomDocument doc( QStringLiteral(
"connections" ) );
603 QDomElement root = doc.createElement( QStringLiteral(
"qgsGeoNodeConnections" ) );
604 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
605 doc.appendChild( root );
609 for (
int i = 0; i < connections.count(); ++i )
611 path = QStringLiteral(
"/qgis/connections-geonode/" );
612 QDomElement el = doc.createElement( QStringLiteral(
"geonode" ) );
613 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
614 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url",
"" ).toString() );
616 path = QStringLiteral(
"/qgis/GeoNode/" );
617 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username",
"" ).toString() );
618 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password",
"" ).toString() );
619 root.appendChild( el );
625 void QgsManageConnectionsDialog::loadOWSConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
627 QDomElement root = doc.documentElement();
628 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
630 QMessageBox::information(
this, tr(
"Loading Connections" ),
631 tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
635 QString connectionName;
637 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
640 QDomElement child = root.firstChildElement();
642 bool overwrite =
true;
644 while ( !child.isNull() )
646 connectionName = child.attribute( QStringLiteral(
"name" ) );
647 if ( !items.contains( connectionName ) )
649 child = child.nextSiblingElement();
654 if ( keys.contains( connectionName ) && prompt )
656 int res = QMessageBox::warning(
this,
657 tr(
"Loading Connections" ),
658 tr(
"Connection with name '%1' already exists. Overwrite?" )
659 .arg( connectionName ),
660 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
664 case QMessageBox::Cancel:
666 case QMessageBox::No:
667 child = child.nextSiblingElement();
669 case QMessageBox::Yes:
672 case QMessageBox::YesToAll:
676 case QMessageBox::NoToAll:
683 if ( keys.contains( connectionName ) && !overwrite )
685 child = child.nextSiblingElement();
690 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
691 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
692 settings.
setValue( QString(
'/' + connectionName +
"/ignoreGetMapURI" ), child.attribute( QStringLiteral(
"ignoreGetMapURI" ) ) == QLatin1String(
"true" ) );
693 settings.
setValue( QString(
'/' + connectionName +
"/ignoreGetFeatureInfoURI" ), child.attribute( QStringLiteral(
"ignoreGetFeatureInfoURI" ) ) == QLatin1String(
"true" ) );
694 settings.
setValue( QString(
'/' + connectionName +
"/ignoreAxisOrientation" ), child.attribute( QStringLiteral(
"ignoreAxisOrientation" ) ) == QLatin1String(
"true" ) );
695 settings.
setValue( QString(
'/' + connectionName +
"/invertAxisOrientation" ), child.attribute( QStringLiteral(
"invertAxisOrientation" ) ) == QLatin1String(
"true" ) );
696 settings.
setValue( QString(
'/' + connectionName +
"/referer" ), child.attribute( QStringLiteral(
"referer" ) ) );
697 settings.
setValue( QString(
'/' + connectionName +
"/smoothPixmapTransform" ), child.attribute( QStringLiteral(
"smoothPixmapTransform" ) ) == QLatin1String(
"true" ) );
698 settings.
setValue( QString(
'/' + connectionName +
"/dpiMode" ), child.attribute( QStringLiteral(
"dpiMode" ), QStringLiteral(
"7" ) ).toInt() );
701 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
703 settings.
beginGroup(
"/qgis/" + service.toUpper() +
'/' + connectionName );
704 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
705 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
708 child = child.nextSiblingElement();
712 void QgsManageConnectionsDialog::loadWfsConnections(
const QDomDocument &doc,
const QStringList &items )
714 QDomElement root = doc.documentElement();
715 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
717 QMessageBox::information(
this, tr(
"Loading Connections" ),
718 tr(
"The file is not a WFS connections exchange file." ) );
722 QString connectionName;
724 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
727 QDomElement child = root.firstChildElement();
729 bool overwrite =
true;
731 while ( !child.isNull() )
733 connectionName = child.attribute( QStringLiteral(
"name" ) );
734 if ( !items.contains( connectionName ) )
736 child = child.nextSiblingElement();
741 if ( keys.contains( connectionName ) && prompt )
743 int res = QMessageBox::warning(
this,
744 tr(
"Loading Connections" ),
745 tr(
"Connection with name '%1' already exists. Overwrite?" )
746 .arg( connectionName ),
747 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
751 case QMessageBox::Cancel:
753 case QMessageBox::No:
754 child = child.nextSiblingElement();
756 case QMessageBox::Yes:
759 case QMessageBox::YesToAll:
763 case QMessageBox::NoToAll:
770 if ( keys.contains( connectionName ) && !overwrite )
772 child = child.nextSiblingElement();
777 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
778 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
781 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
783 settings.
beginGroup(
"/qgis/WFS/" + connectionName );
784 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
785 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
788 child = child.nextSiblingElement();
793 void QgsManageConnectionsDialog::loadPgConnections(
const QDomDocument &doc,
const QStringList &items )
795 QDomElement root = doc.documentElement();
796 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
798 QMessageBox::information(
this,
799 tr(
"Loading Connections" ),
800 tr(
"The file is not a PostGIS connections exchange file." ) );
804 QString connectionName;
806 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
809 QDomElement child = root.firstChildElement();
811 bool overwrite =
true;
813 while ( !child.isNull() )
815 connectionName = child.attribute( QStringLiteral(
"name" ) );
816 if ( !items.contains( connectionName ) )
818 child = child.nextSiblingElement();
823 if ( keys.contains( connectionName ) && prompt )
825 int res = QMessageBox::warning(
this,
826 tr(
"Loading Connections" ),
827 tr(
"Connection with name '%1' already exists. Overwrite?" )
828 .arg( connectionName ),
829 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
832 case QMessageBox::Cancel:
834 case QMessageBox::No:
835 child = child.nextSiblingElement();
837 case QMessageBox::Yes:
840 case QMessageBox::YesToAll:
844 case QMessageBox::NoToAll:
851 if ( keys.contains( connectionName ) && !overwrite )
853 child = child.nextSiblingElement();
858 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
860 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
861 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
862 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
863 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
865 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
869 settings.
setValue( QStringLiteral(
"/service" ),
"" );
871 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
872 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
873 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
874 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
875 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
876 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
879 child = child.nextSiblingElement();
883 void QgsManageConnectionsDialog::loadMssqlConnections(
const QDomDocument &doc,
const QStringList &items )
885 QDomElement root = doc.documentElement();
886 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
888 QMessageBox::information(
this,
889 tr(
"Loading Connections" ),
890 tr(
"The file is not a MSSQL connections exchange file." ) );
894 QString connectionName;
896 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
899 QDomElement child = root.firstChildElement();
901 bool overwrite =
true;
903 while ( !child.isNull() )
905 connectionName = child.attribute( QStringLiteral(
"name" ) );
906 if ( !items.contains( connectionName ) )
908 child = child.nextSiblingElement();
913 if ( keys.contains( connectionName ) && prompt )
915 int res = QMessageBox::warning(
this,
916 tr(
"Loading Connections" ),
917 tr(
"Connection with name '%1' already exists. Overwrite?" )
918 .arg( connectionName ),
919 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
922 case QMessageBox::Cancel:
924 case QMessageBox::No:
925 child = child.nextSiblingElement();
927 case QMessageBox::Yes:
930 case QMessageBox::YesToAll:
934 case QMessageBox::NoToAll:
941 if ( keys.contains( connectionName ) && !overwrite )
943 child = child.nextSiblingElement();
948 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
950 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
951 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
952 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
953 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
955 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
959 settings.
setValue( QStringLiteral(
"/service" ),
"" );
961 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
962 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
963 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
964 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
965 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
966 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
969 child = child.nextSiblingElement();
973 void QgsManageConnectionsDialog::loadOracleConnections(
const QDomDocument &doc,
const QStringList &items )
975 QDomElement root = doc.documentElement();
976 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
978 QMessageBox::information(
this,
979 tr(
"Loading Connections" ),
980 tr(
"The file is not an Oracle connections exchange file." ) );
984 QString connectionName;
986 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
989 QDomElement child = root.firstChildElement();
991 bool overwrite =
true;
993 while ( !child.isNull() )
995 connectionName = child.attribute( QStringLiteral(
"name" ) );
996 if ( !items.contains( connectionName ) )
998 child = child.nextSiblingElement();
1003 if ( keys.contains( connectionName ) && prompt )
1005 int res = QMessageBox::warning(
this,
1006 tr(
"Loading Connections" ),
1007 tr(
"Connection with name '%1' already exists. Overwrite?" )
1008 .arg( connectionName ),
1009 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1012 case QMessageBox::Cancel:
1014 case QMessageBox::No:
1015 child = child.nextSiblingElement();
1017 case QMessageBox::Yes:
1020 case QMessageBox::YesToAll:
1024 case QMessageBox::NoToAll:
1031 if ( keys.contains( connectionName ) && !overwrite )
1033 child = child.nextSiblingElement();
1038 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
1040 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1041 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1042 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1043 settings.
setValue( QStringLiteral(
"/dboptions" ), child.attribute( QStringLiteral(
"dboptions" ) ) );
1044 settings.
setValue( QStringLiteral(
"/dbworkspace" ), child.attribute( QStringLiteral(
"dbworkspace" ) ) );
1045 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1046 settings.
setValue( QStringLiteral(
"/userTablesOnly" ), child.attribute( QStringLiteral(
"userTablesOnly" ) ) );
1047 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ) ) );
1048 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ) ) );
1049 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1050 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1051 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1052 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1055 child = child.nextSiblingElement();
1059 void QgsManageConnectionsDialog::loadDb2Connections(
const QDomDocument &doc,
const QStringList &items )
1061 QDomElement root = doc.documentElement();
1062 if ( root.tagName() != QLatin1String(
"qgsDb2Connections" ) )
1064 QMessageBox::information(
this,
1065 tr(
"Loading Connections" ),
1066 tr(
"The file is not a DB2 connections exchange file." ) );
1070 QString connectionName;
1072 settings.
beginGroup( QStringLiteral(
"/DB2/connections" ) );
1075 QDomElement child = root.firstChildElement();
1077 bool overwrite =
true;
1079 while ( !child.isNull() )
1081 connectionName = child.attribute( QStringLiteral(
"name" ) );
1082 if ( !items.contains( connectionName ) )
1084 child = child.nextSiblingElement();
1089 if ( keys.contains( connectionName ) && prompt )
1091 int res = QMessageBox::warning(
this,
1092 tr(
"Loading Connections" ),
1093 tr(
"Connection with name '%1' already exists. Overwrite?" )
1094 .arg( connectionName ),
1095 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1098 case QMessageBox::Cancel:
1100 case QMessageBox::No:
1101 child = child.nextSiblingElement();
1103 case QMessageBox::Yes:
1106 case QMessageBox::YesToAll:
1110 case QMessageBox::NoToAll:
1117 if ( keys.contains( connectionName ) && !overwrite )
1119 child = child.nextSiblingElement();
1124 settings.
beginGroup(
"/DB2/connections/" + connectionName );
1126 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1127 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1128 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1129 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1131 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1135 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1137 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1138 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1139 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1140 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1141 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1142 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1145 child = child.nextSiblingElement();
1149 void QgsManageConnectionsDialog::loadGeonodeConnections(
const QDomDocument &doc,
const QStringList &items )
1151 QDomElement root = doc.documentElement();
1152 if ( root.tagName() != QLatin1String(
"qgsGeoNodeConnections" ) )
1154 QMessageBox::information(
this, tr(
"Loading Connections" ),
1155 tr(
"The file is not a GeoNode connections exchange file." ) );
1159 QString connectionName;
1161 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
1164 QDomElement child = root.firstChildElement();
1166 bool overwrite =
true;
1168 while ( !child.isNull() )
1170 connectionName = child.attribute( QStringLiteral(
"name" ) );
1171 if ( !items.contains( connectionName ) )
1173 child = child.nextSiblingElement();
1178 if ( keys.contains( connectionName ) && prompt )
1180 int res = QMessageBox::warning(
this,
1181 tr(
"Loading Connections" ),
1182 tr(
"Connection with name '%1' already exists. Overwrite?" )
1183 .arg( connectionName ),
1184 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1188 case QMessageBox::Cancel:
1190 case QMessageBox::No:
1191 child = child.nextSiblingElement();
1193 case QMessageBox::Yes:
1196 case QMessageBox::YesToAll:
1200 case QMessageBox::NoToAll:
1207 if ( keys.contains( connectionName ) && !overwrite )
1209 child = child.nextSiblingElement();
1214 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
1215 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
1218 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
1220 settings.
beginGroup(
"/qgis/GeoNode/" + connectionName );
1221 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1222 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1225 child = child.nextSiblingElement();
1231 listConnections->selectAll();
1232 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
1237 listConnections->clearSelection();
1238 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:
void beginGroup(const QString &prefix, const QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QgsManageConnectionsDialog(QWidget *parent=nullptr, Mode mode=Export, Type type=WMS, const QString &fileName=QString())
Constructor for QgsManageConnectionsDialog.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.