Skip to content

Commit

Permalink
chore: update branch
Browse files Browse the repository at this point in the history
  • Loading branch information
merydian committed Dec 28, 2023
2 parents e303fbc + b68be1e commit 33390e5
Show file tree
Hide file tree
Showing 18 changed files with 11,818 additions and 5,540 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ RELEASING:
13. Create new release in GitHub with tag version and release title of `vX.X.X`
-->

## Unreleased
## [1.7.0] - 2023-12-22

### Added
- Add keyboard shortcut (Ctrl+R)
- Add keyboard shortcut (Ctrl+R)
- Additional parameter for the "smoothing factor" to isochrones processing algorithms ([#172](https://github.com/GIScience/orstools-qgis-plugin/issues/172))
- Mention omission of configuration options when using traveling salesman
- option to set location type for isochrones ([#191](https://github.com/GIScience/orstools-qgis-plugin/pull/191))
- Add styling of routing output in main plugin ([#149](https://github.com/GIScience/orstools-qgis-plugin/issues/149))
- make items in centroid list drag and droppable ([#144](https://github.com/GIScience/orstools-qgis-plugin/issues/144))
- Add save button for vertices ([#144](https://github.com/GIScience/orstools-qgis-plugin/issues/144))
- remove blue lines every time the red X button is clicked ([#120](https://github.com/GIScience/orstools-qgis-plugin/issues/120))

## [1.6.0] - 2023-07-25

Expand Down Expand Up @@ -206,7 +209,8 @@ RELEASING:
- first working version of ORS Tools, after replacing OSM Tools plugin


[unreleased]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.6.0...HEAD
[unreleased]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.7.0...HEAD
[1.7.0]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.6.0...v1.7.0
[1.6.0]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.5.3...v1.6.0
[1.5.3]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.5.2...v1.5.3
[1.5.2]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.5.1...v1.5.2
Expand Down
13 changes: 12 additions & 1 deletion ORStools/common/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@
from ORStools.common import networkaccessmanager
from ORStools.utils import exceptions, configmanager, logger

from qgis.core import QgsSettings

_USER_AGENT = f"ORSQGISClient@v{__version__}"


class Client(QObject):
"""Performs requests to the ORS API services."""

def __init__(self, provider=None):
def __init__(self, provider=None, agent=None):
"""
:param provider: A openrouteservice provider from config.yml
:type provider: dict
Expand All @@ -73,6 +75,12 @@ def __init__(self, provider=None):
"Authorization": provider["key"],
}

self.settings = QgsSettings()
# Read the current value
self.user_agent = self.settings.value("qgis/networkAndProxy/userAgent")
# Set a new value
self.settings.setValue("qgis/networkAndProxy/userAgent", agent)

# Save some references to retrieve in client instances
self.url = None
self.warnings = None
Expand Down Expand Up @@ -181,6 +189,9 @@ def request(self, url, params, first_request_time=None, retry_counter=0, post_js
env_var, response.headers.get(self.ENV_VARS[env_var], "None")
)

# Reset to old value
self.settings.setValue("qgis/networkAndProxy/userAgent", self.user_agent)

return json.loads(content.decode("utf-8"))

def _check_status(self):
Expand Down
63 changes: 59 additions & 4 deletions ORStools/gui/ORStoolsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,22 @@
import webbrowser

from PyQt5.QtNetwork import QNetworkRequest
from qgis._core import QgsBlockingNetworkRequest
from qgis._core import Qgis
from qgis.core import (
QgsProject,
QgsVectorLayer,
QgsTextAnnotation,
QgsMapLayerProxyModel,
QgsCoordinateReferenceSystem,
QgsFeature,
QgsPointXY,
QgsGeometry,
QgsCoordinateReferenceSystem,
QgsBlockingNetworkRequest,
)
from qgis.gui import QgsMapCanvasAnnotationItem

from PyQt5.QtCore import QSizeF, QPointF, QCoreApplication, Qt, QUrl
from PyQt5.QtCore import QSizeF, QPointF, QCoreApplication, QSettings, Qt, QUrl

from PyQt5.QtGui import QIcon, QTextDocument
from PyQt5.QtWidgets import (
QAction,
Expand Down Expand Up @@ -251,6 +255,20 @@ def run_gui_control(self):
layer_out.dataProvider().addAttributes(directions_core.get_fields())
layer_out.updateFields()

basepath = os.path.dirname(__file__)

# add ors svg path
my_new_path = os.path.join(basepath, "img/svg")
svg_paths = QSettings().value("svg/searchPathsForSVG")
if my_new_path not in svg_paths:
svg_paths.append(my_new_path)
QSettings().setValue("svg/searchPathsForSVG", svg_paths)

# style output layer
qml_path = os.path.join(basepath, "linestyle.qml")
layer_out.loadNamedStyle(qml_path, True)
layer_out.triggerRepaint()

# Associate annotations with map layer, so they get deleted when layer is deleted
for annotation in self.dlg.annotations:
# Has the potential to be pretty cool: instead of deleting, associate with mapLayer
Expand Down Expand Up @@ -293,7 +311,8 @@ def run_gui_control(self):
)
return

clnt = client.Client(provider)
agent = "QGIS_ORStoolsDialog"
clnt = client.Client(provider, agent)
clnt_msg = ""

directions = directions_gui.Directions(self.dlg)
Expand Down Expand Up @@ -423,6 +442,7 @@ def __init__(self, iface, parent=None):
# Routing tab
self.routing_fromline_map.clicked.connect(self._on_linetool_init)
self.routing_fromline_clear.clicked.connect(self._on_clear_listwidget_click)
self.save_vertices.clicked.connect(self._save_vertices_to_layer)

# Batch
self.batch_routing_points.clicked.connect(
Expand Down Expand Up @@ -557,6 +577,33 @@ def add_geocoded_items(self):
settings symbol in the main ORS Tools GUI, next to the provider dropdown.""",
)

def _save_vertices_to_layer(self):
"""Saves the vertices list to a temp layer"""
items = [
self.routing_fromline_list.item(x).text()
for x in range(self.routing_fromline_list.count())
]

if len(items) > 0:
point_layer = QgsVectorLayer(
"point?crs=epsg:4326&field=ID:integer", "Vertices", "memory"
)
point_layer.updateFields()
for idx, x in enumerate(items):
coords = x.split(":")[1]
x, y = (float(i) for i in coords.split(", "))
feature = QgsFeature()
feature.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(x, y)))
feature.setAttributes([idx])

point_layer.dataProvider().addFeature(feature)
QgsProject.instance().addMapLayer(point_layer)
self._iface.mapCanvas().refresh()

self._iface.messageBar().pushMessage(
"Success", "Vertices saved to layer.", level=Qgis.Success
)

def _on_prov_refresh_click(self):
"""Populates provider dropdown with fresh list from config.yml"""

Expand All @@ -581,6 +628,10 @@ def _on_clear_listwidget_click(self):
self._clear_annotations()
self.geocoded = False

# Remove blue lines (rubber band)
if self.line_tool:
self.line_tool.canvas.scene().removeItem(self.line_tool.rubberBand)

def _linetool_annotate_point(self, point, idx, crs=None):
if not crs:
crs = self._iface.mapCanvas().mapSettings().destinationCrs()
Expand Down Expand Up @@ -609,6 +660,10 @@ def _clear_annotations(self):

def _on_linetool_init(self):
"""Hides GUI dialog, inits line maptool and add items to line list box."""
# Remove blue lines (rubber band)
if self.line_tool:
self.line_tool.canvas.scene().removeItem(self.line_tool.rubberBand)

self.hide()
if not self.geocoded:
self.routing_fromline_list.clear()
Expand Down
29 changes: 21 additions & 8 deletions ORStools/gui/ORStoolsDialogUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class Ui_ORStoolsDialogBase(object):
def setupUi(self, ORStoolsDialogBase):
ORStoolsDialogBase.setObjectName("ORStoolsDialogBase")
ORStoolsDialogBase.resize(412, 868)
ORStoolsDialogBase.resize(412, 686)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
Expand Down Expand Up @@ -216,7 +216,19 @@ def setupUi(self, ORStoolsDialogBase):
self.routing_fromline_list.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
self.routing_fromline_list.setResizeMode(QtWidgets.QListView.Fixed)
self.routing_fromline_list.setObjectName("routing_fromline_list")
self.gridLayout.addWidget(self.routing_fromline_list, 0, 2, 3, 1)
self.gridLayout.addWidget(self.routing_fromline_list, 0, 1, 4, 1)
self.save_vertices = QtWidgets.QPushButton(self.widget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.save_vertices.sizePolicy().hasHeightForWidth())
self.save_vertices.setSizePolicy(sizePolicy)
self.save_vertices.setText("")
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap(":/plugins/ORStools/img/save_vertices.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.save_vertices.setIcon(icon4)
self.save_vertices.setObjectName("save_vertices")
self.gridLayout.addWidget(self.save_vertices, 2, 0, 1, 1)
self.verticalLayout_7.addWidget(self.widget)
self.advances_group = QgsCollapsibleGroupBox(self.qwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
Expand Down Expand Up @@ -447,15 +459,15 @@ def setupUi(self, ORStoolsDialogBase):
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.help_button.sizePolicy().hasHeightForWidth())
self.help_button.setSizePolicy(sizePolicy)
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap(":/plugins/ORStools/img/icon_help.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.help_button.setIcon(icon4)
icon5 = QtGui.QIcon()
icon5.addPixmap(QtGui.QPixmap(":/plugins/ORStools/img/icon_help.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.help_button.setIcon(icon5)
self.help_button.setObjectName("help_button")
self.horizontalLayout_8.addWidget(self.help_button)
self.about_button = QtWidgets.QPushButton(self.widget_2)
icon5 = QtGui.QIcon()
icon5.addPixmap(QtGui.QPixmap(":/plugins/ORStools/img/icon_about.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.about_button.setIcon(icon5)
icon6 = QtGui.QIcon()
icon6.addPixmap(QtGui.QPixmap(":/plugins/ORStools/img/icon_about.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.about_button.setIcon(icon6)
self.about_button.setObjectName("about_button")
self.horizontalLayout_8.addWidget(self.about_button)
self.global_buttons = QtWidgets.QDialogButtonBox(self.widget_2)
Expand Down Expand Up @@ -495,6 +507,7 @@ def retranslateUi(self, ORStoolsDialogBase):
self.routing_fromline_map.setToolTip(_translate("ORStoolsDialogBase", "<html><head/><body><p>Add wayoints interactively from the map canvas.</p><p>Double-click will terminate waypoint selection.</p></body></html>"))
self.routing_fromline_clear.setToolTip(_translate("ORStoolsDialogBase", "<html><head/><body><p>If waypoints are selected in the list, only these will be deleted. Else all waypoints will be deleted.</p></body></html>"))
self.routing_fromline_list.setToolTip(_translate("ORStoolsDialogBase", "Select waypoints from the map!"))
self.save_vertices.setToolTip(_translate("ORStoolsDialogBase", "<html><head/><body><p>Save points in list to layer.</p></body></html>"))
self.advances_group.setTitle(_translate("ORStoolsDialogBase", "Advanced Configuration"))
self.optimization_group.setToolTip(_translate("ORStoolsDialogBase", "<html><head/><body><p>Enabling Traveling Salesman will omit all other advanced configuration and assume the preference to be <span style=\" font-weight:600;\">fastest</span>.</p></body></html>"))
self.optimization_group.setTitle(_translate("ORStoolsDialogBase", "Traveling Salesman"))
Expand Down
22 changes: 21 additions & 1 deletion ORStools/gui/ORStoolsDialogUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
</property>
</widget>
</item>
<item row="0" column="2" rowspan="3">
<item row="0" column="1" rowspan="4">
<widget class="QListWidget" name="routing_fromline_list">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
Expand Down Expand Up @@ -390,6 +390,26 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="save_vertices">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save points in list to layer.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/plugins/ORStools/img/save_vertices.png</normaloff>:/plugins/ORStools/img/save_vertices.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
Binary file added ORStools/gui/img/save_vertices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions ORStools/gui/img/svg/endpoint_marker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions ORStools/gui/img/svg/startpoint_marker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 33390e5

Please sign in to comment.