Skip to content

Commit

Permalink
support for Qt 6 builds (#102)
Browse files Browse the repository at this point in the history
* move settings to QGIS API

* raise QGIS minimum to 3.34, config available for 3.40+

* remmoved submodule

* follow up

* fix docker image

* fix settings

* fix ui

* bump to 3.40
  • Loading branch information
3nids authored Oct 8, 2024
1 parent db416d6 commit d1b4ca9
Show file tree
Hide file tree
Showing 16 changed files with 303 additions and 200 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:

- name: docker test
run: |
docker run -v $(pwd):/usr/src -w /usr/src opengisch/qgis:${QGIS_TEST_VERSION} sh -c 'xvfb-run pytest-3 --ignore-glob=**/qgissettingmanager/*'
docker run -v $(pwd):/usr/src -w /usr/src qgis/qgis:${QGIS_TEST_VERSION} sh -c 'xvfb-run pytest-3'
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

39 changes: 26 additions & 13 deletions swiss_locator/core/filters/swiss_locator_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply, QNetworkAccessManager

from qgis.core import (
metaEnumFromType,
Qgis,
QgsLocatorFilter,
QgsLocatorResult,
Expand Down Expand Up @@ -59,6 +60,7 @@
)
from swiss_locator.core.settings import Settings
from swiss_locator.core.language import get_language

from swiss_locator.gui.config_dialog import ConfigDialog
from swiss_locator.gui.maptip import MapTip
from swiss_locator.gui.qtwebkit_conf import with_qt_web_kit
Expand Down Expand Up @@ -118,9 +120,12 @@ def __init__(
self.result_found = False
self.access_managers = {}
self.minimum_search_length = 2
self.me = metaEnumFromType(QgsLocatorFilter.Priority)

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

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

self.rubber_band = QgsRubberBand(self.map_canvas, QgsWkbTypes.GeometryType.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)
Expand All @@ -155,7 +162,13 @@ def name(self):
return self.__class__.__name__

def priority(self):
return self.settings.value(f"{self.type.value}_priority")
(value, ok) = self.me.keyToValue(
self.settings.filters[self.type.value]["priority"].value()
)
if ok:
return QgsLocatorFilter.Priority(value)
else:
return QgsLocatorFilter.Priority.Medium

def displayName(self):
# this should be re-implemented
Expand Down Expand Up @@ -185,20 +198,20 @@ def hasConfigWidget(self):

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

def create_transforms(self):
# this should happen in the main thread
self.crs = self.settings.value("crs")
if self.crs == "project":
map_crs = self.map_canvas.mapSettings().destinationCrs()
if map_crs.isValid() and ":" in map_crs.authid():
self.crs = map_crs.authid().split(":")[1]
if self.crs not in AVAILABLE_CRS:
self.crs = "2056"
map_crs = self.map_canvas.mapSettings().destinationCrs()
if map_crs.isValid() and ":" in map_crs.authid():
self.crs = map_crs.authid().split(":")[1]
if self.crs not in AVAILABLE_CRS:
self.crs = "2056"
assert self.crs in AVAILABLE_CRS
src_crs_ch = QgsCoordinateReferenceSystem("EPSG:{}".format(self.crs))
assert src_crs_ch.isValid()
Expand Down Expand Up @@ -421,7 +434,7 @@ def triggerResult(self, result: QgsLocatorResult):
point = QgsGeometry.fromPointXY(swiss_result.point)
point.transform(self.transform_4326)
self.highlight(point)
if self.settings.value("show_map_tip") and with_qt_web_kit():
if self.settings.show_map_tip.value() and with_qt_web_kit():
self.show_map_tip(swiss_result.layer, swiss_result.feature_id, point)

# Vector tiles
Expand Down Expand Up @@ -519,7 +532,7 @@ def triggerResult(self, result: QgsLocatorResult):
if layer and feature_id:
self.fetch_feature(layer, feature_id)

if self.settings.value("show_map_tip") and with_qt_web_kit():
if self.settings.show_map_tip.value() and with_qt_web_kit():
self.show_map_tip(layer, feature_id, point)
else:
self.current_timer = QTimer()
Expand Down
2 changes: 1 addition & 1 deletion swiss_locator/core/filters/swiss_locator_filter_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def perform_fetch_results(self, search: str, feedback: QgsFeedback):
# otherwise URL is too long
requests = []
try:
limit = self.settings.value(f"{FilterType.Feature.value}_limit")
limit = self.settings.filter_feature_limit.value()
layers = list(self.searchable_layers.keys())
assert len(layers) > 0
step = 20
Expand Down
2 changes: 1 addition & 1 deletion swiss_locator/core/filters/swiss_locator_filter_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def prefix(self):
return "chl"

def perform_fetch_results(self, search: str, feedback: QgsFeedback):
limit = self.settings.value(f"{FilterType.Location.value}_limit")
limit = self.settings.filter_layers_limit.value()
urls = [
map_geo_admin_url(search, self.type.value, self.crs, self.lang, limit),
opendata_swiss_url(search),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def prefix(self):
return "chs"

def perform_fetch_results(self, search: str, feedback: QgsFeedback):
limit = self.settings.value(f"{FilterType.Location.value}_limit")
limit = self.settings.filter_location_limit.value()
url, params = map_geo_admin_url(
search, self.type.value, self.crs, self.lang, limit
)
Expand Down
30 changes: 17 additions & 13 deletions swiss_locator/core/filters/swiss_locator_filter_vector_tiles.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from qgis.gui import QgisInterface
from qgis.core import (
QgsApplication,
QgsBlockingNetworkRequest,
QgsFetchedContent,
QgsLocatorResult,
QgsFeedback,
)
Expand Down Expand Up @@ -38,27 +36,31 @@ def perform_fetch_results(self, search: str, feedback: QgsFeedback):
"title": "Base map",
"description": "",
"url": "https://vectortiles.geo.admin.ch/tiles/ch.swisstopo.base.vt/v1.0.0/{z}/{x}/{y}.pbf",
"style": "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json"
"style": "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json",
},
"light base map": {
"title": "Light base map", "description": "",
"title": "Light base map",
"description": "",
"url": "https://vectortiles.geo.admin.ch/tiles/ch.swisstopo.base.vt/v1.0.0/{z}/{x}/{y}.pbf",
"style": "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.lightbasemap.vt/style.json"
"style": "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.lightbasemap.vt/style.json",
},
"imagery base map": {
"title": "Imagery base map", "description": "",
"title": "Imagery base map",
"description": "",
"url": "https://vectortiles.geo.admin.ch/tiles/ch.swisstopo.base.vt/v1.0.0/{z}/{x}/{y}.pbf",
"style": "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.imagerybasemap.vt/style.json"
"style": "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.imagerybasemap.vt/style.json",
},
"leichte-basiskarte": {
"title": "leichte-basiskarte", "description": "",
"title": "leichte-basiskarte",
"description": "",
"url": "https://vectortiles.geo.admin.ch/tiles/ch.swisstopo.leichte-basiskarte.vt/v3.0.1/{z}/{x}/{y}.pbf",
"style": "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.leichte-basiskarte.vt/style.json"
"style": "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.leichte-basiskarte.vt/style.json",
},
"leichte-basiskarte-imagery": {
"title": "leichte-basiskarte-imagery", "description": "",
"title": "leichte-basiskarte-imagery",
"description": "",
"url": "https://vectortiles.geo.admin.ch/tiles/ch.swisstopo.leichte-basiskarte.vt/v3.0.1/{z}/{x}/{y}.pbf",
"style": "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.leichte-basiskarte-imagery.vt/style.json"
"style": "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.leichte-basiskarte-imagery.vt/style.json",
},
}

Expand All @@ -68,7 +70,9 @@ def perform_fetch_results(self, search: str, feedback: QgsFeedback):
if not search or search.lower() in keyword:
result = QgsLocatorResult()
result.filter = self
result.icon = QgsApplication.getThemeIcon("/mActionAddVectorTileLayer.svg")
result.icon = QgsApplication.getThemeIcon(
"/mActionAddVectorTileLayer.svg"
)

result.displayString = data[keyword]["title"]
result.description = data[keyword]["description"]
Expand All @@ -82,7 +86,7 @@ def perform_fetch_results(self, search: str, feedback: QgsFeedback):
results[result] = score

# sort the results with score
#results = sorted([result for (result, score) in results.items()])
# results = sorted([result for (result, score) in results.items()])

for result in results:
self.resultFetched.emit(result)
Expand Down
17 changes: 12 additions & 5 deletions swiss_locator/core/filters/swiss_locator_filter_wmts.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def __init__(self, iface: QgisInterface = None, crs: str = None, capabilities=No

self.info(self.content.status())

if self.content.status() == QgsFetchedContent.ContentStatus.Finished and self.content.filePath():
if (
self.content.status() == QgsFetchedContent.ContentStatus.Finished
and self.content.filePath()
):
file_path = self.content.filePath()
self.info(
f"Swisstopo capabilities already downloaded. Reading from {file_path}"
Expand All @@ -73,7 +76,8 @@ def clone(self):
nam.get(request, forceRefresh=True)
reply = nam.reply()
if (
reply.attribute(QNetworkRequest.Attribute.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 @@ -92,15 +96,18 @@ def prefix(self):
return "chw"

def handle_capabilities_response(self):
if self.content.status() == QgsFetchedContent.ContentStatus.Finished and self.content.filePath():
if (
self.content.status() == QgsFetchedContent.ContentStatus.Finished
and self.content.filePath()
):
self.info(
f"Swisstopo capabilities has been downloaded. Reading from {self.content.filePath()}"
)
self.capabilities = ET.parse(self.content.filePath()).getroot()
else:
self.info(
"The Swiss Locator filter for WMTS layers could not fetch capabilities",
Qgis.MessageLevel.Critical
Qgis.MessageLevel.Critical,
)

def perform_fetch_results(self, search: str, feedback: QgsFeedback):
Expand Down Expand Up @@ -170,6 +177,6 @@ def perform_fetch_results(self, search: str, feedback: QgsFeedback):
# sort the results with score
results = sorted([result for (result, score) in results.items()])

for result in results[0 : self.settings.value("wmts_limit")]:
for result in results[0 : self.settings.filter_wmts_limit.value()]:
self.resultFetched.emit(result)
self.result_found = True
11 changes: 4 additions & 7 deletions swiss_locator/core/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from qgis.PyQt.QtCore import QLocale, QSettings
from .settings import Settings
from qgis.core import NULL
from .parameters import AVAILABLE_LANGUAGES


def get_language() -> str:
Expand All @@ -36,17 +37,13 @@ def get_language() -> str:
:return: 2 chars long string representing the language to be used
"""
# get lang from settings
lang = Settings().value("lang")
lang = Settings().lang.value()
if not lang:
# if None, try to use the locale one
from .parameters import AVAILABLE_LANGUAGES

locale = str(QSettings().value("locale/userLocale")).replace(str(NULL), "en_CH")
locale_lang = QLocale.languageToString(QLocale(locale).language())
if locale_lang in AVAILABLE_LANGUAGES:
lang = AVAILABLE_LANGUAGES[locale_lang]
else:
# defaults to English
lang = "en"
if lang not in AVAILABLE_LANGUAGES:
lang = "en"

return lang
Loading

0 comments on commit d1b4ca9

Please sign in to comment.