Skip to content

Commit

Permalink
Add support for updating a uri with GeoNode WFS/WMS related connectio…
Browse files Browse the repository at this point in the history
…n settings
  • Loading branch information
nyalldawson committed Sep 12, 2017
1 parent 05e047d commit ac15df9
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 10 deletions.
14 changes: 14 additions & 0 deletions python/core/geocms/geonode/qgsgeonodeconnection.sip
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ class QgsGeoNodeConnection
.. seealso:: uri()
%End

QgsDataSourceUri &addWmsConnectionSettings( QgsDataSourceUri &uri ) const;
%Docstring
Adds uri parameters relating to the settings for a WMS layer on the connection to a QgsDataSourceUri ``uri``.
.. seealso:: addWmsWcsConnectionSettings()
:rtype: QgsDataSourceUri
%End

QgsDataSourceUri &addWfsConnectionSettings( QgsDataSourceUri &uri ) const;
%Docstring
Adds uri parameters relating to the settings for a WFS layer on the connection to a QgsDataSourceUri ``uri``.
.. seealso:: addWmsWcsConnectionSettings()
:rtype: QgsDataSourceUri
%End

};

class QgsGeoNodeConnectionUtils
Expand Down
26 changes: 21 additions & 5 deletions src/core/geocms/geonode/qgsgeonodeconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "qgsgeonodeconnection.h"
#include "qgslogger.h"
#include "qgsdatasourceuri.h"
#include "qgsowsconnection.h"

const QString QgsGeoNodeConnectionUtils::sPathGeoNodeConnection = "qgis/connections-geonode";
const QString QgsGeoNodeConnectionUtils::sPathGeoNodeConnectionDetails = "qgis/GeoNode";
Expand All @@ -27,21 +28,21 @@ QgsGeoNodeConnection::QgsGeoNodeConnection( const QString &name )
QgsSettings settings;

// settings.Section
QString key = QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/" ) + mConnName;
QString key = settingsKey();
QString credentialsKey = QgsGeoNodeConnectionUtils::pathGeoNodeConnectionDetails() + QStringLiteral( "/" ) + mConnName;

mUri.setParam( QStringLiteral( "url" ), settings.value( key + QStringLiteral( "/url" ), QString(), QgsSettings::Providers ).toString() );
mUri.setParam( QStringLiteral( "url" ), settings.value( key + QStringLiteral( "/url" ), QString() ).toString() );

// Check for credentials and prepend to the connection info
QString username = settings.value( credentialsKey + QStringLiteral( "/username" ), QString(), QgsSettings::Providers ).toString();
QString password = settings.value( credentialsKey + QStringLiteral( "/password" ), QString(), QgsSettings::Providers ).toString();
QString username = settings.value( credentialsKey + QStringLiteral( "/username" ), QString() ).toString();
QString password = settings.value( credentialsKey + QStringLiteral( "/password" ), QString() ).toString();
if ( !username.isEmpty() )
{
mUri.setParam( QStringLiteral( "username" ), username );
mUri.setParam( QStringLiteral( "password" ), password );
}

QString authcfg = settings.value( credentialsKey + QStringLiteral( "/authcfg" ), QString(), QgsSettings::Providers ).toString();
QString authcfg = settings.value( credentialsKey + QStringLiteral( "/authcfg" ), QString() ).toString();
if ( !authcfg.isEmpty() )
{
mUri.setParam( QStringLiteral( "authcfg" ), authcfg );
Expand Down Expand Up @@ -70,6 +71,21 @@ void QgsGeoNodeConnection::setUri( const QgsDataSourceUri &uri )
mUri = uri;
}

QgsDataSourceUri &QgsGeoNodeConnection::addWmsConnectionSettings( QgsDataSourceUri &uri ) const
{
return QgsOwsConnection::addWmsWcsConnectionSettings( uri, settingsKey() + QStringLiteral( "/wms" ) );
}

