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" #include "qgsgeonoderequest.h"


QgsGeoNodeNewConnection::QgsGeoNodeNewConnection( QWidget *parent, const QString &connName, Qt::WindowFlags fl ) 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" ) ); 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() void QgsGeoNodeSourceSelect::connectToGeonodeConnection()
{ {
QgsGeoNodeConnection connection( cmbConnections->currentText() ); QgsGeoNodeConnection connection = currentConnection();


QString url = connection.uri().param( QStringLiteral( "url" ) ); QString url = connection.uri().param( QStringLiteral( "url" ) );
QgsGeoNodeRequest *geonodeRequest = new QgsGeoNodeRequest( url, true ); QgsGeoNodeRequest *geonodeRequest = new QgsGeoNodeRequest( url, true );
Expand Down Expand Up @@ -360,6 +360,8 @@ void QgsGeoNodeSourceSelect::addButtonClicked()
return; return;
} }


QgsGeoNodeConnection connection = currentConnection();

QModelIndexList modelIndexList = treeView->selectionModel()->selectedRows(); QModelIndexList modelIndexList = treeView->selectionModel()->selectedRows();
for ( int i = 0; i < modelIndexList.size(); i++ ) for ( int i = 0; i < modelIndexList.size(); i++ )
{ {
Expand Down Expand Up @@ -396,6 +398,8 @@ void QgsGeoNodeSourceSelect::addButtonClicked()
QString styles; QString styles;
QString contextualWMSLegend( QStringLiteral( "0" ) ); QString contextualWMSLegend( QStringLiteral( "0" ) );


connection.addWmsConnectionSettings( uri );

uri.setParam( QStringLiteral( "contextualWMSLegend" ), contextualWMSLegend ); uri.setParam( QStringLiteral( "contextualWMSLegend" ), contextualWMSLegend );
uri.setParam( QStringLiteral( "layers" ), layerName ); uri.setParam( QStringLiteral( "layers" ), layerName );
uri.setParam( QStringLiteral( "styles" ), styles ); uri.setParam( QStringLiteral( "styles" ), styles );
Expand All @@ -414,25 +418,28 @@ void QgsGeoNodeSourceSelect::addButtonClicked()
// typeName, titleName, sql, // typeName, titleName, sql,
// Build url for WFS // Build url for WFS
// restrictToRequestBBOX='1' srsname='EPSG:26719' typename='geonode:cab_mun' url='http://demo.geonode.org/geoserver/geonode/wms' table=\"\" sql=" // restrictToRequestBBOX='1' srsname='EPSG:26719' typename='geonode:cab_mun' url='http://demo.geonode.org/geoserver/geonode/wms' table=\"\" sql="
QString uri; QgsDataSourceUri uri;
uri += QStringLiteral( " restrictToRequestBBOX='1'" );
uri += QStringLiteral( " srsname='%1'" ).arg( crs ); uri.setParam( QStringLiteral( "restrictToRequestBBOX" ), "1" );
uri.setParam( QStringLiteral( "srsname" ), crs );
if ( serviceURL.contains( QStringLiteral( "qgis-server" ) ) ) if ( serviceURL.contains( QStringLiteral( "qgis-server" ) ) )
{ {
// I need to do this since the typename used in qgis-server is without the workspace. // I need to do this since the typename used in qgis-server is without the workspace.
QString qgisServerTypeName = QString( typeName ).split( ':' ).last(); QString qgisServerTypeName = QString( typeName ).split( ':' ).last();
uri += QStringLiteral( " typename='%1'" ).arg( qgisServerTypeName ); uri.setParam( QStringLiteral( "typename" ), qgisServerTypeName );
} }
else else
{ {
uri += QStringLiteral( " typename='%1'" ).arg( typeName ); uri.setParam( QStringLiteral( "typename" ), typeName );
} }
uri += QStringLiteral( " url='%1'" ).arg( serviceURL ); uri.setParam( QStringLiteral( "url" ), serviceURL );
uri += QStringLiteral( " table=\"\"" ); //uri.setParam( QStringLiteral( "table" ), QStringLiteral( "\"\"" ) );
uri += QStringLiteral( " sql=" ); //uri.setParam( QStringLiteral( "sql" ), QString() );


QgsDebugMsg( "Add WFS from GeoNode : " + uri + " and typename: " + typeName ); connection.addWfsConnectionSettings( uri );
emit addVectorLayer( uri, typeName, QStringLiteral( "WFS" ) );
QgsDebugMsg( "Add WFS from GeoNode : " + uri.uri() + " and typename: " + typeName );
emit addVectorLayer( uri.uri(), typeName, QStringLiteral( "WFS" ) );
} }
else if ( webServiceType == QStringLiteral( "XYZ" ) ) else if ( webServiceType == QStringLiteral( "XYZ" ) )
{ {
Expand All @@ -458,3 +465,8 @@ void QgsGeoNodeSourceSelect::updateButtonStateForAvailableConnections()
btnDelete->setEnabled( connectionsAvailable ); btnDelete->setEnabled( connectionsAvailable );
btnSave->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 "qgsapplication.h"
#include "ui_qgsgeonodesourceselectbase.h" #include "ui_qgsgeonodesourceselectbase.h"
#include "qgis_gui.h" #include "qgis_gui.h"
#include "qgsgeonodeconnection.h"


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


void updateButtonStateForAvailableConnections(); void updateButtonStateForAvailableConnections();
QgsGeoNodeConnection currentConnection() const;


private slots: private slots:
void addConnectionsEntryList(); 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; QgsSettings settings;
// Add Section manually // Add Section manually
settings.beginGroup( QStringLiteral( "providers/qgis/connections-geonode" ) ); settings.beginGroup( QStringLiteral( "qgis/connections-geonode" ) );
return settings.childGroups(); return settings.childGroups();
} }


void QgsGeoNodeConnectionUtils::deleteConnection( const QString &name ) void QgsGeoNodeConnectionUtils::deleteConnection( const QString &name )
{ {
QgsSettings settings; QgsSettings settings;
// Add Section manually // Add Section manually
settings.remove( QStringLiteral( "providers/qgis/connections-geonode/" ) + name ); settings.remove( QStringLiteral( "qgis/connections-geonode/" ) + name );
settings.remove( QStringLiteral( "providers/qgis/geonode/" ) + name ); settings.remove( QStringLiteral( "qgis/geonode/" ) + name );
} }


QString QgsGeoNodeConnectionUtils::pathGeoNodeConnection() QString QgsGeoNodeConnectionUtils::pathGeoNodeConnection()
Expand Down

0 comments on commit 687fc52

Please sign in to comment.