Skip to content

Commit

Permalink
Merge branch 'main' into add-export-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
koebi authored Sep 13, 2024
2 parents a6dbf5d + 78064b1 commit 712fce9
Show file tree
Hide file tree
Showing 25 changed files with 1,365 additions and 75 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

name: Testing

on:
pull_request:

jobs:
test_3_16:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run test 3.16
run: |
docker run -v ${GITHUB_WORKSPACE}:/src -w /src qgis/qgis:release-3_16 sh -c 'apt-get -y update && apt-get -y install xvfb && export ORS_API_KEY=${{ secrets.ORS_API_KEY }} && export DISPLAY=:0.0 && pip install -U pytest && xvfb-run pytest'
env:
DOCKER_IMAGE: ${{ steps.docker-build.outputs.FULL_IMAGE_NAME }}
test_3_22:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run test 3.22
run: |
docker run -v ${GITHUB_WORKSPACE}:/src -w /src qgis/qgis:release-3_22 sh -c 'apt-get -y update && apt-get -y install xvfb && export DISPLAY=:0.0 && export ORS_API_KEY=${{ secrets.ORS_API_KEY }} && export DISPLAY=:0.0 && pip install -U pytest && xvfb-run pytest'
env:
DOCKER_IMAGE: ${{ steps.docker-build.outputs.FULL_IMAGE_NAME }}
test_latest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run test latest
run: |
docker run -v ${GITHUB_WORKSPACE}:/src -w /src qgis/qgis:latest sh -c 'apt-get -y update && apt-get -y install xvfb && export DISPLAY=:0.0 && export ORS_API_KEY=${{ secrets.ORS_API_KEY }} && apt install python3-pytest && xvfb-run pytest'
env:
DOCKER_IMAGE: ${{ steps.docker-build.outputs.FULL_IMAGE_NAME }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
tets/
docs/wiki/OSMtools.wiki/
.idea/
Expand Down
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ RELEASING:
### Added
- Processing algorithms for the Network Export endpoint ([#210](https://github.com/GIScience/orstools-qgis-plugin/issues/210))

### Changed
- Use QgsSettings instead of config.yml file to avoid deletion of providers on update ([#108](https://github.com/GIScience/orstools-qgis-plugin/issues/108))

## [1.8.4] - 2024-07-29

### Fixed
- issue with missing locale value for non-default user([#271](https://github.com/GIScience/orstools-qgis-plugin/issues/271))

## [1.8.3] - 2024-05-29

### Fixed
Expand Down Expand Up @@ -81,6 +89,10 @@ RELEASING:
- Improved type hints


# Unreleased
### Added
- Unit- and e2e-testing

## [1.7.1] - 2024-01-15

### Added
Expand Down Expand Up @@ -261,7 +273,8 @@ RELEASING:
- first working version of ORS Tools, after replacing OSM Tools plugin


[unreleased]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.3...HEAD
[unreleased]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.4...HEAD
[1.8.4]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.3...v1.8.4
[1.8.3]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.2...v1.8.3
[1.8.2]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.1...v1.8.2
[1.8.1]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.0...v1.8.1
Expand Down
3 changes: 2 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2021 HeiGIT gGmbH
Copyright (c) 2017 Nils Nolde
Copyright (c) 2019 HeiGIT gGmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 22 additions & 0 deletions ORStools/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2017 Nils Nolde
Copyright (c) 2019 HeiGIT gGmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
45 changes: 37 additions & 8 deletions ORStools/ORStoolsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

from .gui import ORStoolsDialog
Expand All @@ -56,15 +56,24 @@ def __init__(self, iface: QgisInterface) -> None:
self.plugin_dir = os.path.dirname(__file__)

# initialize locale
locale = QgsSettings().value("locale/userLocale")[0:2]
locale_path = os.path.join(self.plugin_dir, "i18n", "orstools_{}.qm".format(locale))
try:
locale = QgsSettings().value("locale/userLocale")
if not locale:
locale = QLocale().name()
locale = locale[0:2]

if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
locale_path = os.path.join(self.plugin_dir, "i18n", "orstools_{}.qm".format(locale))

if qVersion() > "4.3.3":
QCoreApplication.installTranslator(self.translator)
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)

if qVersion() > "4.3.3":
QCoreApplication.installTranslator(self.translator)
except TypeError:
pass

self.add_default_provider_to_settings()

def initGui(self) -> None:
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
Expand All @@ -76,3 +85,23 @@ def unload(self) -> None:
"""remove menu entry and toolbar icons"""
QgsApplication.processingRegistry().removeProvider(self.provider)
self.dialog.unload()

def add_default_provider_to_settings(self):
s = QgsSettings()
settings = s.value("ORStools/config")
if not settings:
def_settings = {
"providers": [
{
"ENV_VARS": {
"ORS_QUOTA": "X-Ratelimit-Limit",
"ORS_REMAINING": "X-Ratelimit-Remaining",
},
"base_url": "https://api.openrouteservice.org",
"key": "",
"name": "openrouteservice",
"timeout": 60,
}
]
}
s.setValue("ORStools/config", def_settings)
2 changes: 1 addition & 1 deletion ORStools/common/directions_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def build_default_parameters(


def get_extra_info_features_directions(
response: dict, extra_info_order: list[str], to_from_values: Optional[list] = None
response: dict, extra_info_order: List[str], to_from_values: Optional[list] = None
):
extra_info_order = [
key if key != "waytype" else "waytypes" for key in extra_info_order
Expand Down
8 changes: 0 additions & 8 deletions ORStools/config.yml

This file was deleted.

58 changes: 55 additions & 3 deletions ORStools/gui/ORStoolsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
import os
from typing import Optional

import processing
try:
import processing
except ModuleNotFoundError:
pass

import webbrowser

from qgis._core import Qgis, QgsAnnotation
Expand All @@ -50,7 +54,7 @@
from qgis.gui import QgsMapCanvasAnnotationItem

from qgis.PyQt.QtCore import QSizeF, QPointF, QCoreApplication
from qgis.PyQt.QtGui import QIcon, QTextDocument
from qgis.PyQt.QtGui import QIcon, QTextDocument, QColor
from qgis.PyQt.QtWidgets import (
QAction,
QDialog,
Expand Down Expand Up @@ -102,6 +106,8 @@ def on_help_click() -> None:
def on_about_click(parent: QWidget) -> None:
"""Slot for click event of About button/menu entry."""

# ruff will add trailing comma to last string line which breaks pylupdate5
# fmt: off
info = QCoreApplication.translate(
"@default",
'<b>ORS Tools</b> provides access to <a href="https://openrouteservice.org"'
Expand All @@ -116,8 +122,9 @@ def on_about_click(parent: QWidget) -> None:
'Web: <a href="{2}">{2}</a><br>'
'Repo: <a href="https://github.com/GIScience/orstools-qgis-plugin">'
"github.com/GIScience/orstools-qgis-plugin</a><br>"
"Version: {3}",
"Version: {3}"
).format(DEFAULT_COLOR, __email__, __web__, __version__)
# fmt: on

QMessageBox.information(
parent, QCoreApplication.translate("@default", "About {}").format(PLUGIN_NAME), info
Expand Down Expand Up @@ -320,6 +327,27 @@ def run_gui_control(self) -> None:
try:
params = directions.get_parameters()
if self.dlg.optimization_group.isChecked():
# check for duplicate points
points = [
self.dlg.routing_fromline_list.item(x).text()
for x in range(self.dlg.routing_fromline_list.count())
]
if len(points) != len(set(points)):
QMessageBox.warning(
self.dlg,
self.tr("Duplicates"),
self.tr(
"""
There are duplicate points in the input layer. Traveling Salesman Optimization does not allow this.
Either remove the duplicates or deselect Traveling Salesman.
"""
),
)
msg = self.tr("The request has been aborted!")
logger.log(msg, 0)
self.dlg.debug_text.setText(msg)
return

if len(params["jobs"]) <= 1: # Start/end locations don't count as job
QMessageBox.critical(
self.dlg,
Expand Down Expand Up @@ -490,6 +518,14 @@ def __init__(self, iface: QgisInterface, parent=None) -> None:
self.routing_fromline_list.model().rowsMoved.connect(self._reindex_list_items)
self.routing_fromline_list.model().rowsRemoved.connect(self._reindex_list_items)

# Connect signals to the color_duplicate_items function
self.routing_fromline_list.model().rowsRemoved.connect(
lambda: self.color_duplicate_items(self.routing_fromline_list)
)
self.routing_fromline_list.model().rowsInserted.connect(
lambda: self.color_duplicate_items(self.routing_fromline_list)
)

self.annotation_canvas = self._iface.mapCanvas()

def _save_vertices_to_layer(self) -> None:
Expand Down Expand Up @@ -633,3 +669,19 @@ def _on_linetool_map_doubleclick(self) -> None:
QApplication.restoreOverrideCursor()
self._iface.mapCanvas().setMapTool(self.last_maptool)
self.show()

def color_duplicate_items(self, list_widget):
item_dict = {}
for index in range(list_widget.count()):
item = list_widget.item(index)
text = item.text()
if text in item_dict:
item_dict[text].append(index)
else:
item_dict[text] = [index]

for indices in item_dict.values():
if len(indices) > 1:
for index in indices:
item = list_widget.item(index)
item.setBackground(QColor("lightsalmon"))
Loading

0 comments on commit 712fce9

Please sign in to comment.