Skip to content

Commit

Permalink
Run migration script to add Qt6 support (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
gacarrillor authored Jul 22, 2024
1 parent f405074 commit 0c34fb3
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 86 deletions.
68 changes: 34 additions & 34 deletions swiss_locator/core/filters/swiss_locator_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import sys
import traceback

from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QLabel, QWidget, QTabWidget
from PyQt5.QtCore import QUrl, pyqtSignal, QEventLoop
from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply, QNetworkAccessManager
from qgis.PyQt.QtCore import Qt, QTimer
from qgis.PyQt.QtGui import QColor
from qgis.PyQt.QtWidgets import QLabel, QWidget, QTabWidget
from qgis.PyQt.QtCore import QUrl, pyqtSignal, QEventLoop
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply, QNetworkAccessManager

from qgis.core import (
Qgis,
Expand Down Expand Up @@ -120,7 +120,7 @@ def __init__(
self.minimum_search_length = 2

self.nam = QNetworkAccessManager()
self.nam.setRedirectPolicy(QNetworkRequest.NoLessSafeRedirectPolicy)
self.nam.setRedirectPolicy(QNetworkRequest.RedirectPolicy.NoLessSafeRedirectPolicy)
self.network_replies = dict()

if crs:
Expand All @@ -133,20 +133,20 @@ def __init__(
self.map_canvas = iface.mapCanvas()
self.map_canvas.destinationCrsChanged.connect(self.create_transforms)

self.rubber_band = QgsRubberBand(self.map_canvas, QgsWkbTypes.PointGeometry)
self.rubber_band = QgsRubberBand(self.map_canvas, QgsWkbTypes.GeometryType.PointGeometry)
self.rubber_band.setColor(QColor(255, 255, 50, 200))
self.rubber_band.setIcon(self.rubber_band.ICON_CIRCLE)
self.rubber_band.setIconSize(15)
self.rubber_band.setWidth(4)
self.rubber_band.setBrushStyle(Qt.NoBrush)
self.rubber_band.setBrushStyle(Qt.BrushStyle.NoBrush)

self.feature_rubber_band = QgsRubberBand(
self.map_canvas, QgsWkbTypes.PolygonGeometry
self.map_canvas, QgsWkbTypes.GeometryType.PolygonGeometry
)
self.feature_rubber_band.setColor(QColor(255, 50, 50, 200))
self.feature_rubber_band.setFillColor(QColor(255, 255, 50, 160))
self.feature_rubber_band.setBrushStyle(Qt.SolidPattern)
self.feature_rubber_band.setLineStyle(Qt.SolidLine)
self.feature_rubber_band.setBrushStyle(Qt.BrushStyle.SolidPattern)
self.feature_rubber_band.setLineStyle(Qt.PenStyle.SolidLine)
self.feature_rubber_band.setWidth(4)

self.create_transforms()
Expand All @@ -170,8 +170,8 @@ def prefix(self):
)

def clearPreviousResults(self):
self.rubber_band.reset(QgsWkbTypes.PointGeometry)
self.feature_rubber_band.reset(QgsWkbTypes.PolygonGeometry)
self.rubber_band.reset(QgsWkbTypes.GeometryType.PointGeometry)
self.feature_rubber_band.reset(QgsWkbTypes.GeometryType.PolygonGeometry)
if self.map_tip is not None:
del self.map_tip
self.map_tip = None
Expand All @@ -185,10 +185,10 @@ def hasConfigWidget(self):

def openConfigWidget(self, parent=None):
dlg = ConfigDialog(parent)
wid = dlg.findChild(QTabWidget, "tabWidget", Qt.FindDirectChildrenOnly)
wid = dlg.findChild(QTabWidget, "tabWidget", Qt.FindChildOption.FindDirectChildrenOnly)
tab = wid.findChild(QWidget, self.type.value)
wid.setCurrentWidget(tab)
dlg.exec_()
dlg.exec()

def create_transforms(self):
# this should happen in the main thread
Expand Down Expand Up @@ -249,7 +249,7 @@ def handle_reply(self, url: str, feedback: QgsFeedback, slot, data=None):
reply = self.network_replies[url]

try:
if reply.error() != QNetworkReply.NoError:
if reply.error() != QNetworkReply.NetworkError.NoError:
self.info(f"could not load url: {reply.errorString()}")
else:
content = reply.readAll().data().decode("utf-8")
Expand All @@ -259,16 +259,16 @@ def handle_reply(self, url: str, feedback: QgsFeedback, slot, data=None):
slot(content, feedback)

except Exception as e:
self.info(e, Qgis.Critical)
self.info(e, Qgis.MessageLevel.Critical)
exc_type, exc_obj, exc_traceback = sys.exc_info()
filename = os.path.split(exc_traceback.tb_frame.f_code.co_filename)[1]
self.info(
"{} {} {}".format(exc_type, filename, exc_traceback.tb_lineno),
Qgis.Critical,
Qgis.MessageLevel.Critical,
)
self.info(
traceback.print_exception(exc_type, exc_obj, exc_traceback),
Qgis.Critical,
Qgis.MessageLevel.Critical,
)

# clean nam
Expand Down Expand Up @@ -306,7 +306,7 @@ def fetch_requests(

# Let the requests end and catch all exceptions (and clean up requests)
if len(self.network_replies) > 0:
self.event_loop.exec_(QEventLoop.ExcludeUserInputEvents)
self.event_loop.exec(QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents)

def fetchResults(
self, search: str, context: QgsLocatorContext, feedback: QgsFeedback
Expand All @@ -327,16 +327,16 @@ def fetchResults(
self.resultFetched.emit(result)

except Exception as e:
self.info(e, Qgis.Critical)
self.info(e, Qgis.MessageLevel.Critical)
exc_type, exc_obj, exc_traceback = sys.exc_info()
filename = os.path.split(exc_traceback.tb_frame.f_code.co_filename)[1]
self.info(
"{} {} {}".format(exc_type, filename, exc_traceback.tb_lineno),
Qgis.Critical,
Qgis.MessageLevel.Critical,
)
self.info(
traceback.print_exception(exc_type, exc_obj, exc_traceback),
Qgis.Critical,
Qgis.MessageLevel.Critical,
)

def triggerResult(self, result: QgsLocatorResult):
Expand All @@ -354,7 +354,7 @@ def triggerResult(self, result: QgsLocatorResult):
self.tr(
"QGIS Swiss Locator encountered an error. Please <b>update to QGIS 3.16.2</b> or newer."
),
Qgis.Warning,
Qgis.MessageLevel.Warning,
None,
)
return
Expand Down Expand Up @@ -383,8 +383,8 @@ def triggerResult(self, result: QgsLocatorResult):
self.info(f"Loading layer: {url_with_params}")
ch_layer = QgsRasterLayer(url_with_params, result.displayString, "wms")
label = QLabel()
label.setTextFormat(Qt.RichText)
label.setTextInteractionFlags(Qt.TextBrowserInteraction)
label.setTextFormat(Qt.TextFormat.RichText)
label.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction)
label.setOpenExternalLinks(True)

if "geo.admin.ch" in swiss_result.url.lower():
Expand All @@ -402,15 +402,15 @@ def triggerResult(self, result: QgsLocatorResult):
swiss_result.title, swiss_result.layer
)
)
level = Qgis.Warning
level = Qgis.MessageLevel.Warning
self.info(msg, level)
else:
msg = self.tr(
"Layers layer added to the map: {} ({})".format(
swiss_result.title, swiss_result.layer
)
)
level = Qgis.Info
level = Qgis.MessageLevel.Info

QgsProject.instance().addMapLayer(ch_layer)

Expand Down Expand Up @@ -447,7 +447,7 @@ def triggerResult(self, result: QgsLocatorResult):
swiss_result.title
)
)
level = Qgis.Warning
level = Qgis.MessageLevel.Warning
self.info(msg, level)
else:
ch_layer.setLabelsEnabled(True)
Expand All @@ -463,7 +463,7 @@ def triggerResult(self, result: QgsLocatorResult):
"; ".join([sublayer.name() for sublayer in sublayers])
)
)
level = Qgis.Info
level = Qgis.MessageLevel.Info
self.info(msg, level)
if error or warnings:
msg = self.tr(
Expand All @@ -473,15 +473,15 @@ def triggerResult(self, result: QgsLocatorResult):
"; ".join(warnings)
)
)
level = Qgis.Warning
level = Qgis.MessageLevel.Warning
self.info(msg, level)

