Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this file here intentionally?

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python-envs.defaultEnvManager": "ms-python.python:system"
}
Comment thread
merydian marked this conversation as resolved.
32 changes: 31 additions & 1 deletion ORStools/ORStoolsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
"""

from qgis.gui import QgisInterface
from qgis.utils import iface
from qgis.core import QgsApplication, QgsSettings
from qgis.PyQt.QtCore import QTranslator, qVersion, QCoreApplication, QLocale
import os.path

from .gui import ORStoolsDialog
from .proc import provider, ENDPOINTS, DEFAULT_SETTINGS
from .utils import configmanager


class ORStools:
Expand All @@ -49,6 +51,7 @@ def __init__(self, iface: QgisInterface) -> None:
application at run time.
:type iface: QgsInterface
"""
self.iface = iface
self.dialog = ORStoolsDialog.ORStoolsDialogMain(iface)
self.provider = provider.ORStoolsProvider()

Expand Down Expand Up @@ -80,6 +83,8 @@ def initGui(self) -> None:

QgsApplication.processingRegistry().addProvider(self.provider)
self.dialog.initGui()
# starts deprecated url dialog after QGIS Main-Window opened
iface.initializationCompleted.connect(self.check_provider_url)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doesn't trigger somehow, what about just calling the function here?


def unload(self) -> None:
"""remove menu entry and toolbar icons"""
Expand All @@ -88,7 +93,7 @@ def unload(self) -> None:

def add_default_provider_to_settings(self):
s = QgsSettings()
settings = s.value("ORStools/config")
settings = configmanager.read_config()

settings_keys = ["ENV_VARS", "base_url", "key", "name", "endpoints"]

Expand All @@ -105,3 +110,28 @@ def add_default_provider_to_settings(self):
s.setValue("ORStools/config", settings)
else:
s.setValue("ORStools/config", DEFAULT_SETTINGS)

def url_is_deprecated(self) -> bool:
settings = configmanager.read_config()

if not settings:
return False

return settings["providers"][0]["base_url"] != DEFAULT_SETTINGS["providers"][0]["base_url"]

def reset_provider_url(self):
"""Reset the first provider URL to the default."""

settings = configmanager.read_config()

if not settings:
return

settings["providers"][0]["base_url"] = DEFAULT_SETTINGS["providers"][0]["base_url"]

configmanager.write_config(settings)

def check_provider_url(self):
if self.url_is_deprecated():
if ORStoolsDialog.url_dialog_reset_button(self.iface.mainWindow()):
self.reset_provider_url()
31 changes: 30 additions & 1 deletion ORStools/gui/ORStoolsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,35 @@ def on_about_click(parent: QWidget) -> None:
)


class DeprecatedUrlDialog(QMessageBox):
"""Dialog informing the user that the configured URL is deprecated."""

def __init__(self, parent=None):
super().__init__(parent)

self.setIcon(QMessageBox.Warning)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This isn't compatible with Qt6, try to use QGIS4 for development to check for these errors.

self.setWindowTitle(self.tr("Deprecated URL"))

self.setText(
self.tr(
"The configured ORS provider URL is deprecated.\n"
"Would you like to reset it to the new default URL?"
)
)

self.reset_button = self.addButton(self.tr("Reset URL"), QMessageBox.AcceptRole)

self.addButton(self.tr("Close"), QMessageBox.RejectRole)


def url_dialog_reset_button(parent=None) -> bool:
"""Shows the deprecated URL dialog and returns bool."""

url_dlg = DeprecatedUrlDialog(parent)
url_dlg.exec()
return url_dlg.clickedButton() == url_dlg.reset_button


class ORStoolsDialogMain:
"""Defines all mandatory QGIS things about dialog."""

Expand Down Expand Up @@ -535,7 +564,7 @@ def reload_geocode_completer_ors(self, request, lineEdit, text):

encoded = quote(lineEdit.text())

url = f"https://api.openrouteservice.org/geocode/search?api_key={api_key}&text={encoded}&focus.point.lat={middle.y()}&focus.point.lon={middle.x()}"
url = f"https://api.heigit.org/geocode/search?api_key={api_key}&text={encoded}&focus.point.lat={middle.y()}&focus.point.lon={middle.x()}"
error_code = request.get(QNetworkRequest(QUrl(url)))
if error_code == QgsBlockingNetworkRequest.ErrorCode.NoError:
reply = request.reply()
Expand Down
2 changes: 1 addition & 1 deletion ORStools/proc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"ORS_QUOTA": "X-Ratelimit-Limit",
"ORS_REMAINING": "X-Ratelimit-Remaining",
},
"base_url": "https://api.openrouteservice.org",
"base_url": "https://api.heigit.org",
"key": "",
"name": "openrouteservice",
"timeout": 60,
Expand Down
2 changes: 1 addition & 1 deletion ORStools/utils/configmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

def read_config() -> dict:
"""
Reads config.yml from file and returns the parsed dict.
Reads config and returns the parsed dict.

:returns: Parsed settings dictionary.
:rtype: dict
Expand Down
5 changes: 4 additions & 1 deletion ORStools/utils/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def route_as_layer(task, provider, profile, optimize, directions):
layer_out.updateFields()

# if no API key is present, when ORS is selected, throw an error message
if not provider["key"] and provider["base_url"].startswith("https://api.openrouteservice.org"):
if not provider["key"] and (
provider["base_url"].startswith("https://api.openrouteservice.org")
or provider["base_url"].startswith("https://api.heigit.org")
):
raise exceptions.InvalidKey()

agent = "QGIS_ORStoolsDialog"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_client_retry_on_over_query_limit(self):
"""Test that client retries on OverQueryLimit and eventually succeeds"""
provider = {
"ENV_VARS": None,
"base_url": "https://api.openrouteservice.org",
"base_url": "https://api.heigit.org",
"key": self.api_key,
"name": "openrouteservice",
"timeout": 60,
Expand Down
Loading