mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Merge pull request #6592 from slarosa/save_load_xyz
[FEATURE][needs-docs] Save/Load connections for XYZ Tiles
This commit is contained in:
commit
9a25d6764e
@ -31,7 +31,8 @@ class QgsManageConnectionsDialog : QDialog
|
||||
DB2,
|
||||
WCS,
|
||||
Oracle,
|
||||
GeoNode
|
||||
GeoNode,
|
||||
XyzTiles
|
||||
};
|
||||
|
||||
QgsManageConnectionsDialog( QWidget *parent /TransferThis/ = 0, Mode mode = Export, Type type = WMS, const QString &fileName = QString() );
|
||||
|
@ -133,6 +133,9 @@ void QgsManageConnectionsDialog::doExportImport()
|
||||
case GeoNode:
|
||||
doc = saveGeonodeConnections( items );
|
||||
break;
|
||||
case XyzTiles:
|
||||
doc = saveXyzTilesConnections( items );
|
||||
break;
|
||||
}
|
||||
|
||||
QFile file( mFileName );
|
||||
@ -201,6 +204,9 @@ void QgsManageConnectionsDialog::doExportImport()
|
||||
case GeoNode:
|
||||
loadGeonodeConnections( doc, items );
|
||||
break;
|
||||
case XyzTiles:
|
||||
loadXyzTilesConnections( doc, items );
|
||||
break;
|
||||
}
|
||||
// clear connections list and close window
|
||||
listConnections->clear();
|
||||
@ -242,6 +248,9 @@ bool QgsManageConnectionsDialog::populateConnections()
|
||||
case GeoNode:
|
||||
settings.beginGroup( QStringLiteral( "/qgis/connections-geonode" ) );
|
||||
break;
|
||||
case XyzTiles:
|
||||
settings.beginGroup( QStringLiteral( "/qgis/connections-xyz" ) );
|
||||
break;
|
||||
}
|
||||
QStringList keys = settings.childGroups();
|
||||
QStringList::Iterator it = keys.begin();
|
||||
@ -353,6 +362,14 @@ bool QgsManageConnectionsDialog::populateConnections()
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case XyzTiles:
|
||||
if ( root.tagName() != QLatin1String( "qgsXYZTilesConnections" ) )
|
||||
{
|
||||
QMessageBox::information( this, tr( "Loading Connections" ),
|
||||
tr( "The file is not a XYZ Tiles connections exchange file." ) );
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
QDomElement child = root.firstChildElement();
|
||||
@ -622,6 +639,35 @@ QDomDocument QgsManageConnectionsDialog::saveGeonodeConnections( const QStringLi
|
||||
return doc;
|
||||
}
|
||||
|
||||
QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections( const QStringList &connections )
|
||||
{
|
||||
QDomDocument doc( QStringLiteral( "connections" ) );
|
||||
QDomElement root = doc.createElement( QStringLiteral( "qgsXYZTilesConnections" ) );
|
||||
root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
|
||||
doc.appendChild( root );
|
||||
|
||||
QgsSettings settings;
|
||||
QString path;
|
||||
for ( int i = 0; i < connections.count(); ++i )
|
||||
{
|
||||
path = "qgis/connections-xyz/" + connections[ i ];
|
||||
QDomElement el = doc.createElement( QStringLiteral( "xyztiles" ) );
|
||||
|
||||
el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
|
||||
el.setAttribute( QStringLiteral( "url" ), settings.value( path + "/url", "" ).toString() );
|
||||
el.setAttribute( QStringLiteral( "zmin" ), settings.value( path + "/zmin", -1 ).toInt() );
|
||||
el.setAttribute( QStringLiteral( "zmax" ), settings.value( path + "/zmax", -1 ).toInt() );
|
||||
el.setAttribute( QStringLiteral( "authcfg" ), settings.value( path + "/authcfg", "" ).toString() );
|
||||
el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username", "" ).toString() );
|
||||
el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password", "" ).toString() );
|
||||
el.setAttribute( QStringLiteral( "referer" ), settings.value( path + "/referer", "" ).toString() );
|
||||
|
||||
root.appendChild( el );
|
||||
}
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
void QgsManageConnectionsDialog::loadOWSConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
|
||||
{
|
||||
QDomElement root = doc.documentElement();
|
||||
@ -1226,6 +1272,85 @@ void QgsManageConnectionsDialog::loadGeonodeConnections( const QDomDocument &doc
|
||||
}
|
||||
}
|
||||
|
||||
void QgsManageConnectionsDialog::loadXyzTilesConnections( const QDomDocument &doc, const QStringList &items )
|
||||
{
|
||||
QDomElement root = doc.documentElement();
|
||||
if ( root.tagName() != QLatin1String( "qgsXYZTilesConnections" ) )
|
||||
{
|
||||
QMessageBox::information( this, tr( "Loading Connections" ),
|
||||
tr( "The file is not a XYZ Tiles connections exchange file." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
QString connectionName;
|
||||
QgsSettings settings;
|
||||
settings.beginGroup( QStringLiteral( "/qgis/connections-xyz" ) );
|
||||
QStringList keys = settings.childGroups();
|
||||
settings.endGroup();
|
||||
QDomElement child = root.firstChildElement();
|
||||
bool prompt = true;
|
||||
bool overwrite = true;
|
||||
|
||||
while ( !child.isNull() )
|
||||
{
|
||||
connectionName = child.attribute( QStringLiteral( "name" ) );
|
||||
if ( !items.contains( connectionName ) )
|
||||
{
|
||||
child = child.nextSiblingElement();
|
||||
continue;
|
||||
}
|
||||
|
||||
// check for duplicates
|
||||
if ( keys.contains( connectionName ) && prompt )
|
||||
{
|
||||
int res = QMessageBox::warning( this,
|
||||
tr( "Loading Connections" ),
|
||||
tr( "Connection with name '%1' already exists. Overwrite?" )
|
||||
.arg( connectionName ),
|
||||
QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
|
||||
|
||||
switch ( res )
|
||||
{
|
||||
case QMessageBox::Cancel:
|
||||
return;
|
||||
case QMessageBox::No:
|
||||
child = child.nextSiblingElement();
|
||||
continue;
|
||||
case QMessageBox::Yes:
|
||||
overwrite = true;
|
||||
break;
|
||||
case QMessageBox::YesToAll:
|
||||
prompt = false;
|
||||
overwrite = true;
|
||||
break;
|
||||
case QMessageBox::NoToAll:
|
||||
prompt = false;
|
||||
overwrite = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( keys.contains( connectionName ) && !overwrite )
|
||||
{
|
||||
child = child.nextSiblingElement();
|
||||
continue;
|
||||
}
|
||||
|
||||
settings.beginGroup( "qgis/connections-xyz/" + connectionName );
|
||||
settings.setValue( QStringLiteral( "url" ), child.attribute( QStringLiteral( "url" ) ) );
|
||||
settings.setValue( QStringLiteral( "zmin" ), child.attribute( QStringLiteral( "zmin" ) ) );
|
||||
settings.setValue( QStringLiteral( "zmax" ), child.attribute( QStringLiteral( "zmax" ) ) );
|
||||
settings.setValue( QStringLiteral( "authcfg" ), child.attribute( QStringLiteral( "authcfg" ) ) );
|
||||
settings.setValue( QStringLiteral( "username" ), child.attribute( QStringLiteral( "username" ) ) );
|
||||
settings.setValue( QStringLiteral( "password" ), child.attribute( QStringLiteral( "password" ) ) );
|
||||
settings.setValue( QStringLiteral( "referer" ), child.attribute( QStringLiteral( "referer" ) ) );
|
||||
settings.endGroup();
|
||||
|
||||
child = child.nextSiblingElement();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QgsManageConnectionsDialog::selectAll()
|
||||
{
|
||||
listConnections->selectAll();
|
||||
|
@ -48,7 +48,8 @@ class GUI_EXPORT QgsManageConnectionsDialog : public QDialog, private Ui::QgsMan
|
||||
DB2,
|
||||
WCS,
|
||||
Oracle,
|
||||
GeoNode
|
||||
GeoNode,
|
||||
XyzTiles
|
||||
};
|
||||
|
||||
/**
|
||||
@ -72,6 +73,7 @@ class GUI_EXPORT QgsManageConnectionsDialog : public QDialog, private Ui::QgsMan
|
||||
QDomDocument saveOracleConnections( const QStringList &connections );
|
||||
QDomDocument saveDb2Connections( const QStringList &connections );
|
||||
QDomDocument saveGeonodeConnections( const QStringList &connections );
|
||||
QDomDocument saveXyzTilesConnections( const QStringList &connections );
|
||||
|
||||
void loadOWSConnections( const QDomDocument &doc, const QStringList &items, const QString &service );
|
||||
void loadWfsConnections( const QDomDocument &doc, const QStringList &items );
|
||||
@ -80,6 +82,7 @@ class GUI_EXPORT QgsManageConnectionsDialog : public QDialog, private Ui::QgsMan
|
||||
void loadOracleConnections( const QDomDocument &doc, const QStringList &items );
|
||||
void loadDb2Connections( const QDomDocument &doc, const QStringList &items );
|
||||
void loadGeonodeConnections( const QDomDocument &doc, const QStringList &items );
|
||||
void loadXyzTilesConnections( const QDomDocument &doc, const QStringList &items );
|
||||
|
||||
QString mFileName;
|
||||
Mode mDialogMode;
|
||||
|
@ -27,12 +27,14 @@
|
||||
#include "qgsnewhttpconnection.h"
|
||||
#include "qgstilescalewidget.h"
|
||||
#include "qgsxyzconnectiondialog.h"
|
||||
#include "qgsmanageconnectionsdialog.h"
|
||||
#endif
|
||||
#include "qgsgeonodeconnection.h"
|
||||
#include "qgsgeonoderequest.h"
|
||||
#include "qgssettings.h"
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QFileDialog>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
QgsWMSConnectionItem::QgsWMSConnectionItem( QgsDataItem *parent, QString name, QString path, QString uri )
|
||||
@ -474,9 +476,20 @@ QVector<QgsDataItem *> QgsXyzTileRootItem::createChildren()
|
||||
#ifdef HAVE_GUI
|
||||
QList<QAction *> QgsXyzTileRootItem::actions( QWidget *parent )
|
||||
{
|
||||
QList<QAction *> lst;
|
||||
|
||||
QAction *actionNew = new QAction( tr( "New Connection…" ), parent );
|
||||
connect( actionNew, &QAction::triggered, this, &QgsXyzTileRootItem::newConnection );
|
||||
return QList<QAction *>() << actionNew;
|
||||
QAction *saveXyzTilesServers = new QAction( tr( "Save Connections…" ), parent );
|
||||
connect( saveXyzTilesServers, &QAction::triggered, this, &QgsXyzTileRootItem::saveXyzTilesServers );
|
||||
QAction *loadXyzTilesServers = new QAction( tr( "Load Connections…" ), parent );
|
||||
connect( loadXyzTilesServers, &QAction::triggered, this, &QgsXyzTileRootItem::loadXyzTilesServers );
|
||||
|
||||
lst.append( actionNew );
|
||||
lst.append( saveXyzTilesServers );
|
||||
lst.append( loadXyzTilesServers );
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
void QgsXyzTileRootItem::newConnection()
|
||||
@ -488,6 +501,26 @@ void QgsXyzTileRootItem::newConnection()
|
||||
QgsXyzConnectionUtils::addConnection( dlg.connection() );
|
||||
refreshConnections();
|
||||
}
|
||||
|
||||
void QgsXyzTileRootItem::saveXyzTilesServers()
|
||||
{
|
||||
QgsManageConnectionsDialog dlg( nullptr, QgsManageConnectionsDialog::Export, QgsManageConnectionsDialog::XyzTiles );
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
void QgsXyzTileRootItem::loadXyzTilesServers()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName( nullptr, tr( "Load Connections" ), QDir::homePath(),
|
||||
tr( "XML files (*.xml *XML)" ) );
|
||||
if ( fileName.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsManageConnectionsDialog dlg( nullptr, QgsManageConnectionsDialog::Import, QgsManageConnectionsDialog::XyzTiles, fileName );
|
||||
dlg.exec();
|
||||
refreshConnections();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -146,6 +146,8 @@ class QgsXyzTileRootItem : public QgsDataCollectionItem
|
||||
private slots:
|
||||
#ifdef HAVE_GUI
|
||||
void newConnection();
|
||||
void saveXyzTilesServers();
|
||||
void loadXyzTilesServers();
|
||||
#endif
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user