msg = self.tr(
"Layer added to the map: {}".format(
swiss_result.title
)
)
level = Qgis.Info
level = Qgis.MessageLevel.Info
self.info(msg, level)

# Load basemap layers at the bottom of the layer tree
Expand Down Expand Up @@ -546,14 +546,14 @@ def parse_map_tip_response(self, content, feedback, point):
def highlight(self, point, bbox=None):
if bbox is None:
bbox = point
self.rubber_band.reset(QgsWkbTypes.PointGeometry)
self.rubber_band.reset(QgsWkbTypes.GeometryType.PointGeometry)
self.rubber_band.addGeometry(point, None)
rect = bbox.boundingBox()
rect.scale(1.1)
self.map_canvas.setExtent(rect)
self.map_canvas.refresh()

def info(self, msg="", level=Qgis.Info):
def info(self, msg="", level=Qgis.MessageLevel.Info):
self.logMessage(str(msg), level)

def dbg_info(self, msg=""):
Expand Down
6 changes: 3 additions & 3 deletions swiss_locator/core/filters/swiss_locator_filter_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import json

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

from qgis.core import (
Qgis,
Expand Down Expand Up @@ -72,7 +72,7 @@ def perform_fetch_results(self, search: str, feedback: QgsFeedback):
except IOError:
self.info(
"Layers data file not found. Please report an issue.",
Qgis.Critical,
Qgis.MessageLevel.Critical,
)
self.fetch_requests(requests, feedback, self.handle_content)

Expand All @@ -96,7 +96,7 @@ def handle_content(self, content: str, feedback: QgsFeedback):
f"Layer {layer} is not in the list of searchable layers."
" Please report issue."
),
Qgis.Warning,
Qgis.MessageLevel.Warning,
)
layer_display = layer
result.group = layer_display
Expand Down
8 changes: 4 additions & 4 deletions swiss_locator/core/filters/swiss_locator_filter_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ def handle_content(self, content: str, feedback: QgsFeedback):
self.resultFetched.emit(result)

