Add support for updating a uri with GeoNode WFS/WMS related connection settings

This commit is contained in:
Nyall Dawson 2017-09-12 14:12:13 +10:00
parent 05e047d779
commit ac15df9863
7 changed files with 141 additions and 10 deletions

View File

@ -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

View File

@ -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";
@ -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 );
@ -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

View File

@ -59,6 +59,18 @@ 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
@ -66,6 +78,8 @@ class CORE_EXPORT QgsGeoNodeConnection
//! Property of mUri
QgsDataSourceUri mUri;
QString settingsKey() const;
};
/**

View File

@ -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() )
{

View File

@ -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
@ -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();

View File

@ -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)

View File

@ -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()