Skip to content

Commit 273243b

Browse files
committed
Add XYZ connection to provide default OpenStreetMap tiles
1 parent 518ffe3 commit 273243b

File tree

5 files changed

+108
-29
lines changed

5 files changed

+108
-29
lines changed

resources/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
INSTALL(FILES srs.db qgis.db symbology-style.xml spatialite.db customization.xml
22
DESTINATION ${QGIS_DATA_DIR}/resources)
3+
INSTALL(FILES qgis_global_settings.ini
4+
DESTINATION ${QGIS_DATA_DIR})
35
INSTALL(DIRECTORY cpt-city-qgis-min DESTINATION ${QGIS_DATA_DIR}/resources)
46
INSTALL(DIRECTORY themes DESTINATION ${QGIS_DATA_DIR}/resources)

resources/qgis_global_settings.ini

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[qgis]
2+
connections-xyz\OpenStreetMap\authcfg=
3+
connections-xyz\OpenStreetMap\password=
4+
connections-xyz\OpenStreetMap\referer=
5+
connections-xyz\OpenStreetMap\url=http://a.tile.openstreetmap.org/{z}/{x}/{y}.png
6+
connections-xyz\OpenStreetMap\username=
7+
connections-xyz\OpenStreetMap\zmax=19
8+
connections-xyz\OpenStreetMap\zmin=0

src/app/main.cpp

+28-29
Original file line numberDiff line numberDiff line change
@@ -785,35 +785,6 @@ int main( int argc, char *argv[] )
785785
QCoreApplication::setApplicationName( QgsApplication::QGIS_APPLICATION_NAME );
786786
QCoreApplication::setAttribute( Qt::AA_DontShowIconsInMenus, false );
787787

788-
789-
// SetUp the QgsSettings Global Settings:
790-
// - use the path specified with --globalsettingsfile path,
791-
// - use the environment if not found
792-
// - use a default location as a fallback
793-
if ( globalsettingsfile.isEmpty() )
794-
{
795-
globalsettingsfile = getenv( "QGIS_GLOBAL_SETTINGS_FILE" );
796-
}
797-
if ( globalsettingsfile.isEmpty() )
798-
{
799-
QString default_globalsettingsfile = QgsApplication::pkgDataPath() + "/qgis_global_settings.ini";
800-
if ( QFile::exists( default_globalsettingsfile ) )
801-
{
802-
globalsettingsfile = default_globalsettingsfile;
803-
}
804-
}
805-
if ( !globalsettingsfile.isEmpty() )
806-
{
807-
if ( ! QgsSettings::setGlobalSettingsPath( globalsettingsfile ) )
808-
{
809-
QgsMessageLog::logMessage( QString( "Invalid globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
810-
}
811-
else
812-
{
813-
QgsMessageLog::logMessage( QString( "Successfully loaded globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
814-
}
815-
}
816-
817788
QgsSettings settings;
818789
if ( configLocalStorageLocation.isEmpty() )
819790
{
@@ -848,6 +819,34 @@ int main( int argc, char *argv[] )
848819

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

822+
// SetUp the QgsSettings Global Settings:
823+
// - use the path specified with --globalsettingsfile path,
824+
// - use the environment if not found
825+
// - use a default location as a fallback
826+
if ( globalsettingsfile.isEmpty() )
827+
{
828+
globalsettingsfile = getenv( "QGIS_GLOBAL_SETTINGS_FILE" );
829+
}
830+
if ( globalsettingsfile.isEmpty() )
831+
{
832+
QString default_globalsettingsfile = QgsApplication::pkgDataPath() + "/qgis_global_settings.ini";
833+
if ( QFile::exists( default_globalsettingsfile ) )
834+
{
835+
globalsettingsfile = default_globalsettingsfile;
836+
}
837+
}
838+
if ( !globalsettingsfile.isEmpty() )
839+
{
840+
if ( ! QgsSettings::setGlobalSettingsPath( globalsettingsfile ) )
841+
{
842+
QgsMessageLog::logMessage( QString( "Invalid globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
843+
}
844+
else
845+
{
846+
QgsMessageLog::logMessage( QString( "Successfully loaded globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
847+
}
848+
}
849+
851850
#ifdef Q_OS_MAC
852851
// Set hidpi icons; use SVG icons, as PNGs will be relatively too small
853852
QCoreApplication::setAttribute( Qt::AA_UseHighDpiPixmaps );

tests/src/python/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ ADD_PYTHON_TEST(PyQgsVersionCompare test_versioncompare.py)
172172
ADD_PYTHON_TEST(PyQgsDBManagerGpkg test_db_manager_gpkg.py)
173173
ADD_PYTHON_TEST(PyQgsFileDownloader test_qgsfiledownloader.py)
174174
ADD_PYTHON_TEST(PyQgsSettings test_qgssettings.py)
175+
ADD_PYTHON_TEST(PyQgsGlobalSettings test_qgis_global_settings.py)
175176
ADD_PYTHON_TEST(PyQgsZipUtils test_qgsziputils.py)
176177

177178
IF (NOT WIN32)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
***************************************************************************
4+
test_qgis_global_settings.py
5+
---------------------
6+
Date : January 2017
7+
Copyright : (C) 2017, Jorge Gustavo Rocha
8+
Email : jgr at geomaster dot pt
9+
***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************
17+
"""
18+
19+
__author__ = 'Jorge Gustavo Rocha'
20+
__date__ = 'August 2017'
21+
__copyright__ = '(C) 2017, Jorge Gustavo Rocha'
22+
# This will get replaced with a git SHA1 when you do a git archive
23+
__revision__ = '$Format:%H$'
24+
25+
from qgis.testing import start_app, unittest
26+
from qgis.PyQt.QtCore import qDebug
27+
from qgis.core import QgsApplication, QgsRasterLayer, QgsSettings
28+
29+
start_app()
30+
31+
def createXYZLayerFromURL(url):
32+
typeandurl = "type=xyz&url=" + url
33+
osm = QgsRasterLayer(typeandurl, "OpenStreetMap", "wms")
34+
return osm
35+
36+
class TestQgsGlobalSettings(unittest.TestCase):
37+
38+
def setUp(self):
39+
"""Run before each test."""
40+
qDebug('setUp')
41+
pass
42+
43+
def tearDown(self):
44+
"""Run after each test."""
45+
qDebug('tearDown')
46+
pass
47+
48+
def test_global_settings_exist(self):
49+
qDebug('QgsApplication.pkgDataPath(): {0}'.format(QgsApplication.pkgDataPath()))
50+
# Path after deployment: QgsApplication.pkgDataPath() + '/qgis_global_settings.ini'
51+
# QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/resources/qgis_global_settings.ini')
52+
QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/qgis_global_settings.ini')
53+
self.settings = QgsSettings('testqgissettings', 'testqgissettings')
54+
settings = QgsSettings()
55+
qDebug('settings.allKeys(): {0}'.format(settings.allKeys()))
56+
defaulturl = settings.value('qgis/connections-xyz/OpenStreetMap/url')
57+
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()
67+
68+
if __name__ == '__main__':
69+
unittest.main()

0 commit comments

Comments
 (0)