Skip to content

Commit 8486767

Browse files
committedAug 22, 2017
Support removal of global defined XYZ connections
1 parent 273243b commit 8486767

File tree

7 files changed

+73
-24
lines changed

7 files changed

+73
-24
lines changed
 

‎python/core/qgssettings.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ Returns a list of all top-level keys that can be read using the QSettings object
155155
%Docstring
156156
Returns a list of all key top-level groups that contain keys that can be read using the QSettings object.
157157
:rtype: list of str
158+
%End
159+
QStringList globalChildGroups() const;
160+
%Docstring
161+
Returns a list of all key top-level groups (same as childGroups) but only for groups defined in global settings.
162+
:rtype: list of str
158163
%End
159164
static QString globalSettingsPath();
160165
%Docstring

‎src/core/qgssettings.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ QStringList QgsSettings::childGroups() const
149149
}
150150
return keys;
151151
}
152+
QStringList QgsSettings::globalChildGroups() const
153+
{
154+
QStringList keys;
155+
if ( mGlobalSettings )
156+
{
157+
QStringList keys = mGlobalSettings->childGroups();
158+
}
159+
return keys;
160+
}
152161

153162
QVariant QgsSettings::value( const QString &key, const QVariant &defaultValue, const QgsSettings::Section section ) const
154163
{

‎src/core/qgssettings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ class CORE_EXPORT QgsSettings : public QObject
150150
QStringList childKeys() const;
151151
//! Returns a list of all key top-level groups that contain keys that can be read using the QSettings object.
152152
QStringList childGroups() const;
153+
//! Returns a list of all key top-level groups (same as childGroups) but only for groups defined in global settings.
154+
QStringList globalChildGroups() const;
153155
//! Return the path to the Global Settings QSettings storage file
154156
static QString globalSettingsPath() { return sGlobalSettingsPath; }
155157
//! Set the Global Settings QSettings storage file

‎src/providers/wms/qgswmssourceselect.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "qgswmsprovider.h"
2222
#include "qgis.h" // GEO_EPSG_CRS_ID
23-
#include "qgscontexthelp.h"
2423
#include "qgscoordinatereferencesystem.h"
2524
#include "qgsdatasourceuri.h"
2625
#include "qgsprojectionselectiondialog.h"

‎src/providers/wms/qgsxyzconnection.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* *
1414
***************************************************************************/
1515

16+
#include <qgslogger.h>
1617
#include "qgsxyzconnection.h"
1718

1819
#include "qgsdatasourceuri.h"
@@ -41,8 +42,27 @@ QString QgsXyzConnection::encodedUri() const
4142
QStringList QgsXyzConnectionUtils::connectionList()
4243
{
4344
QgsSettings settings;
45+
QStringList connList;
46+
4447
settings.beginGroup( QStringLiteral( "qgis/connections-xyz" ) );
45-
return settings.childGroups();
48+
connList = settings.childGroups();
49+
50+
QStringList global = settings.globalChildGroups();
51+
settings.endGroup();
52+
53+
for ( auto &s : global )
54+
{
55+
settings.beginGroup( "qgis/connections-xyz/" + s );
56+
bool isHidden = settings.value( QStringLiteral( "hidden" ), false ).toBool();
57+
QString url = settings.value( QStringLiteral( "url" ), "" ).toString();
58+
settings.endGroup();
59+
if ( isHidden )
60+
{
61+
connList.removeOne( s );
62+
}
63+
}
64+
65+
return connList;
4666
}
4767

4868
QgsXyzConnection QgsXyzConnectionUtils::connection( const QString &name )
@@ -59,18 +79,40 @@ QgsXyzConnection QgsXyzConnectionUtils::connection( const QString &name )
5979
conn.username = settings.value( QStringLiteral( "username" ) ).toString();
6080
conn.password = settings.value( QStringLiteral( "password" ) ).toString();
6181
conn.referer = settings.value( QStringLiteral( "referer" ) ).toString();
82+
conn.hidden = settings.value( QStringLiteral( "hidden" ) ).toBool();
6283
return conn;
6384
}
6485

6586
void QgsXyzConnectionUtils::deleteConnection( const QString &name )
6687
{
6788
QgsSettings settings;
6889
settings.remove( "qgis/connections-xyz/" + name );
90+
91+
settings.beginGroup( QStringLiteral( "qgis/connections-xyz" ) );
92+
QStringList global = settings.globalChildGroups();
93+
94+
if ( global.contains( name ) )
95+
{
96+
QgsSettings settings;
97+
settings.beginGroup( "qgis/connections-xyz/" + name );
98+
settings.setValue( QStringLiteral( "hidden" ), true );
99+
}
100+
69101
}
70102

71103
void QgsXyzConnectionUtils::addConnection( const QgsXyzConnection &conn )
72104
{
73105
QgsSettings settings;
106+
bool addHiddenProperty = false;
107+
108+
settings.beginGroup( QStringLiteral( "qgis/connections-xyz" ) );
109+
QStringList global = settings.globalChildGroups();
110+
if ( global.contains( conn.name ) )
111+
{
112+
addHiddenProperty = true;
113+
}
114+
settings.endGroup();
115+
74116
settings.beginGroup( "qgis/connections-xyz/" + conn.name );
75117
settings.setValue( QStringLiteral( "url" ), conn.url );
76118
settings.setValue( QStringLiteral( "zmin" ), conn.zMin );
@@ -79,4 +121,9 @@ void QgsXyzConnectionUtils::addConnection( const QgsXyzConnection &conn )
79121
settings.setValue( QStringLiteral( "username" ), conn.username );
80122
settings.setValue( QStringLiteral( "password" ), conn.password );
81123
settings.setValue( QStringLiteral( "referer" ), conn.referer );
124+
if ( addHiddenProperty )
125+
{
126+
settings.setValue( QStringLiteral( "hidden" ), false );
127+
}
128+
82129
}

‎src/providers/wms/qgsxyzconnection.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct QgsXyzConnection
3232
QString password;
3333
// Referer
3434
QString referer;
35+
bool hidden;
3536

3637
QString encodedUri() const;
3738
};
@@ -40,7 +41,7 @@ struct QgsXyzConnection
4041
class QgsXyzConnectionUtils
4142
{
4243
public:
43-
//! Returns list of existing connections
44+
//! Returns list of existing connections, unless the hidden ones
4445
static QStringList connectionList();
4546

4647
//! Returns connection details
@@ -54,4 +55,4 @@ class QgsXyzConnectionUtils
5455
};
5556

5657

57-
#endif // QGSXYZCONNECTION_H
58+
#endif // QGSXYZCONNECTION_H

‎tests/src/python/test_qgis_global_settings.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,14 @@
2828

2929
start_app()
3030

31+
3132
def createXYZLayerFromURL(url):
3233
typeandurl = "type=xyz&url=" + url
3334
osm = QgsRasterLayer(typeandurl, "OpenStreetMap", "wms")
3435
return osm
3536

36-
class TestQgsGlobalSettings(unittest.TestCase):
37-
38-
def setUp(self):
39-
"""Run before each test."""
40-
qDebug('setUp')
41-
pass
4237

43-
def tearDown(self):
44-
"""Run after each test."""
45-
qDebug('tearDown')
46-
pass
38+
class TestQgsGlobalSettings(unittest.TestCase):
4739

4840
def test_global_settings_exist(self):
4941
qDebug('QgsApplication.pkgDataPath(): {0}'.format(QgsApplication.pkgDataPath()))
@@ -52,18 +44,12 @@ def test_global_settings_exist(self):
5244
QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/qgis_global_settings.ini')
5345
self.settings = QgsSettings('testqgissettings', 'testqgissettings')
5446
settings = QgsSettings()
55-
qDebug('settings.allKeys(): {0}'.format(settings.allKeys()))
47+
# qDebug('settings.allKeys(): {0}'.format(settings.allKeys()))
5648
defaulturl = settings.value('qgis/connections-xyz/OpenStreetMap/url')
49+
self.assertEqual(defaulturl, 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png')
50+
layer = createXYZLayerFromURL(defaulturl)
51+
self.assertEqual(layer.name(), 'OpenStreetMap')
5752

58-
def testKey():
59-
self.assertEqual(defaulturl, 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png')
60-
61-
def testLayer():
62-
layer = createXYZLayerFromURL(defaulturl)
63-
self.assertEqual(layer.name(), 'OpenStreetMap')
64-
65-
testKey()
66-
testLayer()
6753

6854
if __name__ == '__main__':
6955
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.