Skip to content

Commit ac15df9

Browse files
committedSep 12, 2017
Add support for updating a uri with GeoNode WFS/WMS related connection settings
1 parent 05e047d commit ac15df9

File tree

7 files changed

+141
-10
lines changed

7 files changed

+141
-10
lines changed
 

‎python/core/geocms/geonode/qgsgeonodeconnection.sip

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ class QgsGeoNodeConnection
5151
.. seealso:: uri()
5252
%End
5353

54+
QgsDataSourceUri &addWmsConnectionSettings( QgsDataSourceUri &uri ) const;
55+
%Docstring
56+
Adds uri parameters relating to the settings for a WMS layer on the connection to a QgsDataSourceUri ``uri``.
57+
.. seealso:: addWmsWcsConnectionSettings()
58+
:rtype: QgsDataSourceUri
59+
%End
60+
61+
QgsDataSourceUri &addWfsConnectionSettings( QgsDataSourceUri &uri ) const;
62+
%Docstring
63+
Adds uri parameters relating to the settings for a WFS layer on the connection to a QgsDataSourceUri ``uri``.
64+
.. seealso:: addWmsWcsConnectionSettings()
65+
:rtype: QgsDataSourceUri
66+
%End
67+
5468
};
5569

5670
class QgsGeoNodeConnectionUtils

‎src/core/geocms/geonode/qgsgeonodeconnection.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "qgsgeonodeconnection.h"
1818
#include "qgslogger.h"
1919
#include "qgsdatasourceuri.h"
20+
#include "qgsowsconnection.h"
2021

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

2930
// settings.Section
30-
QString key = QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/" ) + mConnName;
31+
QString key = settingsKey();
3132
QString credentialsKey = QgsGeoNodeConnectionUtils::pathGeoNodeConnectionDetails() + QStringLiteral( "/" ) + mConnName;
3233

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

3536
// Check for credentials and prepend to the connection info
36-
QString username = settings.value( credentialsKey + QStringLiteral( "/username" ), QString(), QgsSettings::Providers ).toString();
37-
QString password = settings.value( credentialsKey + QStringLiteral( "/password" ), QString(), QgsSettings::Providers ).toString();
37+
QString username = settings.value( credentialsKey + QStringLiteral( "/username" ), QString() ).toString();
38+
QString password = settings.value( credentialsKey + QStringLiteral( "/password" ), QString() ).toString();
3839
if ( !username.isEmpty() )
3940
{
4041
mUri.setParam( QStringLiteral( "username" ), username );
4142
mUri.setParam( QStringLiteral( "password" ), password );
4243
}
4344

44-
QString authcfg = settings.value( credentialsKey + QStringLiteral( "/authcfg" ), QString(), QgsSettings::Providers ).toString();
45+
QString authcfg = settings.value( credentialsKey + QStringLiteral( "/authcfg" ), QString() ).toString();
4546
if ( !authcfg.isEmpty() )
4647
{
4748
mUri.setParam( QStringLiteral( "authcfg" ), authcfg );
@@ -70,6 +71,21 @@ void QgsGeoNodeConnection::setUri( const QgsDataSourceUri &uri )
7071
mUri = uri;
7172
}
7273

74+
QgsDataSourceUri &QgsGeoNodeConnection::addWmsConnectionSettings( QgsDataSourceUri &uri ) const
75+
{
76+
return QgsOwsConnection::addWmsWcsConnectionSettings( uri, settingsKey() + QStringLiteral( "/wms" ) );
77+
}
78+
79+
QgsDataSourceUri &QgsGeoNodeConnection::addWfsConnectionSettings( QgsDataSourceUri &uri ) const
80+
{
81+
return QgsOwsConnection::addWfsConnectionSettings( uri, settingsKey() + QStringLiteral( "/wfs" ) );
82+
}
83+
84+
QString QgsGeoNodeConnection::settingsKey() const
85+
{
86+
return QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/" ) + mConnName;
87+
}
88+
7389

7490
//
7591
// QgsGeoNodeConnectionUtils

‎src/core/geocms/geonode/qgsgeonodeconnection.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,27 @@ class CORE_EXPORT QgsGeoNodeConnection
5959
*/
6060
void setUri( const QgsDataSourceUri &uri );
6161

62+
/**
63+
* Adds uri parameters relating to the settings for a WMS layer on the connection to a QgsDataSourceUri \a uri.
64+
* \see addWmsWcsConnectionSettings()
65+
*/
66+
QgsDataSourceUri &addWmsConnectionSettings( QgsDataSourceUri &uri ) const;
67+
68+
/**
69+
* Adds uri parameters relating to the settings for a WFS layer on the connection to a QgsDataSourceUri \a uri.
70+
* \see addWmsWcsConnectionSettings()
71+
*/
72+
QgsDataSourceUri &addWfsConnectionSettings( QgsDataSourceUri &uri ) const;
73+
6274
private:
6375

6476
//! The connection name
6577
QString mConnName;
6678

6779
//! Property of mUri
6880
QgsDataSourceUri mUri;
81+
82+
QString settingsKey() const;
6983
};
7084

