Skip to content
Permalink
Browse files

Merge pull request #5000 from jgrocha/add-default-layers

[FEATURE][needs-docs] Add XYZ connection to provide default OpenStreetMap tiles
  • Loading branch information
elpaso committed Sep 8, 2017
2 parents 25c27b3 + 858413e commit f0e021c2fda13c56649698430645b15ef930e1a9
@@ -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
@@ -1,4 +1,6 @@
INSTALL(FILES srs.db qgis.db symbology-style.xml spatialite.db customization.xml
DESTINATION ${QGIS_DATA_DIR}/resources)
INSTALL(FILES qgis_global_settings.ini
DESTINATION ${QGIS_DATA_DIR})
INSTALL(DIRECTORY cpt-city-qgis-min DESTINATION ${QGIS_DATA_DIR}/resources)
INSTALL(DIRECTORY themes DESTINATION ${QGIS_DATA_DIR}/resources)
@@ -0,0 +1,8 @@
[qgis]
connections-xyz\OpenStreetMap\authcfg=
connections-xyz\OpenStreetMap\password=
connections-xyz\OpenStreetMap\referer=
connections-xyz\OpenStreetMap\url=http://a.tile.openstreetmap.org/{z}/{x}/{y}.png
connections-xyz\OpenStreetMap\username=
connections-xyz\OpenStreetMap\zmax=19
connections-xyz\OpenStreetMap\zmin=0
@@ -785,35 +785,6 @@ int main( int argc, char *argv[] )
QCoreApplication::setApplicationName( QgsApplication::QGIS_APPLICATION_NAME );
QCoreApplication::setAttribute( Qt::AA_DontShowIconsInMenus, false );


// SetUp the QgsSettings Global Settings:
// - use the path specified with --globalsettingsfile path,
// - use the environment if not found
// - use a default location as a fallback
if ( globalsettingsfile.isEmpty() )
{
globalsettingsfile = getenv( "QGIS_GLOBAL_SETTINGS_FILE" );
}
if ( globalsettingsfile.isEmpty() )
{
QString default_globalsettingsfile = QgsApplication::pkgDataPath() + "/qgis_global_settings.ini";
if ( QFile::exists( default_globalsettingsfile ) )
{
globalsettingsfile = default_globalsettingsfile;
}
}
if ( !globalsettingsfile.isEmpty() )
{
if ( ! QgsSettings::setGlobalSettingsPath( globalsettingsfile ) )
{
QgsMessageLog::logMessage( QString( "Invalid globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
}
else
{
QgsMessageLog::logMessage( QString( "Successfully loaded globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
}
}

QgsSettings settings;
if ( configLocalStorageLocation.isEmpty() )
{
@@ -848,6 +819,34 @@ int main( int argc, char *argv[] )

QgsApplication myApp( argc, argv, myUseGuiFlag, profileFolder );

// SetUp the QgsSettings Global Settings:
// - use the path specified with --globalsettingsfile path,
// - use the environment if not found
// - use a default location as a fallback
if ( globalsettingsfile.isEmpty() )
{
globalsettingsfile = getenv( "QGIS_GLOBAL_SETTINGS_FILE" );
}
if ( globalsettingsfile.isEmpty() )
{
QString default_globalsettingsfile = QgsApplication::pkgDataPath() + "/qgis_global_settings.ini";
if ( QFile::exists( default_globalsettingsfile ) )
{
globalsettingsfile = default_globalsettingsfile;
}
}
if ( !globalsettingsfile.isEmpty() )
{
if ( ! QgsSettings::setGlobalSettingsPath( globalsettingsfile ) )
{
QgsMessageLog::logMessage( QString( "Invalid globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
}
else
{
QgsMessageLog::logMessage( QString( "Successfully loaded globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
}
}

#ifdef Q_OS_MAC
// Set hidpi icons; use SVG icons, as PNGs will be relatively too small
QCoreApplication::setAttribute( Qt::AA_UseHighDpiPixmaps );
@@ -20,6 +20,7 @@
#include <QDir>

#include "qgssettings.h"
#include "qgslogger.h"

QString QgsSettings::sGlobalSettingsPath = QString();

@@ -149,6 +150,15 @@ QStringList QgsSettings::childGroups() const
}
return keys;
}
QStringList QgsSettings::globalChildGroups() const
{
QStringList keys;
if ( mGlobalSettings )
{
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
@@ -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();

const QStringList global = settings.globalChildGroups();
settings.endGroup();

for ( const 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,18 +79,40 @@ 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;
}

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
@@ -197,6 +197,33 @@ def test_groups(self):
self.assertEqual('qgisrocks-1', self.settings.value('testqgissettings/names/name1'))
self.assertEqual('qgisrocks-4', self.settings.value('testqgissettings/names/name4'))

def test_global_groups(self):
self.assertEqual(self.settings.allKeys(), [])
self.assertEqual(self.globalsettings.allKeys(), [])

self.addToDefaults('testqgissettings/foo/first', 'qgis')
self.addToDefaults('testqgissettings/foo/last', 'rocks')

self.settings.beginGroup('testqgissettings')
self.assertEqual(['foo'], self.settings.childGroups())
self.assertEqual(['foo'], self.settings.globalChildGroups())
self.settings.endGroup()

self.settings.setValue('testqgissettings/bar/first', 'qgis')
self.settings.setValue('testqgissettings/bar/last', 'rocks')

self.settings.beginGroup('testqgissettings')
self.assertEqual(sorted(['bar', 'foo']), sorted(self.settings.childGroups()))
self.assertEqual(['foo'], self.settings.globalChildGroups())
self.settings.endGroup()

self.globalsettings.remove('testqgissettings/foo')

self.settings.beginGroup('testqgissettings')
self.assertEqual(['bar'], self.settings.childGroups())
self.assertEqual([], self.settings.globalChildGroups())
self.settings.endGroup()

def test_array(self):
self.assertEqual(self.settings.allKeys(), [])
self.addArrayToDefaults('testqgissettings', 'key', ['qgisrocks1', 'qgisrocks2', 'qgisrocks3'])

0 comments on commit f0e021c

Please sign in to comment.
You can’t perform that action at this time.