Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings follow-up #104

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading