mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Support removal of global defined XYZ connections
This commit is contained in:
parent
273243b4c4
commit
8486767fa3
@ -155,6 +155,11 @@ Returns a list of all top-level keys that can be read using the QSettings object
|
||||
%Docstring
|
||||
Returns a list of all key top-level groups that contain keys that can be read using the QSettings object.
|
||||
:rtype: list of str
|
||||
%End
|
||||
QStringList globalChildGroups() const;
|
||||
%Docstring
|
||||
Returns a list of all key top-level groups (same as childGroups) but only for groups defined in global settings.
|
||||
:rtype: list of str
|
||||
%End
|
||||
static QString globalSettingsPath();
|
||||
%Docstring
|
||||
|
@ -149,6 +149,15 @@ QStringList QgsSettings::childGroups() const
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
QStringList QgsSettings::globalChildGroups() const
|
||||
{
|
||||
QStringList keys;
|
||||
if ( mGlobalSettings )
|
||||
{
|
||||
QStringList keys = mGlobalSettings->childGroups();
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
QVariant QgsSettings::value( const QString &key, const QVariant &defaultValue, const QgsSettings::Section section ) const
|
||||
{
|
||||
|
@ -150,6 +150,8 @@ class CORE_EXPORT QgsSettings : public QObject
|
||||
QStringList childKeys() const;
|
||||
//! Returns a list of all key top-level groups that contain keys that can be read using the QSettings object.
|
||||
QStringList childGroups() const;
|
||||
//! Returns a list of all key top-level groups (same as childGroups) but only for groups defined in global settings.
|
||||
QStringList globalChildGroups() const;
|
||||
//! Return the path to the Global Settings QSettings storage file
|
||||
static QString globalSettingsPath() { return sGlobalSettingsPath; }
|
||||
//! Set the Global Settings QSettings storage file
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "qgswmsprovider.h"
|
||||
#include "qgis.h" // GEO_EPSG_CRS_ID
|
||||
#include "qgscontexthelp.h"
|
||||
#include "qgscoordinatereferencesystem.h"
|
||||
#include "qgsdatasourceuri.h"
|
||||
#include "qgsprojectionselectiondialog.h"
|
||||
|
@ -13,6 +13,7 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qgslogger.h>
|
||||
#include "qgsxyzconnection.h"
|
||||
|
||||
#include "qgsdatasourceuri.h"
|
||||
@ -41,8 +42,27 @@ QString QgsXyzConnection::encodedUri() const
|
||||
QStringList QgsXyzConnectionUtils::connectionList()
|
||||
{
|
||||
QgsSettings settings;
|
||||
QStringList connList;
|
||||
|
||||
settings.beginGroup( QStringLiteral( "qgis/connections-xyz" ) );
|
||||
return settings.childGroups();
|
||||
connList = settings.childGroups();
|
||||
|
||||
QStringList global = settings.globalChildGroups();
|
||||
settings.endGroup();
|
||||
|
||||
for ( auto &s : global )
|
||||
{
|
||||
settings.beginGroup( "qgis/connections-xyz/" + s );
|
||||
bool isHidden = settings.value( QStringLiteral( "hidden" ), false ).toBool();
|
||||
QString url = settings.value( QStringLiteral( "url" ), "" ).toString();
|
||||
settings.endGroup();
|
||||
if ( isHidden )
|
||||
{
|
||||
connList.removeOne( s );
|
||||
}
|
||||
}
|
||||
|
||||
return connList;
|
||||
}
|
||||
|
||||
QgsXyzConnection QgsXyzConnectionUtils::connection( const QString &name )
|
||||
@ -59,6 +79,7 @@ QgsXyzConnection QgsXyzConnectionUtils::connection( const QString &name )
|
||||
conn.username = settings.value( QStringLiteral( "username" ) ).toString();
|
||||
conn.password = settings.value( QStringLiteral( "password" ) ).toString();
|
||||
conn.referer = settings.value( QStringLiteral( "referer" ) ).toString();
|
||||
conn.hidden = settings.value( QStringLiteral( "hidden" ) ).toBool();
|
||||
return conn;
|
||||
}
|
||||
|
||||
@ -66,11 +87,32 @@ void QgsXyzConnectionUtils::deleteConnection( const QString &name )
|
||||
{
|
||||
QgsSettings settings;
|
||||
settings.remove( "qgis/connections-xyz/" + name );
|
||||
|
||||
settings.beginGroup( QStringLiteral( "qgis/connections-xyz" ) );
|
||||
QStringList global = settings.globalChildGroups();
|
||||
|
||||
if ( global.contains( name ) )
|
||||
{
|
||||
QgsSettings settings;
|
||||
settings.beginGroup( "qgis/connections-xyz/" + name );
|
||||
settings.setValue( QStringLiteral( "hidden" ), true );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void QgsXyzConnectionUtils::addConnection( const QgsXyzConnection &conn )
|
||||
{
|
||||
QgsSettings settings;
|
||||
bool addHiddenProperty = false;
|
||||
|
||||
settings.beginGroup( QStringLiteral( "qgis/connections-xyz" ) );
|
||||
QStringList global = settings.globalChildGroups();
|
||||
if ( global.contains( conn.name ) )
|
||||
{
|
||||
addHiddenProperty = true;
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup( "qgis/connections-xyz/" + conn.name );
|
||||
settings.setValue( QStringLiteral( "url" ), conn.url );
|
||||
settings.setValue( QStringLiteral( "zmin" ), conn.zMin );
|
||||
@ -79,4 +121,9 @@ void QgsXyzConnectionUtils::addConnection( const QgsXyzConnection &conn )
|
||||
settings.setValue( QStringLiteral( "username" ), conn.username );
|
||||
settings.setValue( QStringLiteral( "password" ), conn.password );
|
||||
settings.setValue( QStringLiteral( "referer" ), conn.referer );
|
||||
if ( addHiddenProperty )
|
||||
{
|
||||
settings.setValue( QStringLiteral( "hidden" ), false );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ struct QgsXyzConnection
|
||||
QString password;
|
||||
// Referer
|
||||
QString referer;
|
||||
bool hidden;
|
||||
|
||||
QString encodedUri() const;
|
||||
};
|
||||
@ -40,7 +41,7 @@ struct QgsXyzConnection
|
||||
class QgsXyzConnectionUtils
|
||||
{
|
||||
public:
|
||||
//! Returns list of existing connections
|
||||
//! Returns list of existing connections, unless the hidden ones
|
||||
static QStringList connectionList();
|
||||
|
||||
//! Returns connection details
|
||||
@ -54,4 +55,4 @@ class QgsXyzConnectionUtils
|
||||
};
|
||||
|
||||
|
||||
#endif // QGSXYZCONNECTION_H
|
||||
#endif // QGSXYZCONNECTION_H
|
@ -28,23 +28,15 @@ from qgis.core import QgsApplication, QgsRasterLayer, QgsSettings
|
||||
|
||||
start_app()
|
||||
|
||||
|
||||
def createXYZLayerFromURL(url):
|
||||
typeandurl = "type=xyz&url=" + url
|
||||
osm = QgsRasterLayer(typeandurl, "OpenStreetMap", "wms")
|
||||
return osm
|
||||
|
||||
|
||||
class TestQgsGlobalSettings(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""Run before each test."""
|
||||
qDebug('setUp')
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
"""Run after each test."""
|
||||
qDebug('tearDown')
|
||||
pass
|
||||
|
||||
def test_global_settings_exist(self):
|
||||
qDebug('QgsApplication.pkgDataPath(): {0}'.format(QgsApplication.pkgDataPath()))
|
||||
# Path after deployment: QgsApplication.pkgDataPath() + '/qgis_global_settings.ini'
|
||||
@ -52,18 +44,12 @@ class TestQgsGlobalSettings(unittest.TestCase):
|
||||
QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/qgis_global_settings.ini')
|
||||
self.settings = QgsSettings('testqgissettings', 'testqgissettings')
|
||||
settings = QgsSettings()
|
||||
qDebug('settings.allKeys(): {0}'.format(settings.allKeys()))
|
||||
# qDebug('settings.allKeys(): {0}'.format(settings.allKeys()))
|
||||
defaulturl = settings.value('qgis/connections-xyz/OpenStreetMap/url')
|
||||
self.assertEqual(defaulturl, 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png')
|
||||
layer = createXYZLayerFromURL(defaulturl)
|
||||
self.assertEqual(layer.name(), 'OpenStreetMap')
|
||||
|
||||
def testKey():
|
||||
self.assertEqual(defaulturl, 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png')
|
||||
|
||||
def testLayer():
|
||||
layer = createXYZLayerFromURL(defaulturl)
|
||||
self.assertEqual(layer.name(), 'OpenStreetMap')
|
||||
|
||||
testKey()
|
||||
testLayer()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user