QgsDataSourceUri &QgsGeoNodeConnection::addWfsConnectionSettings( QgsDataSourceUri &uri ) const
{
return QgsOwsConnection::addWfsConnectionSettings( uri, settingsKey() + QStringLiteral( "/wfs" ) );
}

QString QgsGeoNodeConnection::settingsKey() const
{
return QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/" ) + mConnName;
}


//
// QgsGeoNodeConnectionUtils
Expand Down
14 changes: 14 additions & 0 deletions src/core/geocms/geonode/qgsgeonodeconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,27 @@ class CORE_EXPORT QgsGeoNodeConnection
*/
void setUri( const QgsDataSourceUri &uri );

/**
* Adds uri parameters relating to the settings for a WMS layer on the connection to a QgsDataSourceUri \a uri.
* \see addWmsWcsConnectionSettings()
*/
QgsDataSourceUri &addWmsConnectionSettings( QgsDataSourceUri &uri ) const;

/**
* Adds uri parameters relating to the settings for a WFS layer on the connection to a QgsDataSourceUri \a uri.
* \see addWmsWcsConnectionSettings()
*/
QgsDataSourceUri &addWfsConnectionSettings( QgsDataSourceUri &uri ) const;

private:

//! The connection name
QString mConnName;

//! Property of mUri
QgsDataSourceUri mUri;

