From 9935acab89554d920e4fb1d50b43a9ba47a9a7cc Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 7 Oct 2024 14:29:15 +0200 Subject: [PATCH] raise QGIS minimum to 3.34, config available for 3.40+ --- .../core/filters/swiss_locator_filter.py | 6 +- swiss_locator/core/settings.py | 98 ++++++++++--------- swiss_locator/gui/config_dialog.py | 87 ++++++++++++---- swiss_locator/metadata.txt | 2 +- swiss_locator/ui/config.ui | 74 ++++++-------- 5 files changed, 161 insertions(+), 106 deletions(-) diff --git a/swiss_locator/core/filters/swiss_locator_filter.py b/swiss_locator/core/filters/swiss_locator_filter.py index eed53de..440b45f 100644 --- a/swiss_locator/core/filters/swiss_locator_filter.py +++ b/swiss_locator/core/filters/swiss_locator_filter.py @@ -59,7 +59,9 @@ ) from swiss_locator.core.settings import Settings from swiss_locator.core.language import get_language -from swiss_locator.gui.config_dialog import ConfigDialog + +if Qgis.QGIS_VERSION_INT >= 33900: + 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 from swiss_locator.utils.utils import url_with_param @@ -185,7 +187,7 @@ def clearPreviousResults(self): self.current_timer = None def hasConfigWidget(self): - return True + return Qgis.QGIS_VERSION_INT >= 33900 def openConfigWidget(self, parent=None): dlg = ConfigDialog(parent) diff --git a/swiss_locator/core/settings.py b/swiss_locator/core/settings.py index 3443076..c4db3fa 100644 --- a/swiss_locator/core/settings.py +++ b/swiss_locator/core/settings.py @@ -25,11 +25,11 @@ # --------------------------------------------------------------------- from qgis.core import ( + metaEnumFromType, QgsLocatorFilter, QgsSettingsTree, QgsSettingsEntryBool, QgsSettingsEntryString, - QgsSettingsEntryEnumFlag, QgsSettingsEntryInteger, QgsSettingsEntryStringList, ) @@ -61,49 +61,59 @@ def __new__(cls): "feature_search_layers_list", settings_node, [] ) - cls.filter_location_priority = QgsSettingsEntryEnumFlag( - f"{FilterType.Location.value}_priority", - settings_node, - QgsLocatorFilter.Priority.Highest, - ) - cls.filter_location_limit = QgsSettingsEntryInteger( - f"{FilterType.Location.value}_limit", settings_node, 8 - ) + me = metaEnumFromType(QgsLocatorFilter.Priority) - cls.filter_wmts_priority = QgsSettingsEntryEnumFlag( - f"{FilterType.WMTS.value}_priority", - settings_node, - QgsLocatorFilter.Priority.Medium, - ) - cls.filter_wmts_limit = QgsSettingsEntryInteger( - f"{FilterType.WMTS.value}_limit", settings_node, 8 - ) - - cls.filter_vt_priority = QgsSettingsEntryEnumFlag( - f"{FilterType.VectorTiles.value}_priority", - settings_node, - QgsLocatorFilter.Priority.Highest, - ) - cls.filter_vt_limit = QgsSettingsEntryInteger( - f"{FilterType.VectorTiles.value}_limit", settings_node, 8 - ) - - cls.filter_feature_priority = QgsSettingsEntryEnumFlag( - f"{FilterType.Feature.value}_priority", - settings_node, - QgsLocatorFilter.Priority.High, - ) - cls.filter_feature_limit = QgsSettingsEntryInteger( - f"{FilterType.Feature.value}_limit", settings_node, 8 - ) - - cls.filter_layers_priority = QgsSettingsEntryEnumFlag( - f"{FilterType.Layers.value}_priority", - settings_node, - QgsLocatorFilter.Priority.High, - ) - cls.filter_layers_limit = QgsSettingsEntryInteger( - f"{FilterType.Layers.value}_limit", settings_node, 5 - ) + 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 + ), + }, + } return cls.instance diff --git a/swiss_locator/gui/config_dialog.py b/swiss_locator/gui/config_dialog.py index 4cb84ac..8396452 100644 --- a/swiss_locator/gui/config_dialog.py +++ b/swiss_locator/gui/config_dialog.py @@ -25,8 +25,12 @@ 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.gui import QgsSettingsStringComboBoxWrapper +from qgis.core import QgsLocatorFilter, metaEnumFromType +from qgis.gui import ( + QgsSettingsEditorWidgetWrapper, + QgsSettingsStringComboBoxWrapper, + QgsSettingsBoolCheckBoxWrapper, +) from ..core.settings import Settings from ..core.language import get_language @@ -39,11 +43,23 @@ 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): self.settings = Settings() QDialog.__init__(self, parent) - self.setupUi(self) + self.wrappers: [QgsSettingsEditorWidgetWrapper] = [] self.lang.addItem( self.tr("use the application locale, defaults to English"), "" @@ -51,24 +67,51 @@ def __init__(self, parent=None): for key, val in AVAILABLE_LANGUAGES.items(): self.lang.addItem(key, val) - self.lang_wrapper = QgsSettingsStringComboBoxWrapper( - self.lang, self.settings.lang + 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) @@ -88,10 +131,14 @@ 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 @@ -103,6 +150,12 @@ def __init__(self, parent=None): 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()): diff --git a/swiss_locator/metadata.txt b/swiss_locator/metadata.txt index eef59cb..72a612b 100644 --- a/swiss_locator/metadata.txt +++ b/swiss_locator/metadata.txt @@ -1,7 +1,7 @@ [general] name=Swiss Locator -qgisMinimumVersion=3.16 +qgisMinimumVersion=3.34 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 diff --git a/swiss_locator/ui/config.ui b/swiss_locator/ui/config.ui index db61569..b901441 100644 --- a/swiss_locator/ui/config.ui +++ b/swiss_locator/ui/config.ui @@ -14,50 +14,17 @@ 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 @@ -273,7 +240,7 @@ true - + true @@ -328,13 +295,36 @@ - - + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + - Show map tip on the map whenever possible + Language + + + + Qt::Horizontal + + + + 40 + 20 + + + +