Skip to content

Commit

Permalink
settings follow-up (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored Oct 10, 2024
1 parent 8a77ca3 commit 153c206
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 46 deletions.
10 changes: 1 addition & 9 deletions swiss_locator/core/filters/swiss_locator_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply, QNetworkAccessManager

from qgis.core import (
metaEnumFromType,
Qgis,
QgsLocatorFilter,
QgsLocatorResult,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
27 changes: 13 additions & 14 deletions swiss_locator/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
# ---------------------------------------------------------------------

from qgis.core import (
metaEnumFromType,
QgsLocatorFilter,
QgsSettingsTree,
QgsSettingsEntryBool,
QgsSettingsEntryEnumFlag,
QgsSettingsEntryString,
QgsSettingsEntryInteger,
QgsSettingsEntryStringList,
Expand Down Expand Up @@ -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
39 changes: 16 additions & 23 deletions swiss_locator/gui/config_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 153c206

Please sign in to comment.