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

Prepare icon and UI imports for qt6 QGis builds #250

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ RELEASING:
-->

## Unreleased
- Replace PyQt5 imports with qgis.PyQt imports to prepare for Qt6-QGis builds

### Fixed
- QGis crashes when selecting more than two vertices for deletion ([#230](https://github.com/GIScience/orstools-qgis-plugin/issues/230))
Expand Down
2 changes: 1 addition & 1 deletion ORStools/ORStoolsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"""

from qgis.core import QgsApplication, QgsSettings
from PyQt5.QtCore import QTranslator, qVersion, QCoreApplication
from qgis.PyQt.QtCore import QTranslator, qVersion, QCoreApplication
import os.path

from .gui import ORStoolsDialog
Expand Down
2 changes: 1 addition & 1 deletion ORStools/common/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from datetime import datetime, timedelta
from urllib.parse import urlencode

from PyQt5.QtCore import QObject, pyqtSignal
from qgis.PyQt.QtCore import QObject, pyqtSignal
from requests.utils import unquote_unreserved

from ORStools import __version__
Expand Down
2 changes: 1 addition & 1 deletion ORStools/common/directions_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from qgis.core import QgsPoint, QgsPointXY, QgsGeometry, QgsFeature, QgsFields, QgsField
from typing import List

from PyQt5.QtCore import QVariant
from qgis.PyQt.QtCore import QVariant

from ORStools.utils import convert

Expand Down
4 changes: 2 additions & 2 deletions ORStools/common/isochrones_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
QgsCategorizedSymbolRenderer,
)

from PyQt5.QtCore import QVariant
from PyQt5.QtGui import QColor
from qgis.PyQt.QtCore import QVariant
from qgis.PyQt.QtGui import QColor


# import processing
Expand Down
20 changes: 12 additions & 8 deletions ORStools/common/networkaccessmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def request(self, url, method="GET", body=None, headers=None, blocking=True):

# Catch all exceptions (and clean up requests)
try:
self.el.exec_(QEventLoop.ExcludeUserInputEvents)
self.el.exec(QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents)
except Exception as e:
raise e

Expand Down Expand Up @@ -293,8 +293,10 @@ def requestTimedOut(self, reply):

def replyFinished(self):
err = self.reply.error()
httpStatus = self.reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
httpStatusMessage = self.reply.attribute(QNetworkRequest.HttpReasonPhraseAttribute)
httpStatus = self.reply.attribute(QNetworkRequest.Attribute.HttpStatusCodeAttribute)
httpStatusMessage = self.reply.attribute(
QNetworkRequest.Attribute.HttpReasonPhraseAttribute
)
self.http_call_result.status_code = httpStatus
self.http_call_result.status = httpStatus
self.http_call_result.status_message = httpStatusMessage
Expand All @@ -306,7 +308,7 @@ def replyFinished(self):
v.data(), encoding="utf-8"
)

if err != QNetworkReply.NoError:
if err != QNetworkReply.NetworkError.NoError:
# handle error
# check if errorString is empty, if so, then set err string as
# reply dump
Expand All @@ -326,13 +328,13 @@ def replyFinished(self):
self.http_call_result.ok = False
self.msg_log(msg)
# set return exception
if err == QNetworkReply.TimeoutError:
if err == QNetworkReply.NetworkError.TimeoutError:
self.http_call_result.exception = RequestsExceptionTimeout(msg)

elif err == QNetworkReply.ConnectionRefusedError:
elif err == QNetworkReply.NetworkError.ConnectionRefusedError:
self.http_call_result.exception = RequestsExceptionConnectionError(msg)

elif err == QNetworkReply.OperationCanceledError:
elif err == QNetworkReply.NetworkError.OperationCanceledError:
# request abort by calling NAM.abort() => cancelled by the user
if self.on_abort:
self.http_call_result.exception = RequestsExceptionUserAbort(msg)
Expand All @@ -348,7 +350,9 @@ def replyFinished(self):

else:
# Handle redirections
redirectionUrl = self.reply.attribute(QNetworkRequest.RedirectionTargetAttribute)
redirectionUrl = self.reply.attribute(
QNetworkRequest.Attribute.RedirectionTargetAttribute
)
if redirectionUrl is not None and redirectionUrl != self.reply.url():
if redirectionUrl.isRelative():
redirectionUrl = self.reply.url().resolved(redirectionUrl)
Expand Down
61 changes: 31 additions & 30 deletions ORStools/gui/ORStoolsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import processing
import webbrowser

from qgis.PyQt import uic
from qgis._core import Qgis
from qgis.core import (
QgsProject,
Expand All @@ -46,12 +47,11 @@
)
from qgis.gui import QgsMapCanvasAnnotationItem

from PyQt5.QtCore import QSizeF, QPointF, QCoreApplication
from PyQt5.QtGui import QIcon, QTextDocument
from PyQt5.QtWidgets import QAction, QDialog, QApplication, QMenu, QMessageBox, QDialogButtonBox
from qgis.PyQt.QtCore import QSizeF, QPointF, QCoreApplication
from qgis.PyQt.QtGui import QTextDocument
from qgis.PyQt.QtWidgets import QAction, QDialog, QApplication, QMenu, QMessageBox, QDialogButtonBox

from ORStools import (
RESOURCE_PREFIX,
PLUGIN_NAME,
DEFAULT_COLOR,
__version__,
Expand All @@ -66,11 +66,8 @@
PREFERENCES,
)
from ORStools.gui import directions_gui
from ORStools.utils import exceptions, maptools, logger, configmanager, transform
from .ORStoolsDialogConfig import ORStoolsDialogConfigMain
from .ORStoolsDialogUI import Ui_ORStoolsDialogBase

from . import resources_rc # noqa: F401
from ORStools.utils import exceptions, maptools, logger, configmanager, transform, gui


def on_config_click(parent):
Expand All @@ -80,7 +77,7 @@ def on_config_click(parent):
:type parent: QDialog
"""
config_dlg = ORStoolsDialogConfigMain(parent=parent)
config_dlg.exec_()
config_dlg.exec()


def on_help_click():
Expand Down Expand Up @@ -135,19 +132,7 @@ def __init__(self, iface):
def initGui(self):
"""Called when plugin is activated (on QGIS startup or when activated in Plugin Manager)."""

def create_icon(f):
"""
internal function to create action icons

:param f: file name of icon.
:type f: str

:returns: icon object to insert to QAction
:rtype: QIcon
"""
return QIcon(RESOURCE_PREFIX + f)

icon_plugin = create_icon("icon_orstools.png")
icon_plugin = gui.GuiUtils.get_icon("icon_orstools.png")

self.actions = [
QAction(
Expand All @@ -157,14 +142,18 @@ def create_icon(f):
),
# Config dialog
QAction(
create_icon("icon_settings.png"),
gui.GuiUtils.get_icon("icon_settings.png"),
self.tr("Provider Settings"),
self.iface.mainWindow(),
),
# About dialog
QAction(create_icon("icon_about.png"), self.tr("About"), self.iface.mainWindow()),
QAction(
gui.GuiUtils.get_icon("icon_about.png"), self.tr("About"), self.iface.mainWindow()
),
# Help page
QAction(create_icon("icon_help.png"), self.tr("Help"), self.iface.mainWindow()),
QAction(
gui.GuiUtils.get_icon("icon_help.png"), self.tr("Help"), self.iface.mainWindow()
),
]

# Create menu
Expand Down Expand Up @@ -227,7 +216,7 @@ def _init_gui_control(self):
# Make sure plugin window stays open when OK is clicked by reconnecting the accepted() signal
self.dlg.global_buttons.accepted.disconnect(self.dlg.accept)
self.dlg.global_buttons.accepted.connect(self.run_gui_control)
self.dlg.avoidpolygon_dropdown.setFilters(QgsMapLayerProxyModel.PolygonLayer)
self.dlg.avoidpolygon_dropdown.setFilters(QgsMapLayerProxyModel.Filter.PolygonLayer)

# Populate provider box on window startup, since can be changed from multiple menus/buttons
providers = configmanager.read_config()["providers"]
Expand Down Expand Up @@ -385,7 +374,10 @@ def tr(self, string):
return QCoreApplication.translate(str(self.__class__.__name__), string)


class ORStoolsDialog(QDialog, Ui_ORStoolsDialogBase):
MAIN_WIDGET, _ = uic.loadUiType(gui.GuiUtils.get_ui_file_path("ORStoolsDialogUI.ui"))


class ORStoolsDialog(QDialog, MAIN_WIDGET):
"""Define the custom behaviour of Dialog"""

def __init__(self, iface, parent=None):
Expand Down Expand Up @@ -416,8 +408,8 @@ def __init__(self, iface, parent=None):
self.routing_preference_combo.addItems(PREFERENCES)

# Change OK and Cancel button names
self.global_buttons.button(QDialogButtonBox.Ok).setText(self.tr("Apply"))
self.global_buttons.button(QDialogButtonBox.Cancel).setText(self.tr("Close"))
self.global_buttons.button(QDialogButtonBox.StandardButton.Ok).setText(self.tr("Apply"))
self.global_buttons.button(QDialogButtonBox.StandardButton.Cancel).setText(self.tr("Close"))

# Set up signals/slots

Expand Down Expand Up @@ -456,6 +448,15 @@ def __init__(self, iface, parent=None):
self.routing_fromline_list.model().rowsMoved.connect(self._reindex_list_items)
self.routing_fromline_list.model().rowsRemoved.connect(self._reindex_list_items)

# Add icons to buttons
self.routing_fromline_map.setIcon(gui.GuiUtils.get_icon("icon_add.png"))
self.routing_fromline_clear.setIcon(gui.GuiUtils.get_icon("icon_clear.png"))
self.save_vertices.setIcon(gui.GuiUtils.get_icon("save_vertices.png"))
self.provider_refresh.setIcon(gui.GuiUtils.get_icon("icon_refresh.png"))
self.provider_config.setIcon(gui.GuiUtils.get_icon("icon_settings.png"))
self.about_button.setIcon(gui.GuiUtils.get_icon("icon_about.png"))
self.help_button.setIcon(gui.GuiUtils.get_icon("icon_help.png"))

def _save_vertices_to_layer(self):
"""Saves the vertices list to a temp layer"""
items = [
Expand All @@ -480,7 +481,7 @@ def _save_vertices_to_layer(self):
self._iface.mapCanvas().refresh()

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

def _on_prov_refresh_click(self):
Expand Down
18 changes: 9 additions & 9 deletions ORStools/gui/ORStoolsDialogConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@

from qgis.gui import QgsCollapsibleGroupBox

from PyQt5 import QtWidgets
from PyQt5.QtCore import QMetaObject
from PyQt5.QtWidgets import QDialog, QInputDialog, QLineEdit
from PyQt5.QtGui import QIntValidator
from qgis.PyQt import QtWidgets, uic
from qgis.PyQt.QtCore import QMetaObject
from qgis.PyQt.QtWidgets import QDialog, QInputDialog, QLineEdit
from qgis.PyQt.QtGui import QIntValidator

from ORStools.utils import configmanager
from .ORStoolsDialogConfigUI import Ui_ORStoolsDialogConfigBase
from ORStools.utils import configmanager, gui

CONFIG_WIDGET, _ = uic.loadUiType(gui.GuiUtils.get_ui_file_path("ORStoolsDialogConfigUI.ui"))

class ORStoolsDialogConfigMain(QDialog, Ui_ORStoolsDialogConfigBase):

class ORStoolsDialogConfigMain(QDialog, CONFIG_WIDGET):
"""Builds provider config dialog."""

def __init__(self, parent=None):
Expand Down Expand Up @@ -73,7 +74,7 @@ def accept(self):
).text()
timeout_input = box.findChild(QtWidgets.QLineEdit, box.title() + "_timeout_text")
# https://doc.qt.io/qt-5/qvalidator.html#State-enum
if timeout_input.validator().State() != 2:
if timeout_input.validator().State != 2:
self._adjust_timeout_input(timeout_input)
current_provider["timeout"] = int(timeout_input.text())

Expand Down Expand Up @@ -209,4 +210,3 @@ def _add_box(self, name, url, key, timeout, new=False):
gridLayout_3.addWidget(timeout_text, 5, 0, 1, 4)

self.verticalLayout.addWidget(provider)
provider.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
53 changes: 0 additions & 53 deletions ORStools/gui/ORStoolsDialogConfigUI.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like more context on the deletion of this file.

This file was deleted.

Loading
Loading