diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 3162396..ef47a86 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -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'
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 6dbbcef..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "swiss_locator/qgissettingmanager"]
- path = swiss_locator/qgissettingmanager
- url = git@github.com:opengisch/qgis_setting_manager.git
diff --git a/swiss_locator/core/filters/swiss_locator_filter.py b/swiss_locator/core/filters/swiss_locator_filter.py
index 85a0899..26fec1a 100644
--- a/swiss_locator/core/filters/swiss_locator_filter.py
+++ b/swiss_locator/core/filters/swiss_locator_filter.py
@@ -31,6 +31,7 @@
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply, QNetworkAccessManager
from qgis.core import (
+ metaEnumFromType,
Qgis,
QgsLocatorFilter,
QgsLocatorResult,
@@ -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
@@ -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:
@@ -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)
@@ -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
@@ -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()
@@ -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
@@ -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()
diff --git a/swiss_locator/core/filters/swiss_locator_filter_feature.py b/swiss_locator/core/filters/swiss_locator_filter_feature.py
index fd1085c..fd83ab7 100644
--- a/swiss_locator/core/filters/swiss_locator_filter_feature.py
+++ b/swiss_locator/core/filters/swiss_locator_filter_feature.py
@@ -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
diff --git a/swiss_locator/core/filters/swiss_locator_filter_layer.py b/swiss_locator/core/filters/swiss_locator_filter_layer.py
index 524b789..c8d4385 100644
--- a/swiss_locator/core/filters/swiss_locator_filter_layer.py
+++ b/swiss_locator/core/filters/swiss_locator_filter_layer.py
@@ -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),
diff --git a/swiss_locator/core/filters/swiss_locator_filter_location.py b/swiss_locator/core/filters/swiss_locator_filter_location.py
index 7d24e61..daca5d0 100644
--- a/swiss_locator/core/filters/swiss_locator_filter_location.py
+++ b/swiss_locator/core/filters/swiss_locator_filter_location.py
@@ -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
)
diff --git a/swiss_locator/core/filters/swiss_locator_filter_vector_tiles.py b/swiss_locator/core/filters/swiss_locator_filter_vector_tiles.py
index cc8b937..8a2a6bd 100644
--- a/swiss_locator/core/filters/swiss_locator_filter_vector_tiles.py
+++ b/swiss_locator/core/filters/swiss_locator_filter_vector_tiles.py
@@ -1,8 +1,6 @@
from qgis.gui import QgisInterface
from qgis.core import (
QgsApplication,
- QgsBlockingNetworkRequest,
- QgsFetchedContent,
QgsLocatorResult,
QgsFeedback,
)
@@ -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",
},
}
@@ -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"]
@@ -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)
diff --git a/swiss_locator/core/filters/swiss_locator_filter_wmts.py b/swiss_locator/core/filters/swiss_locator_filter_wmts.py
index 5ebd014..6b36b93 100644
--- a/swiss_locator/core/filters/swiss_locator_filter_wmts.py
+++ b/swiss_locator/core/filters/swiss_locator_filter_wmts.py
@@ -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}"
@@ -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:
@@ -92,7 +96,10 @@ 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()}"
)
@@ -100,7 +107,7 @@ def handle_capabilities_response(self):
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):
@@ -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
diff --git a/swiss_locator/core/language.py b/swiss_locator/core/language.py
index ad3712a..e1d24a3 100644
--- a/swiss_locator/core/language.py
+++ b/swiss_locator/core/language.py
@@ -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:
@@ -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
diff --git a/swiss_locator/core/settings.py b/swiss_locator/core/settings.py
index d67e0d1..c3cd400 100644
--- a/swiss_locator/core/settings.py
+++ b/swiss_locator/core/settings.py
@@ -24,82 +24,96 @@
#
# ---------------------------------------------------------------------
-
-from qgis.core import QgsLocatorFilter
-from swiss_locator.qgissettingmanager import (
- SettingManager,
- Scope,
- Bool,
- String,
- Stringlist,
- Integer,
- Enum,
+from qgis.core import (
+ metaEnumFromType,
+ QgsLocatorFilter,
+ QgsSettingsTree,
+ QgsSettingsEntryBool,
+ QgsSettingsEntryString,
+ QgsSettingsEntryInteger,
+ QgsSettingsEntryStringList,
)
from swiss_locator.core.filters.filter_type import FilterType
-pluginName = "swiss_locator_plugin"
+PLUGIN_NAME = "swiss_locator_plugin"
-class Settings(SettingManager):
- def __init__(self):
- SettingManager.__init__(self, pluginName)
+class Settings:
+ instance = None
- # lang of the service
- # possible values are de, fr, it , rm, en
- # if left empty or NULL, try to use locale and defaults to en
- self.add_setting(String("lang", Scope.Global, ""))
- self.add_setting(
- String(
- "crs",
- Scope.Global,
- "project",
- allowed_values=("2056", "21781", "project"),
- )
- )
- self.add_setting(Bool("show_map_tip", Scope.Global, False))
+ def __new__(cls):
+ if cls.instance is None:
+ cls.instance = super(Settings, cls).__new__(cls)
- self.add_setting(
- Enum(
- f"{FilterType.Location.value}_priority",
- Scope.Global,
- QgsLocatorFilter.Priority.Highest,
- )
- )
- self.add_setting(Integer(f"{FilterType.Location.value}_limit", Scope.Global, 8))
- self.add_setting(
- Enum(
- f"{FilterType.WMTS.value}_priority",
- Scope.Global,
- QgsLocatorFilter.Priority.Highest,
+ settings_node = QgsSettingsTree.createPluginTreeNode(pluginName=PLUGIN_NAME)
+
+ cls.lang = QgsSettingsEntryString("lang", settings_node, "lang")
+ cls.show_map_tip = QgsSettingsEntryBool(
+ "show_map_tip", settings_node, False
)
- )
- self.add_setting(Integer(f"{FilterType.WMTS.value}_limit", Scope.Global, 8))
- self.add_setting(
- Enum(
- f"{FilterType.VectorTiles.value}_priority",
- Scope.Global,
- QgsLocatorFilter.Priority.Medium,
+ cls.feature_search_restrict = QgsSettingsEntryBool(
+ "feature_search_restrict", settings_node, False
)
- )
- self.add_setting(Integer(f"{FilterType.VectorTiles.value}_limit", Scope.Global, 8))
- self.add_setting(
- Enum(
- f"{FilterType.Feature.value}_priority",
- Scope.Global,
- QgsLocatorFilter.Priority.Highest,
+ cls.layers_include_opendataswiss = QgsSettingsEntryBool(
+ "layers_include_opendataswiss", settings_node, True
)
- )
- self.add_setting(Integer(f"{FilterType.Feature.value}_limit", Scope.Global, 8))
- self.add_setting(
- Enum(
- f"{FilterType.Layers.value}_priority",
- Scope.Global,
- QgsLocatorFilter.Priority.High,
+ cls.feature_search_layers_list = QgsSettingsEntryStringList(
+ "feature_search_layers_list", settings_node, []
)
- )
- self.add_setting(Integer(f"{FilterType.Layers.value}_limit", Scope.Global, 5))
- self.add_setting(Bool("feature_search_restrict", Scope.Global, False))
- self.add_setting(Stringlist("feature_search_layers_list", Scope.Global, None))
+ me = metaEnumFromType(QgsLocatorFilter.Priority)
+
+ cls.filters = {
+ FilterType.Location.value: {
+ "priority": QgsSettingsEntryString(
+ f"{FilterType.Location.value}_priority",
+ settings_node,
+ me.valueToKey(QgsLocatorFilter.Priority.Highest),
+ ),
+ "limit": QgsSettingsEntryInteger(
+ f"{FilterType.Location.value}_limit", settings_node, 8
+ ),
+ },
+ FilterType.WMTS.value: {
+ "priority": QgsSettingsEntryString(
+ f"{FilterType.WMTS.value}_priority",
+ settings_node,
+ me.valueToKey(QgsLocatorFilter.Priority.Medium),
+ ),
+ "limit": QgsSettingsEntryInteger(
+ f"{FilterType.WMTS.value}_limit", settings_node, 8
+ ),
+ },
+ FilterType.VectorTiles.value: {
+ "priority": QgsSettingsEntryString(
+ f"{FilterType.VectorTiles.value}_priority",
+ settings_node,
+ me.valueToKey(QgsLocatorFilter.Priority.Highest),
+ ),
+ "limit": QgsSettingsEntryInteger(
+ f"{FilterType.VectorTiles.value}_limit", settings_node, 8
+ ),
+ },
+ FilterType.Feature.value: {
+ "priority": QgsSettingsEntryString(
+ f"{FilterType.Feature.value}_priority",
+ settings_node,
+ me.valueToKey(QgsLocatorFilter.Priority.High),
+ ),
+ "limit": QgsSettingsEntryInteger(
+ f"{FilterType.Feature.value}_limit", settings_node, 8
+ ),
+ },
+ FilterType.Layers.value: {
+ "priority": QgsSettingsEntryString(
+ f"{FilterType.Layers.value}_priority",
+ settings_node,
+ me.valueToKey(QgsLocatorFilter.Priority.High),
+ ),
+ "limit": QgsSettingsEntryInteger(
+ f"{FilterType.Layers.value}_limit", settings_node, 5
+ ),
+ },
+ }
- self.add_setting(Bool("layers_include_opendataswiss", Scope.Global, True))
+ return cls.instance
diff --git a/swiss_locator/gui/config_dialog.py b/swiss_locator/gui/config_dialog.py
index cab1315..8396452 100644
--- a/swiss_locator/gui/config_dialog.py
+++ b/swiss_locator/gui/config_dialog.py
@@ -25,48 +25,93 @@
from qgis.PyQt.QtCore import Qt, pyqtSlot
from qgis.PyQt.QtWidgets import QDialog, QTableWidgetItem, QAbstractItemView, QComboBox
from qgis.PyQt.uic import loadUiType
-from qgis.core import QgsLocatorFilter
+from qgis.core import QgsLocatorFilter, metaEnumFromType
+from qgis.gui import (
+ QgsSettingsEditorWidgetWrapper,
+ QgsSettingsStringComboBoxWrapper,
+ QgsSettingsBoolCheckBoxWrapper,
+)
-from ..qgissettingmanager.setting_dialog import SettingDialog, UpdateMode
from ..core.settings import Settings
from ..core.language import get_language
from ..map_geo_admin.layers import searchable_layers
from .qtwebkit_conf import with_qt_web_kit
+from ..core.filters.filter_type import FilterType
+from ..core.parameters import AVAILABLE_LANGUAGES
DialogUi, _ = loadUiType(os.path.join(os.path.dirname(__file__), "../ui/config.ui"))
-class ConfigDialog(QDialog, DialogUi, SettingDialog):
+class ConfigDialog(QDialog, DialogUi):
+ def accept(self):
+ for wrapper in self.wrappers:
+ wrapper.setSettingFromWidget()
+
+ layers_list = []
+ for r in range(self.feature_search_layers_list.rowCount()):
+ item = self.feature_search_layers_list.item(r, 0)
+ if item.checkState() == Qt.CheckState.Checked:
+ layers_list.append(item.text())
+ self.settings.feature_search_layers_list.setValue(layers_list)
+ super().accept()
+
def __init__(self, parent=None):
- settings = Settings()
+ self.settings = Settings()
QDialog.__init__(self, parent)
- SettingDialog.__init__(
- self, setting_manager=settings, mode=UpdateMode.DialogAccept
- )
self.setupUi(self)
+ self.wrappers: [QgsSettingsEditorWidgetWrapper] = []
self.lang.addItem(
self.tr("use the application locale, defaults to English"), ""
)
- from ..core.filters.filter_type import FilterType
- from ..core.parameters import AVAILABLE_LANGUAGES
-
for key, val in AVAILABLE_LANGUAGES.items():
self.lang.addItem(key, val)
+
+ self.wrappers.append(
+ QgsSettingsStringComboBoxWrapper(
+ self.lang,
+ self.settings.lang,
+ QgsSettingsStringComboBoxWrapper.Mode.Data,
+ )
+ )
+
+ self.wrappers.append(
+ QgsSettingsBoolCheckBoxWrapper(
+ self.layers_include_opendataswiss,
+ self.settings.layers_include_opendataswiss,
+ )
+ )
+ self.wrappers.append(
+ QgsSettingsBoolCheckBoxWrapper(
+ self.feature_search_restrict, self.settings.feature_search_restrict
+ )
+ )
+
+ me = metaEnumFromType(QgsLocatorFilter.Priority)
for filter_type in FilterType:
cb = self.findChild(QComboBox, "{}_priority".format(filter_type.value))
if cb is not None: # Some filters might not have a config dialog
- cb.addItem(self.tr("Highest"), QgsLocatorFilter.Priority.Highest)
- cb.addItem(self.tr("High"), QgsLocatorFilter.Priority.High)
- cb.addItem(self.tr("Medium"), QgsLocatorFilter.Priority.Medium)
- cb.addItem(self.tr("Low"), QgsLocatorFilter.Priority.Low)
- cb.addItem(self.tr("Lowest"), QgsLocatorFilter.Priority.Lowest)
-
- self.crs.addItem(
- self.tr("Use map CRS if possible, defaults to CH1903+"), "project"
- )
- self.crs.addItem("CH 1903+ (EPSG:2056)", "2056")
- self.crs.addItem("CH 1903 (EPSG:21781)", "21781")
+ cb.addItem(
+ self.tr("Highest"), me.valueToKey(QgsLocatorFilter.Priority.Highest)
+ )
+ cb.addItem(
+ self.tr("High"), me.valueToKey(QgsLocatorFilter.Priority.High)
+ )
+ cb.addItem(
+ self.tr("Medium"), me.valueToKey(QgsLocatorFilter.Priority.Medium)
+ )
+ cb.addItem(self.tr("Low"), me.valueToKey(QgsLocatorFilter.Priority.Low))
+ cb.addItem(
+ self.tr("Lowest"), me.valueToKey(QgsLocatorFilter.Priority.Lowest)
+ )
+
+ self.wrappers.append(
+ QgsSettingsStringComboBoxWrapper(
+ cb,
+ self.settings.filters[filter_type.value]["priority"],
+ QgsSettingsStringComboBoxWrapper.Mode.Data,
+ )
+ )
self.search_line_edit.textChanged.connect(self.filter_rows)
self.select_all_button.pressed.connect(self.select_all)
@@ -86,33 +131,45 @@ def __init__(self, parent=None):
QAbstractItemView.SelectionMode.SingleSelection
)
r = 0
+ layers_list = self.settings.feature_search_layers_list.value()
for layer, description in layers.items():
item = QTableWidgetItem(layer)
item.setFlags(Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsUserCheckable)
- # item.setCheckState(Qt.Unchecked)
+ checked = layer in layers_list
+ item.setCheckState(
+ Qt.CheckState.Checked if checked else Qt.CheckState.Unchecked
+ )
self.feature_search_layers_list.setItem(r, 0, item)
self.feature_search_layers_list.setItem(r, 1, QTableWidgetItem(description))
r += 1
self.feature_search_layers_list.horizontalHeader().setStretchLastSection(True)
self.feature_search_layers_list.resizeColumnsToContents()
- self.settings = settings
- self.init_widgets()
-
if not with_qt_web_kit():
- map_tip = self.setting_widget("show_map_tip")
- map_tip.widget.setEnabled(False)
- map_tip.widget.setToolTip(self.tr("You need to install QtWebKit to use map tips."))
+ self.show_map_tip.setEnabled(False)
+ self.show_map_tip.setToolTip(
+ self.tr("You need to install QtWebKit to use map tips.")
+ )
+ else:
+ self.wrappers.append(
+ QgsSettingsBoolCheckBoxWrapper(
+ self.show_map_tip, self.settings.show_map_tip
+ )
+ )
def select_all(self, select: bool = True):
for r in range(self.feature_search_layers_list.rowCount()):
item = self.feature_search_layers_list.item(r, 0)
- item.setCheckState(Qt.CheckState.Checked if select else Qt.CheckState.Unchecked)
+ item.setCheckState(
+ Qt.CheckState.Checked if select else Qt.CheckState.Unchecked
+ )
@pyqtSlot(str)
def filter_rows(self, text: str):
if text:
- items = self.feature_search_layers_list.findItems(text, Qt.MatchFlag.MatchContains)
+ items = self.feature_search_layers_list.findItems(
+ text, Qt.MatchFlag.MatchContains
+ )
print(text)
print(len(items))
shown_rows = []
diff --git a/swiss_locator/map_geo_admin/layers.py b/swiss_locator/map_geo_admin/layers.py
index df25e11..f1ea1ea 100644
--- a/swiss_locator/map_geo_admin/layers.py
+++ b/swiss_locator/map_geo_admin/layers.py
@@ -43,8 +43,8 @@ def searchable_layers(lang: str, restrict: bool = False) -> dict:
assert lang in AVAILABLE_LANGUAGES.values()
settings = Settings()
- restrict_enabled_by_user = settings.value("feature_search_restrict")
- restrict_layer_list = settings.value("feature_search_layers_list")
+ restrict_enabled_by_user = settings.feature_search_restrict.value()
+ restrict_layer_list = settings.feature_search_layers_list.value()
layers = {}
diff --git a/swiss_locator/metadata.txt b/swiss_locator/metadata.txt
index a42aaa7..e64469e 100644
--- a/swiss_locator/metadata.txt
+++ b/swiss_locator/metadata.txt
@@ -1,13 +1,16 @@
[general]
name=Swiss Locator
-qgisMinimumVersion=3.16
+qgisMinimumVersion=3.40
description=A locator filter for Swiss Geoportal (geo.admin.ch) and opendata.swiss resources
about=Search for locations, WMS layers of features in the whole Swiss Geoportal catalog as well as in opendata.swiss
version=dev
author=OPENGIS.ch
email=info@opengis.ch
+supportsQt6=yes
+
+
# Tags are comma separated with spaces allowed
tags=swiss, suisse, schweiz, locator, geoadmin, geoportal, opendata.swiss
diff --git a/swiss_locator/qgissettingmanager b/swiss_locator/qgissettingmanager
deleted file mode 160000
index 565a0bc..0000000
--- a/swiss_locator/qgissettingmanager
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 565a0bcd496ec3e42b3e39e06abb7cd24b8af48d
diff --git a/swiss_locator/swiss_locator_plugin.py b/swiss_locator/swiss_locator_plugin.py
index 6771926..1d365fd 100644
--- a/swiss_locator/swiss_locator_plugin.py
+++ b/swiss_locator/swiss_locator_plugin.py
@@ -20,7 +20,7 @@
import os
from qgis.PyQt.QtCore import QCoreApplication, QLocale, QSettings, QTranslator
from qgis.PyQt.QtWidgets import QWidget
-from qgis.core import Qgis, QgsApplication, QgsMessageLog, NULL
+from qgis.core import Qgis, QgsApplication, QgsMessageLog, NULL, QgsSettingsTree
from qgis.gui import QgisInterface, QgsMessageBarItem
from swiss_locator.core.filters.swiss_locator_filter_feature import (
@@ -36,12 +36,15 @@
from swiss_locator.core.filters.swiss_locator_filter_vector_tiles import (
SwissLocatorFilterVectorTiles,
)
+
try:
from swiss_locator.core.profiles.profile_generator import SwissProfileSource
except ImportError:
# Should fail only for QGIS < 3.26, where profiles weren't available
SwissProfileSource = None
+from swiss_locator.core.settings import PLUGIN_NAME
+
class SwissLocatorPlugin:
def __init__(self, iface: QgisInterface):
@@ -75,11 +78,13 @@ def initGui(self):
self.locator_filters[-1].message_emitted.connect(self.show_message)
if Qgis.QGIS_VERSION_INT >= 33700:
- QgsApplication.profileSourceRegistry().registerProfileSource(self.profile_source)
+ QgsApplication.profileSourceRegistry().registerProfileSource(
+ self.profile_source
+ )
QgsMessageLog.logMessage(
"Swiss profile source has been registered!",
"Swiss locator",
- Qgis.MessageLevel.Info
+ Qgis.MessageLevel.Info,
)
def unload(self):
@@ -88,13 +93,17 @@ def unload(self):
self.iface.deregisterLocatorFilter(locator_filter)
if Qgis.QGIS_VERSION_INT >= 33700:
- QgsApplication.profileSourceRegistry().unregisterProfileSource(self.profile_source)
+ QgsApplication.profileSourceRegistry().unregisterProfileSource(
+ self.profile_source
+ )
QgsMessageLog.logMessage(
"Swiss profile source has been unregistered!",
"Swiss locator",
- Qgis.MessageLevel.Info
+ Qgis.MessageLevel.Info,
)
+ QgsSettingsTree.unregisterPluginTreeNode(PLUGIN_NAME)
+
def show_message(
self, title: str, msg: str, level: Qgis.MessageLevel, widget: QWidget = None
):
diff --git a/swiss_locator/ui/config.ui b/swiss_locator/ui/config.ui
index db61569..e5b5e96 100644
--- a/swiss_locator/ui/config.ui
+++ b/swiss_locator/ui/config.ui
@@ -14,53 +14,20 @@
Swiss locator filter configuration
- -
-
-
- Language
-
-
-
- -
-
-
- Coordinates system
-
-
-
- -
-
-
-
- -
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
-
+
+
+ Show map tip on the map whenever possible
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
+
-
- 0
+ 1
@@ -127,8 +94,18 @@
- -
-
+
-
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
-
@@ -140,15 +117,18 @@
-
- -
-
+
-
+
+
+ -
+
- Qt::Vertical
+ Qt::Horizontal
- 20
- 40
+ 40
+ 20
@@ -273,7 +253,7 @@
true
-
+
true
@@ -328,13 +308,36 @@
- -
-
+
-
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+ -
+
- Show map tip on the map whenever possible
+ Language
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+