From 687fc52a1d8f341dacb185e27e4c454c8a1667ea Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 12 Sep 2017 14:48:53 +1000 Subject: [PATCH] Make sure WFS/WMS settings are respected when adding GeoNode layers from source select dialog --- .../geonode/qgsgeonodenewconnection.cpp | 2 +- .../geocms/geonode/qgsgeonodesourceselect.cpp | 34 +++++++++++++------ .../geocms/geonode/qgsgeonodesourceselect.h | 2 ++ .../geocms/geonode/qgsgeonodeconnection.cpp | 6 ++-- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/app/geocms/geonode/qgsgeonodenewconnection.cpp b/src/app/geocms/geonode/qgsgeonodenewconnection.cpp index 13b4cfbb250d..ae5295d8a6c8 100644 --- a/src/app/geocms/geonode/qgsgeonodenewconnection.cpp +++ b/src/app/geocms/geonode/qgsgeonodenewconnection.cpp @@ -21,7 +21,7 @@ #include "qgsgeonoderequest.h" QgsGeoNodeNewConnection::QgsGeoNodeNewConnection( QWidget *parent, const QString &connName, Qt::WindowFlags fl ) - : QgsNewHttpConnection( parent, 0, QgsGeoNodeConnectionUtils::pathGeoNodeConnection(), connName, QgsNewHttpConnection::FlagShowTestConnection, fl ) + : QgsNewHttpConnection( parent, 0, QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + '/', connName, QgsNewHttpConnection::FlagShowTestConnection, fl ) { setWindowTitle( tr( "Create a New GeoNode Connection" ) ); diff --git a/src/app/geocms/geonode/qgsgeonodesourceselect.cpp b/src/app/geocms/geonode/qgsgeonodesourceselect.cpp index 15319291e0ae..f200d1add4bd 100644 --- a/src/app/geocms/geonode/qgsgeonodesourceselect.cpp +++ b/src/app/geocms/geonode/qgsgeonodesourceselect.cpp @@ -150,7 +150,7 @@ void QgsGeoNodeSourceSelect::showHelp() void QgsGeoNodeSourceSelect::connectToGeonodeConnection() { - QgsGeoNodeConnection connection( cmbConnections->currentText() ); + QgsGeoNodeConnection connection = currentConnection(); QString url = connection.uri().param( QStringLiteral( "url" ) ); QgsGeoNodeRequest *geonodeRequest = new QgsGeoNodeRequest( url, true ); @@ -360,6 +360,8 @@ void QgsGeoNodeSourceSelect::addButtonClicked() return; } + QgsGeoNodeConnection connection = currentConnection(); + QModelIndexList modelIndexList = treeView->selectionModel()->selectedRows(); for ( int i = 0; i < modelIndexList.size(); i++ ) { @@ -396,6 +398,8 @@ void QgsGeoNodeSourceSelect::addButtonClicked() QString styles; QString contextualWMSLegend( QStringLiteral( "0" ) ); + connection.addWmsConnectionSettings( uri ); + uri.setParam( QStringLiteral( "contextualWMSLegend" ), contextualWMSLegend ); uri.setParam( QStringLiteral( "layers" ), layerName ); uri.setParam( QStringLiteral( "styles" ), styles ); @@ -414,25 +418,28 @@ void QgsGeoNodeSourceSelect::addButtonClicked() // typeName, titleName, sql, // Build url for WFS // restrictToRequestBBOX='1' srsname='EPSG:26719' typename='geonode:cab_mun' url='http://demo.geonode.org/geoserver/geonode/wms' table=\"\" sql=" - QString uri; - uri += QStringLiteral( " restrictToRequestBBOX='1'" ); - uri += QStringLiteral( " srsname='%1'" ).arg( crs ); + QgsDataSourceUri uri; + + uri.setParam( QStringLiteral( "restrictToRequestBBOX" ), "1" ); + uri.setParam( QStringLiteral( "srsname" ), crs ); if ( serviceURL.contains( QStringLiteral( "qgis-server" ) ) ) { // I need to do this since the typename used in qgis-server is without the workspace. QString qgisServerTypeName = QString( typeName ).split( ':' ).last(); - uri += QStringLiteral( " typename='%1'" ).arg( qgisServerTypeName ); + uri.setParam( QStringLiteral( "typename" ), qgisServerTypeName ); } else { - uri += QStringLiteral( " typename='%1'" ).arg( typeName ); + uri.setParam( QStringLiteral( "typename" ), typeName ); } - uri += QStringLiteral( " url='%1'" ).arg( serviceURL ); - uri += QStringLiteral( " table=\"\"" ); - uri += QStringLiteral( " sql=" ); + uri.setParam( QStringLiteral( "url" ), serviceURL ); + //uri.setParam( QStringLiteral( "table" ), QStringLiteral( "\"\"" ) ); + //uri.setParam( QStringLiteral( "sql" ), QString() ); - QgsDebugMsg( "Add WFS from GeoNode : " + uri + " and typename: " + typeName ); - emit addVectorLayer( uri, typeName, QStringLiteral( "WFS" ) ); + connection.addWfsConnectionSettings( uri ); + + QgsDebugMsg( "Add WFS from GeoNode : " + uri.uri() + " and typename: " + typeName ); + emit addVectorLayer( uri.uri(), typeName, QStringLiteral( "WFS" ) ); } else if ( webServiceType == QStringLiteral( "XYZ" ) ) { @@ -458,3 +465,8 @@ void QgsGeoNodeSourceSelect::updateButtonStateForAvailableConnections() btnDelete->setEnabled( connectionsAvailable ); btnSave->setEnabled( connectionsAvailable ); } + +QgsGeoNodeConnection QgsGeoNodeSourceSelect::currentConnection() const +{ + return QgsGeoNodeConnection( cmbConnections->currentText() ); +} diff --git a/src/app/geocms/geonode/qgsgeonodesourceselect.h b/src/app/geocms/geonode/qgsgeonodesourceselect.h index 0da0310d201f..af08bc545222 100644 --- a/src/app/geocms/geonode/qgsgeonodesourceselect.h +++ b/src/app/geocms/geonode/qgsgeonodesourceselect.h @@ -26,6 +26,7 @@ #include "qgsapplication.h" #include "ui_qgsgeonodesourceselectbase.h" #include "qgis_gui.h" +#include "qgsgeonodeconnection.h" class QgsGeonodeItemDelegate : public QItemDelegate { @@ -66,6 +67,7 @@ class QgsGeoNodeSourceSelect: public QgsAbstractDataSourceWidget, private Ui::Qg QModelIndex mSQLIndex; void updateButtonStateForAvailableConnections(); + QgsGeoNodeConnection currentConnection() const; private slots: void addConnectionsEntryList(); diff --git a/src/core/geocms/geonode/qgsgeonodeconnection.cpp b/src/core/geocms/geonode/qgsgeonodeconnection.cpp index 89ef3e636850..0706bb3195b3 100644 --- a/src/core/geocms/geonode/qgsgeonodeconnection.cpp +++ b/src/core/geocms/geonode/qgsgeonodeconnection.cpp @@ -96,7 +96,7 @@ QStringList QgsGeoNodeConnectionUtils::connectionList() { QgsSettings settings; // Add Section manually - settings.beginGroup( QStringLiteral( "providers/qgis/connections-geonode" ) ); + settings.beginGroup( QStringLiteral( "qgis/connections-geonode" ) ); return settings.childGroups(); } @@ -104,8 +104,8 @@ void QgsGeoNodeConnectionUtils::deleteConnection( const QString &name ) { QgsSettings settings; // Add Section manually - settings.remove( QStringLiteral( "providers/qgis/connections-geonode/" ) + name ); - settings.remove( QStringLiteral( "providers/qgis/geonode/" ) + name ); + settings.remove( QStringLiteral( "qgis/connections-geonode/" ) + name ); + settings.remove( QStringLiteral( "qgis/geonode/" ) + name ); } QString QgsGeoNodeConnectionUtils::pathGeoNodeConnection()