except Exception as e:
self.info(str(e), Qgis.Critical)
self.info(str(e), Qgis.MessageLevel.Critical)
exc_type, exc_obj, exc_traceback = sys.exc_info()
filename = os.path.split(exc_traceback.tb_frame.f_code.co_filename)[1]
self.info(
f"{exc_type} {filename} {exc_traceback.tb_lineno}",
Qgis.Critical,
Qgis.MessageLevel.Critical,
)
self.info(
traceback.print_exception(exc_type, exc_obj, exc_traceback),
Qgis.Critical,
Qgis.MessageLevel.Critical,
)

def fetch_feature(self, layer, feature_id):
Expand All @@ -135,7 +135,7 @@ def parse_feature_response(self, content, feedback: QgsFeedback):
geometry = QgsGeometry.fromPolygonXY(rings)
geometry.transform(self.transform_ch)

self.feature_rubber_band.reset(QgsWkbTypes.PolygonGeometry)
self.feature_rubber_band.reset(QgsWkbTypes.GeometryType.PolygonGeometry)
self.feature_rubber_band.addGeometry(geometry, None)

def group_info(self, group: str) -> (str, str):
Expand Down
4 changes: 2 additions & 2 deletions swiss_locator/core/filters/swiss_locator_filter_wmts.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def clone(self):
nam.get(request, forceRefresh=True)
reply = nam.reply()
if (
reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) == 200
reply.attribute(QNetworkRequest.Attribute.HttpStatusCodeAttribute) == 200
): # other codes are handled by NetworkAccessManager
self.capabilities = ET.fromstring(reply.content().data().decode("utf8"))
else:
Expand All @@ -100,7 +100,7 @@ def handle_capabilities_response(self):
else:
self.info(
"The Swiss Locator filter for WMTS layers could not fetch capabilities",
Qgis.Critical
Qgis.MessageLevel.Critical
)

def perform_fetch_results(self, search: str, feedback: QgsFeedback):
Expand Down
2 changes: 1 addition & 1 deletion swiss_locator/core/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#
# ---------------------------------------------------------------------

from PyQt5.QtCore import QLocale, QSettings
from qgis.PyQt.QtCore import QLocale, QSettings
from .settings import Settings
from qgis.core import NULL

Expand Down
6 changes: 3 additions & 3 deletions swiss_locator/core/profiles/profile_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __get_profile_from_rest_api(self):
QgsMessageLog.logMessage(
"Unable to parse results from Profile service. Details: {}".format(e.msg),
"Swiss locator",
Qgis.Critical
Qgis.MessageLevel.Critical
)

return result
Expand All @@ -85,7 +85,7 @@ def generateProfile(self, context): # QgsProfileGenerationContext
except QgsCsException as e:
QgsMessageLog.logMessage("Error transforming profile line to EPSG:2056.",
"Swiss locator",
Qgis.Critical)
Qgis.MessageLevel.Critical)
return False

self.__results = SwissProfileResults()
Expand All @@ -94,7 +94,7 @@ def generateProfile(self, context): # QgsProfileGenerationContext
result = self.__get_profile_from_rest_api()

if "error" in result:
QgsMessageLog.logMessage(result["error"], "Swiss locator", Qgis.Critical)
QgsMessageLog.logMessage(result["error"], "Swiss locator", Qgis.MessageLevel.Critical)
return False

cartesian_d = 0
Expand Down
8 changes: 4 additions & 4 deletions swiss_locator/core/profiles/profile_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def __render_continuous_surface(self, context):
if not painter:
return

painter.setBrush(Qt.NoBrush)
painter.setPen(Qt.NoPen)
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.setPen(Qt.PenStyle.NoPen)

min_distance = context.distanceRange().lower()
max_distance = context.distanceRange().upper()
Expand Down Expand Up @@ -187,8 +187,8 @@ def __render_markers(self, context):
if not painter:
return

painter.setBrush(Qt.NoBrush)
painter.setPen(Qt.NoPen)
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.setPen(Qt.PenStyle.NoPen)

minDistance = context.distanceRange().lower()
maxDistance = context.distanceRange().upper()
Expand Down
Loading

0 comments on commit 0c34fb3

Please sign in to comment.