Skip to content

Commit

Permalink
Make sure WFS/WMS settings are respected when adding GeoNode layers f…
Browse files Browse the repository at this point in the history
…rom source select dialog
  • Loading branch information
nyalldawson committed Sep 12, 2017
1 parent ac15df9 commit 687fc52
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/app/geocms/geonode/qgsgeonodenewconnection.cpp
Expand Up @@ -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" ) );

Expand Down
34 changes: 23 additions & 11 deletions src/app/geocms/geonode/qgsgeonodesourceselect.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -360,6 +360,8 @@ void QgsGeoNodeSourceSelect::addButtonClicked()
return;
}

QgsGeoNodeConnection connection = currentConnection();

QModelIndexList modelIndexList = treeView->selectionModel()->selectedRows();
for ( int i = 0; i < modelIndexList.size(); i++ )
{
Expand Down Expand Up @@ -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 );
Expand All @@ -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" ) )
{
Expand All @@ -458,3 +465,8 @@ void QgsGeoNodeSourceSelect::updateButtonStateForAvailableConnections()
btnDelete->setEnabled( connectionsAvailable );
btnSave->setEnabled( connectionsAvailable );
}

QgsGeoNodeConnection QgsGeoNodeSourceSelect::currentConnection() const
{
return QgsGeoNodeConnection( cmbConnections->currentText() );
}
2 changes: 2 additions & 0 deletions src/app/geocms/geonode/qgsgeonodesourceselect.h
Expand Up @@ -26,6 +26,7 @@
#include "qgsapplication.h"
#include "ui_qgsgeonodesourceselectbase.h"
#include "qgis_gui.h"
#include "qgsgeonodeconnection.h"

class QgsGeonodeItemDelegate : public QItemDelegate
{
Expand Down Expand Up @@ -66,6 +67,7 @@ class QgsGeoNodeSourceSelect: public QgsAbstractDataSourceWidget, private Ui::Qg
QModelIndex mSQLIndex;

void updateButtonStateForAvailableConnections();
QgsGeoNodeConnection currentConnection() const;

private slots:
void addConnectionsEntryList();
Expand Down
6 changes: 3 additions & 3 deletions src/core/geocms/geonode/qgsgeonodeconnection.cpp
Expand Up @@ -96,16 +96,16 @@ QStringList QgsGeoNodeConnectionUtils::connectionList()
{
QgsSettings settings;
// Add Section manually
settings.beginGroup( QStringLiteral( "providers/qgis/connections-geonode" ) );
settings.beginGroup( QStringLiteral( "qgis/connections-geonode" ) );
return settings.childGroups();
}

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()
Expand Down

0 comments on commit 687fc52

Please sign in to comment.