QString settingsKey() const;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ QVector<QgsDataItem *> QgsWmsDataItemProvider::createDataItems( const QString &p
QgsSettings settings;
QString key( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + "/" + connectionName );

QString dpiMode = settings.value( key + "/wms/dpiMode", "all", QgsSettings::Providers ).toString();
QString dpiMode = settings.value( key + "/wms/dpiMode", "all" ).toString();
uri.setParam( QStringLiteral( "url" ), encodedUri );
if ( !dpiMode.isEmpty() )
{
Expand Down
8 changes: 4 additions & 4 deletions tests/src/core/testqgsgeonodeconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ void TestQgsGeoNodeConnection::initTestCase()
QgsSettings settings;

// Testing real server, demo.geonode.org. Need to be changed later.
settings.setValue( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/%1/url" ).arg( mDemoGeoNodeName ), mDemoGeoNodeURL, QgsSettings::Providers );
settings.setValue( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/%1/url" ).arg( mDemoGeoNodeName ), mDemoGeoNodeURL );
// Testing real server, staging.geonode.kartoza.com. Need to be changed later.
settings.setValue( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/%1/url" ).arg( mKartozaGeoNodeQGISServerName ), mKartozaGeoNodeQGISServerURL, QgsSettings::Providers );
settings.setValue( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/%1/url" ).arg( mKartozaGeoNodeQGISServerName ), mKartozaGeoNodeQGISServerURL );
// Testing real server, staginggs.geonode.kartoza.com. Need to be changed later.
settings.setValue( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/%1/url" ).arg( mKartozaGeoNodeGeoServerName ), mKartozaGeoNodeGeoServerURL, QgsSettings::Providers );
settings.setValue( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/%1/url" ).arg( mKartozaGeoNodeGeoServerName ), mKartozaGeoNodeGeoServerURL );
}

// Test the creation of geonode connection
Expand All @@ -108,7 +108,7 @@ void TestQgsGeoNodeConnection::testCreation()
// Add new GeoNode Connection
QgsSettings settings;

settings.setValue( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/%1/url" ).arg( mGeoNodeConnectionName ), mGeoNodeConnectionURL, QgsSettings::Providers );
settings.setValue( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/%1/url" ).arg( mGeoNodeConnectionName ), mGeoNodeConnectionURL );

QStringList newConnectionList = QgsGeoNodeConnectionUtils::connectionList();
int newNumberOfConnection = newConnectionList.count();
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ADD_PYTHON_TEST(PyQgsFilterLineEdit test_qgsfilterlineedit.py)
ADD_PYTHON_TEST(PyQgsFloatingWidget test_qgsfloatingwidget.py)
ADD_PYTHON_TEST(PyQgsFontButton test_qgsfontbutton.py)
ADD_PYTHON_TEST(PyQgsFontUtils test_qgsfontutils.py)
ADD_PYTHON_TEST(PyQgsGeoNodeConnection test_qgsgeonodeconnection.py)
ADD_PYTHON_TEST(PyQgsGeometryAvoidIntersections test_qgsgeometry_avoid_intersections.py)
ADD_PYTHON_TEST(PyQgsGeometryGeneratorSymbolLayer test_qgsgeometrygeneratorsymbollayer.py)
ADD_PYTHON_TEST(PyQgsGeometryTest test_qgsgeometry.py)
Expand Down
86 changes: 86 additions & 0 deletions tests/src/python/test_qgsgeonodeconnection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsGeoNodeConnection
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Nyall Dawson'
__date__ = '12.09.2017'
__copyright__ = 'Copyright 2017, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # NOQA

from qgis.testing import unittest, start_app
from qgis.core import (QgsGeoNodeConnectionUtils,
QgsGeoNodeConnection,
QgsDataSourceUri,
QgsSettings)
from qgis.PyQt.QtCore import QCoreApplication


class TestQgsGeoNodeConnection(unittest.TestCase):

@classmethod
def setUpClass(cls):
"""Run before all tests"""
QCoreApplication.setOrganizationName("QGIS_Test")
QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsColorScheme.com")
QCoreApplication.setApplicationName("QGIS_TestPyQgsColorScheme")
QgsSettings().clear()
start_app()

# setup a fake connection
settings = QgsSettings()
key = QgsGeoNodeConnectionUtils.pathGeoNodeConnection() + '/test/'

settings.setValue(key + 'wms/referer', 'my_ref')
settings.setValue(key + 'wms/ignoreGetMapURI', True)
settings.setValue(key + 'wms/ignoreGetFeatureInfoURI', True)
settings.setValue(key + 'wms/smoothPixmapTransform', True)
settings.setValue(key + 'wms/dpiMode', 4)
settings.setValue(key + 'wms/ignoreAxisOrientation', True)
settings.setValue(key + 'wms/invertAxisOrientation', True)

settings.setValue(key + 'wfs/version', '1.1.0')
settings.setValue(key + 'wfs/maxnumfeatures', '47')
settings.setValue(key + 'wfs/ignoreAxisOrientation', True)
settings.setValue(key + 'wfs/invertAxisOrientation', True)

def testWmsConnection(self):
"""
Test adding GeoNode WMS related connection settings to a uri
"""
c = QgsGeoNodeConnection('test')

uri = c.uri()
c.addWmsConnectionSettings(uri)

self.assertEqual(uri.param('referer'), 'my_ref')
self.assertEqual(uri.param('IgnoreGetMapUrl'), '1')
self.assertEqual(uri.param('IgnoreGetFeatureInfoUrl'), '1')
self.assertEqual(uri.param('SmoothPixmapTransform'), '1')
self.assertEqual(uri.param('dpiMode'), '4')
self.assertEqual(uri.param('IgnoreAxisOrientation'), '1')
self.assertEqual(uri.param('InvertAxisOrientation'), '1')

def testWfsConnection(self):
"""
Test adding GeoNode WFS related connection settings to a uri
"""
c = QgsGeoNodeConnection('test')

uri = c.uri()
c.addWfsConnectionSettings(uri)

self.assertEqual(uri.param('version'), '1.1.0')
self.assertEqual(uri.param('maxNumFeatures'), '47')
self.assertEqual(uri.param('IgnoreAxisOrientation'), '1')
self.assertEqual(uri.param('InvertAxisOrientation'), '1')


if __name__ == "__main__":
unittest.main()

0 comments on commit ac15df9

Please sign in to comment.