diff --git a/swiss_locator/core/filters/swiss_locator_filter.py b/swiss_locator/core/filters/swiss_locator_filter.py index 54485f6..ade4e3c 100644 --- a/swiss_locator/core/filters/swiss_locator_filter.py +++ b/swiss_locator/core/filters/swiss_locator_filter.py @@ -31,7 +31,6 @@ from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply, QNetworkAccessManager from qgis.core import ( - metaEnumFromType, Qgis, QgsLocatorFilter, QgsLocatorResult, @@ -121,7 +120,6 @@ 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( @@ -163,13 +161,7 @@ def name(self): return self.__class__.__name__ def priority(self): - (value, ok) = self.me.keyToValue( - self.settings.filters[self.type.value]["priority"].value() - ) - if ok: - return QgsLocatorFilter.Priority(value) - else: - return QgsLocatorFilter.Priority.Medium + return self.settings.filters[self.type.value]["priority"].value() def displayName(self): # this should be re-implemented diff --git a/swiss_locator/core/settings.py b/swiss_locator/core/settings.py index c3cd400..e8a2252 100644 --- a/swiss_locator/core/settings.py +++ b/swiss_locator/core/settings.py @@ -25,10 +25,10 @@ # --------------------------------------------------------------------- from qgis.core import ( - metaEnumFromType, QgsLocatorFilter, QgsSettingsTree, QgsSettingsEntryBool, + QgsSettingsEntryEnumFlag, QgsSettingsEntryString, QgsSettingsEntryInteger, QgsSettingsEntryStringList, @@ -61,59 +61,58 @@ def __new__(cls): "feature_search_layers_list", settings_node, [] ) - me = metaEnumFromType(QgsLocatorFilter.Priority) - - cls.filters = { + filters = { FilterType.Location.value: { - "priority": QgsSettingsEntryString( + "priority": QgsSettingsEntryEnumFlag( f"{FilterType.Location.value}_priority", settings_node, - me.valueToKey(QgsLocatorFilter.Priority.Highest), + QgsLocatorFilter.Priority.Highest, ), "limit": QgsSettingsEntryInteger( f"{FilterType.Location.value}_limit", settings_node, 8 ), }, FilterType.WMTS.value: { - "priority": QgsSettingsEntryString( + "priority": QgsSettingsEntryEnumFlag( f"{FilterType.WMTS.value}_priority", settings_node, - me.valueToKey(QgsLocatorFilter.Priority.Medium), + QgsLocatorFilter.Priority.Medium, ), "limit": QgsSettingsEntryInteger( f"{FilterType.WMTS.value}_limit", settings_node, 8 ), }, FilterType.VectorTiles.value: { - "priority": QgsSettingsEntryString( + "priority": QgsSettingsEntryEnumFlag( f"{FilterType.VectorTiles.value}_priority", settings_node, - me.valueToKey(QgsLocatorFilter.Priority.Highest), + QgsLocatorFilter.Priority.Highest, ), "limit": QgsSettingsEntryInteger( f"{FilterType.VectorTiles.value}_limit", settings_node, 8 ), }, FilterType.Feature.value: { - "priority": QgsSettingsEntryString( + "priority": QgsSettingsEntryEnumFlag( f"{FilterType.Feature.value}_priority", settings_node, - me.valueToKey(QgsLocatorFilter.Priority.High), + QgsLocatorFilter.Priority.High, ), "limit": QgsSettingsEntryInteger( f"{FilterType.Feature.value}_limit", settings_node, 8 ), }, FilterType.Layers.value: { - "priority": QgsSettingsEntryString( + "priority": QgsSettingsEntryEnumFlag( f"{FilterType.Layers.value}_priority", settings_node, - me.valueToKey(QgsLocatorFilter.Priority.High), + QgsLocatorFilter.Priority.High, ), "limit": QgsSettingsEntryInteger( f"{FilterType.Layers.value}_limit", settings_node, 5 ), }, } + cls.filters = filters return cls.instance diff --git a/swiss_locator/gui/config_dialog.py b/swiss_locator/gui/config_dialog.py index 8396452..dc1c8df 100644 --- a/swiss_locator/gui/config_dialog.py +++ b/swiss_locator/gui/config_dialog.py @@ -25,11 +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, metaEnumFromType +from qgis.core import QgsLocatorFilter from qgis.gui import ( - QgsSettingsEditorWidgetWrapper, QgsSettingsStringComboBoxWrapper, QgsSettingsBoolCheckBoxWrapper, + QgsSettingsEnumEditorWidgetWrapper, + QgsSettingsEditorWidgetWrapper, ) from ..core.settings import Settings @@ -87,31 +88,23 @@ def __init__(self, parent=None): ) ) - me = metaEnumFromType(QgsLocatorFilter.Priority) + display_strings = { + QgsLocatorFilter.Priority.Highest: self.tr("Highest"), + QgsLocatorFilter.Priority.High: self.tr("High"), + QgsLocatorFilter.Priority.Medium: self.tr("Medium"), + QgsLocatorFilter.Priority.Low: self.tr("Low"), + QgsLocatorFilter.Priority.Lowest: self.tr("Lowest"), + } + 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"), 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, - ) + ew = QgsSettingsEnumEditorWidgetWrapper( + editor=cb, + setting=self.settings.filters[filter_type.value]["priority"], + displayStrings=display_strings, ) + self.wrappers.append(ew) self.search_line_edit.textChanged.connect(self.filter_rows) self.select_all_button.pressed.connect(self.select_all)