Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE][needs-docs] Add XYZ connection to provide default OpenStreetMap tiles #5000

Merged
merged 11 commits into from Sep 8, 2017
Merged

[FEATURE][needs-docs] Add XYZ connection to provide default OpenStreetMap tiles #5000

merged 11 commits into from Sep 8, 2017

Conversation

jgrocha
Copy link
Member

@jgrocha jgrocha commented Aug 7, 2017

Description

This PR adds a default XYZ connection, so users can add easily OpenStreetMap tiles.
Currently, no layer is added to the map. Later we can add an option to add it by default when starting a new project, but only if the user enables it.

With this connection available, users can add the OpenStreetMap as a new layer with just one double click on it, using the old brower panel or the new brower.

adding default openstreetmap tiles

This feature was discusssed on the mailing list. The thread was started by @pcav.

There is a previous PR #4352 that can be closed if this one is merged. The previous PR contains the discussion that supports the approach taken. The approach used is based on the new qgis_global_settings.ini. This file is read only and support initial settings. The contents write now are:

[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

Removal of global settings

To delete a global settings connection, it is necessary to write something on the local settings.
So, if the user decide to remove the OpenStreetMap default connection, a new entry will be added to the local settings:

connections-xyz\OpenStreetMap\hidden=true

This way, the connection will not be visible. If the user resets his local settings, the global one will be visible again.

Test

To test this PR on a developing environment (QGIS not installed) it is necessary to manually copy or link qgis_global_settings.ini to the current development QgsApplication::pkgDataPath() folder, is is problably the root of the repository. Just in case, it can be checked on the Python console with: QgsApplication.pkgDataPath(). In my case, I just need to;

git fetch upstream
git checkout pr/5000
ln -s resources/qgis_global_settings.ini .

Checklist

Reviewing is a process done by project maintainers, mostly on a volunteer basis. We try to keep the overhead as small as possible and appreciate if you help us to do so by completing the following items. Feel free to ask in a comment if you have troubles with any of them.

  • Commit messages are descriptive and explain the rationale for changes
  • Commits which fix bugs include fixes #11111 in the commit message next to the description
  • Commits which add new features are tagged with [FEATURE] in the commit message
  • Commits which change the UI or existing user workflows are tagged with [needs-docs] in the commit message and containt sufficient information in the commit message to be documented
  • I have read the QGIS Coding Standards and this PR complies with them
  • This PR passes all existing unit tests (test results will be reported by travis-ci after opening this PR)
  • New unit tests have been added for core changes
  • I have run the scripts/prepare-commit.sh script before each commit

def tearDown(self):
"""Run after each test."""
qDebug('tearDown')
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch out for the indentation here

@jgrocha jgrocha changed the title WIP: [FEATURE][needs-docs] Add XYZ connection to provide default OpenStreetMap tiles [WIP][FEATURE][needs-docs] Add XYZ connection to provide default OpenStreetMap tiles Aug 9, 2017
qDebug('settings.allKeys(): {0}'.format(settings.allKeys()))
defaulturl = settings.value('qgis/connections-xyz/OpenStreetMap/url')

def testKey():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this function necessary?
I think you should just assert in the main body, same for testLayer

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @elpaso
Done!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a WIP. Now I think it is fully implemented.
Now we support the removal of default connections by users.

@jgrocha jgrocha changed the title [WIP][FEATURE][needs-docs] Add XYZ connection to provide default OpenStreetMap tiles [FEATURE][needs-docs] Add XYZ connection to provide default OpenStreetMap tiles Aug 23, 2017
Copy link
Contributor

@elpaso elpaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!
Can you please address the two minor issues that I've commented in the review?

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

for ( auto &s : global )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid a detach you might want to try the new qgsAsConst 029f741 recently added by @nyalldawson or use Q_FOREACH

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also should be const auto &

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid a detach you might want to try the new qgsAsConst 029f741 recently added by @nyalldawson or use Q_FOREACH

... or simply use const QStringList global

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to avoid the Q_FOREACH.

I've used the suggested pattern:

  const QStringList global = settings.globalChildGroups();
  for ( const auto &s : global )

@@ -156,6 +156,11 @@ Returns a list of all top-level keys that can be read using the QSettings object
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a test case for globalChildGroups() to https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgssettings.py ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @elpaso. I discovered another minor issue writing the test. The test now covers the settings.globalChildGroups().

qDebug('QgsApplication.pkgDataPath(): {0}'.format(QgsApplication.pkgDataPath()))
# Path after deployment
# QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/qgis_global_settings.ini')
# Path before deployment
QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/resources/qgis_global_settings.ini')
assert QgsSettings.setGlobalSettingsPath(QgsApplication.pkgDataPath() + '/resources/qgis_global_settings.ini')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use self.assertTrue

Copy link
Member Author

@jgrocha jgrocha Sep 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn thanks! Fixed!

@elpaso
Copy link
Contributor

elpaso commented Sep 1, 2017

@jgrocha sorry if I didn't mentioned it before, but maybe would be better if you move the tests from globaltest_qgis_global_settings.py into test_qgssettings.py.
I don't see a good reason for adding a new test file for a single test case on a method that it's part of the main QgsSettings class.

@jgrocha
Copy link
Member Author

jgrocha commented Sep 1, 2017

@elpaso I was separating all logic regarding to the presence/absence of the new qgis_global_settings.ini in this new test_qgis_global_settings.py. But your suggestion is equally good and I'll move all tests t the same file.

@jgrocha
Copy link
Member Author

jgrocha commented Sep 5, 2017

@elpaso The new method settings.globalChildGroups() was included in test_qgssettings.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants