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

run pyqt5_to_pyqt6 script #246

Merged
merged 5 commits into from
May 17, 2024
Merged
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 @@ -29,7 +29,7 @@

from qgis.gui import QgisInterface
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 @@ -34,7 +34,7 @@
from typing import Union, Dict, List, Optional
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, Generator, Tuple, Any, Optional

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

from ORStools.utils import convert, logger

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 @@ -42,8 +42,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 @@ -265,7 +265,7 @@ def request(

# 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 @@ -295,8 +295,10 @@ def requestTimedOut(self, reply) -> None:

def replyFinished(self) -> None:
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 @@ -308,7 +310,7 @@ def replyFinished(self) -> None:
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 @@ -328,13 +330,13 @@ def replyFinished(self) -> None:
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 @@ -350,7 +352,9 @@ def replyFinished(self) -> None:

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
16 changes: 8 additions & 8 deletions ORStools/gui/ORStoolsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
)
from qgis.gui import QgsMapCanvasAnnotationItem

from PyQt5.QtCore import QSizeF, QPointF, QCoreApplication
from PyQt5.QtGui import QIcon, QTextDocument
from PyQt5.QtWidgets import (
from qgis.PyQt.QtCore import QSizeF, QPointF, QCoreApplication
from qgis.PyQt.QtGui import QIcon, QTextDocument
from qgis.PyQt.QtWidgets import (
QAction,
QDialog,
QApplication,
Expand Down Expand Up @@ -91,7 +91,7 @@ def on_config_click(parent):
:type parent: QDialog
"""
config_dlg = ORStoolsDialogConfigMain(parent=parent)
config_dlg.exec_()
config_dlg.exec()


def on_help_click() -> None:
Expand Down Expand Up @@ -238,7 +238,7 @@ def _init_gui_control(self) -> None:
# 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 @@ -450,8 +450,8 @@ def __init__(self, iface: QgisInterface, parent=None) -> 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 @@ -516,7 +516,7 @@ def _save_vertices_to_layer(self) -> None:
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) -> None:
Expand Down
6 changes: 3 additions & 3 deletions ORStools/gui/ORStoolsDialogConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
from qgis.gui import QgsCollapsibleGroupBox

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

from ORStools.utils import configmanager
from .ORStoolsDialogConfigUI import Ui_ORStoolsDialogConfigBase
Expand Down
2 changes: 1 addition & 1 deletion ORStools/gui/directions_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import json

from PyQt5.QtWidgets import QCheckBox
from qgis.PyQt.QtWidgets import QCheckBox

from ORStools.utils import transform

Expand Down
12 changes: 7 additions & 5 deletions ORStools/proc/base_processing_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
***************************************************************************/
"""

from PyQt5.QtCore import QCoreApplication
from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (
QgsProcessing,
QgsProcessingAlgorithm,
Expand All @@ -42,7 +42,7 @@
)
from typing import Any, Dict

from PyQt5.QtGui import QIcon
from qgis.PyQt.QtGui import QIcon

from ORStools import RESOURCE_PREFIX, __help__
from ORStools.utils import configmanager
Expand Down Expand Up @@ -174,7 +174,7 @@ def option_parameters(self) -> [QgsProcessingParameterDefinition]:
QgsProcessingParameterFeatureSource(
self.IN_AVOID_POLYGONS,
self.tr("Polygons to avoid", "ORSBaseProcessingAlgorithm"),
types=[QgsProcessing.TypeVectorPolygon],
types=[QgsProcessing.SourceType.TypeVectorPolygon],
optional=True,
),
]
Expand Down Expand Up @@ -236,11 +236,13 @@ def initAlgorithm(self, configuration: Dict) -> None:
for param in parameters:
if param.name() in ADVANCED_PARAMETERS:
if self.GROUP == "Matrix":
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagHidden)
param.setFlags(param.flags() | QgsProcessingParameterDefinition.Flag.FlagHidden)
else:
# flags() is a wrapper around an enum of ints for type-safety.
# Flags are added by or-ing values, much like the union operator would work
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
param.setFlags(
param.flags() | QgsProcessingParameterDefinition.Flag.FlagAdvanced
)

self.addParameter(param)

Expand Down
6 changes: 3 additions & 3 deletions ORStools/proc/directions_lines_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self):
QgsProcessingParameterFeatureSource(
name=self.IN_LINES,
description=self.tr("Input Line layer"),
types=[QgsProcessing.TypeVectorLine],
types=[QgsProcessing.SourceType.TypeVectorLine],
),
QgsProcessingParameterField(
name=self.IN_FIELD,
Expand Down Expand Up @@ -264,15 +264,15 @@ def _get_sorted_lines(layer: QgsProcessingFeatureSource, field_name: str) -> Gen
line = None
field_value = feat[field_name] if field_name else None

if QgsWkbTypes.flatType(layer.wkbType()) == QgsWkbTypes.MultiLineString:
if QgsWkbTypes.flatType(layer.wkbType()) == QgsWkbTypes.Type.MultiLineString:
# TODO: only takes the first polyline geometry from the multiline geometry currently
# Loop over all polyline geometries
line = [
x_former.transform(QgsPointXY(point))
for point in feat.geometry().asMultiPolyline()[0]
]

elif QgsWkbTypes.flatType(layer.wkbType()) == QgsWkbTypes.LineString:
elif QgsWkbTypes.flatType(layer.wkbType()) == QgsWkbTypes.Type.LineString:
line = [
x_former.transform(QgsPointXY(point)) for point in feat.geometry().asPolyline()
]
Expand Down
8 changes: 4 additions & 4 deletions ORStools/proc/directions_points_layer_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self):
QgsProcessingParameterFeatureSource(
name=self.IN_POINTS,
description=self.tr("Input (Multi)Point layer"),
types=[QgsProcessing.TypeVectorPoint],
types=[QgsProcessing.SourceType.TypeVectorPoint],
),
QgsProcessingParameterField(
name=self.IN_FIELD,
Expand Down Expand Up @@ -176,7 +176,7 @@ def processAlgorithm(
self.OUT,
context,
sink_fields,
QgsWkbTypes.LineString,
QgsWkbTypes.Type.LineString,
QgsCoordinateReferenceSystem.fromEpsgId(4326),
)

Expand All @@ -197,13 +197,13 @@ def sort(f):
from_values = list()
x_former = transform.transformToWGS(source.sourceCrs())

if QgsWkbTypes.flatType(source.wkbType()) == QgsWkbTypes.Point:
if QgsWkbTypes.flatType(source.wkbType()) == QgsWkbTypes.Type.Point:
points = list()
for feat in sorted(source.getFeatures(), key=sort):
points.append(x_former.transform(QgsPointXY(feat.geometry().asPoint())))
input_points.append(points)
from_values.append(None)
elif QgsWkbTypes.flatType(source.wkbType()) == QgsWkbTypes.MultiPoint:
elif QgsWkbTypes.flatType(source.wkbType()) == QgsWkbTypes.Type.MultiPoint:
# loop through multipoint features
for feat in sorted(source.getFeatures(), key=sort):
for point in feat.geometry().asMultiPoint():
Expand Down
6 changes: 3 additions & 3 deletions ORStools/proc/directions_points_layers_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self):
QgsProcessingParameterFeatureSource(
name=self.IN_START,
description=self.tr("Input Start Point layer"),
types=[QgsProcessing.TypeVectorPoint],
types=[QgsProcessing.SourceType.TypeVectorPoint],
),
QgsProcessingParameterField(
name=self.IN_START_FIELD,
Expand All @@ -90,7 +90,7 @@ def __init__(self):
QgsProcessingParameterFeatureSource(
name=self.IN_END,
description=self.tr("Input End Point layer"),
types=[QgsProcessing.TypeVectorPoint],
types=[QgsProcessing.SourceType.TypeVectorPoint],
),
QgsProcessingParameterField(
name=self.IN_END_FIELD,
Expand Down Expand Up @@ -216,7 +216,7 @@ def sort_end(f):
self.OUT,
context,
sink_fields,
QgsWkbTypes.LineString,
QgsWkbTypes.Type.LineString,
QgsCoordinateReferenceSystem.fromEpsgId(4326),
)

Expand Down
6 changes: 3 additions & 3 deletions ORStools/proc/isochrones_layer_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self):
QgsProcessingParameterFeatureSource(
name=self.IN_POINTS,
description=self.tr("Input Point layer"),
types=[QgsProcessing.TypeVectorPoint],
types=[QgsProcessing.SourceType.TypeVectorPoint],
),
# QgsProcessingParameterBoolean(
# name=self.IN_DIFFERENCE,
Expand Down Expand Up @@ -141,7 +141,7 @@ def processAlgorithm(

# Make the actual requests
requests = []
if QgsWkbTypes.flatType(source.wkbType()) == QgsWkbTypes.MultiPoint:
if QgsWkbTypes.flatType(source.wkbType()) == QgsWkbTypes.Type.MultiPoint:
raise QgsProcessingException(
"TypeError: Multipoint Layers are not accepted. Please convert to single geometry layer."
)
Expand Down Expand Up @@ -181,7 +181,7 @@ def processAlgorithm(
self.OUT,
context,
self.isochrones.get_fields(),
QgsWkbTypes.Polygon,
QgsWkbTypes.Type.Polygon,
# Needs Multipolygon if difference parameter will ever be
# reactivated
self.crs_out,
Expand Down
2 changes: 1 addition & 1 deletion ORStools/proc/isochrones_point_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def processAlgorithm(
self.OUT,
context,
self.isochrones.get_fields(),
QgsWkbTypes.Polygon,
QgsWkbTypes.Type.Polygon,
# Needs Multipolygon if difference parameter will ever be
# reactivated
self.crs_out,
Expand Down
10 changes: 5 additions & 5 deletions ORStools/proc/matrix_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
QgsProcessingFeedback,
)

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

from ORStools.common import PROFILES
from ORStools.utils import transform, exceptions, logger
Expand All @@ -63,7 +63,7 @@ def __init__(self):
QgsProcessingParameterFeatureSource(
name=self.IN_START,
description=self.tr("Input Start Point layer"),
types=[QgsProcessing.TypeVectorPoint],
types=[QgsProcessing.SourceType.TypeVectorPoint],
),
QgsProcessingParameterField(
name=self.IN_START_FIELD,
Expand All @@ -75,7 +75,7 @@ def __init__(self):
QgsProcessingParameterFeatureSource(
name=self.IN_END,
description=self.tr("Input End Point layer"),
types=[QgsProcessing.TypeVectorPoint],
types=[QgsProcessing.SourceType.TypeVectorPoint],
),
QgsProcessingParameterField(
name=self.IN_END_FIELD,
Expand Down Expand Up @@ -112,7 +112,7 @@ def processAlgorithm(
# Abort when MultiPoint type
if (
QgsWkbTypes.flatType(source.wkbType()) or QgsWkbTypes.flatType(destination.wkbType())
) == QgsWkbTypes.MultiPoint:
) == QgsWkbTypes.Type.MultiPoint:
raise QgsProcessingException(
"TypeError: Multipoint Layers are not accepted. Please convert to single geometry layer."
)
Expand Down Expand Up @@ -183,7 +183,7 @@ def processAlgorithm(
logger.log(msg)

(sink, dest_id) = self.parameterAsSink(
parameters, self.OUT, context, sink_fields, QgsWkbTypes.NoGeometry
parameters, self.OUT, context, sink_fields, QgsWkbTypes.Type.NoGeometry
)

sources_attributes = [
Expand Down
2 changes: 1 addition & 1 deletion ORStools/proc/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from qgis.core import QgsProcessingProvider

from PyQt5.QtGui import QIcon
from qgis.PyQt.QtGui import QIcon

from ORStools import RESOURCE_PREFIX, PLUGIN_NAME, __version__
from .directions_lines_proc import ORSDirectionsLinesAlgo
Expand Down
Loading
Loading