7185
/**

‎src/providers/wms/qgswmsdataitems.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ QVector<QgsDataItem *> QgsWmsDataItemProvider::createDataItems( const QString &p
577577
QgsSettings settings;
578578
QString key( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + "/" + connectionName );
579579

580-
QString dpiMode = settings.value( key + "/wms/dpiMode", "all", QgsSettings::Providers ).toString();
580+
QString dpiMode = settings.value( key + "/wms/dpiMode", "all" ).toString();
581581
uri.setParam( QStringLiteral( "url" ), encodedUri );
582582
if ( !dpiMode.isEmpty() )
583583
{

‎tests/src/core/testqgsgeonodeconnection.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ void TestQgsGeoNodeConnection::initTestCase()
8484
QgsSettings settings;
8585

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

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

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

113113
QStringList newConnectionList = QgsGeoNodeConnectionUtils::connectionList();
114114
int newNumberOfConnection = newConnectionList.count();

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ADD_PYTHON_TEST(PyQgsFilterLineEdit test_qgsfilterlineedit.py)
6565
ADD_PYTHON_TEST(PyQgsFloatingWidget test_qgsfloatingwidget.py)
6666
ADD_PYTHON_TEST(PyQgsFontButton test_qgsfontbutton.py)
6767
ADD_PYTHON_TEST(PyQgsFontUtils test_qgsfontutils.py)
68+
ADD_PYTHON_TEST(PyQgsGeoNodeConnection test_qgsgeonodeconnection.py)
6869
ADD_PYTHON_TEST(PyQgsGeometryAvoidIntersections test_qgsgeometry_avoid_intersections.py)
6970
ADD_PYTHON_TEST(PyQgsGeometryGeneratorSymbolLayer test_qgsgeometrygeneratorsymbollayer.py)
7071
ADD_PYTHON_TEST(PyQgsGeometryTest test_qgsgeometry.py)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsGeoNodeConnection
3+
4+
.. note:: This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 2 of the License, or
7+
(at your option) any later version.
8+
"""
9+
__author__ = 'Nyall Dawson'
10+
__date__ = '12.09.2017'
11+
__copyright__ = 'Copyright 2017, The QGIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
import qgis # NOQA
16+
17+
from qgis.testing import unittest, start_app
18+
from qgis.core import (QgsGeoNodeConnectionUtils,
19+
QgsGeoNodeConnection,
20+
QgsDataSourceUri,
21+
QgsSettings)
22+
from qgis.PyQt.QtCore import QCoreApplication
23+
24+
25+
class TestQgsGeoNodeConnection(unittest.TestCase):
26+
27+
@classmethod
28+
def setUpClass(cls):
29+
"""Run before all tests"""
30+
QCoreApplication.setOrganizationName("QGIS_Test")
31+
QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsColorScheme.com")
32+
QCoreApplication.setApplicationName("QGIS_TestPyQgsColorScheme")
33+
QgsSettings().clear()
34+
start_app()
35+
36+
# setup a fake connection
37+
settings = QgsSettings()
38+
key = QgsGeoNodeConnectionUtils.pathGeoNodeConnection() + '/test/'
39+
40+
settings.setValue(key + 'wms/referer', 'my_ref')
41+
settings.setValue(key + 'wms/ignoreGetMapURI', True)
42+
settings.setValue(key + 'wms/ignoreGetFeatureInfoURI', True)
43+
settings.setValue(key + 'wms/smoothPixmapTransform', True)
44+
settings.setValue(key + 'wms/dpiMode', 4)
45+
settings.setValue(key + 'wms/ignoreAxisOrientation', True)
46+
settings.setValue(key + 'wms/invertAxisOrientation', True)
47+
48+
settings.setValue(key + 'wfs/version', '1.1.0')
49+
settings.setValue(key + 'wfs/maxnumfeatures', '47')
50+
settings.setValue(key + 'wfs/ignoreAxisOrientation', True)
51+
settings.setValue(key + 'wfs/invertAxisOrientation', True)
52+
53+
def testWmsConnection(self):
54+
"""
55+
Test adding GeoNode WMS related connection settings to a uri
56+
"""
57+
c = QgsGeoNodeConnection('test')
58+
59+
uri = c.uri()
60+
c.addWmsConnectionSettings(uri)
61+
62+
self.assertEqual(uri.param('referer'), 'my_ref')
63+
self.assertEqual(uri.param('IgnoreGetMapUrl'), '1')
64+
self.assertEqual(uri.param('IgnoreGetFeatureInfoUrl'), '1')
65+
self.assertEqual(uri.param('SmoothPixmapTransform'), '1')
66+
self.assertEqual(uri.param('dpiMode'), '4')
67+
self.assertEqual(uri.param('IgnoreAxisOrientation'), '1')
68+
self.assertEqual(uri.param('InvertAxisOrientation'), '1')
69+
70+
def testWfsConnection(self):
71+
"""
72+
Test adding GeoNode WFS related connection settings to a uri
73+
"""
74+
c = QgsGeoNodeConnection('test')
75+
76+
uri = c.uri()
77+
c.addWfsConnectionSettings(uri)
78+
79+
self.assertEqual(uri.param('version'), '1.1.0')
80+
self.assertEqual(uri.param('maxNumFeatures'), '47')
81+
self.assertEqual(uri.param('IgnoreAxisOrientation'), '1')
82+
self.assertEqual(uri.param('InvertAxisOrientation'), '1')
83+
84+
85+
if __name__ == "__main__":
86+
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.