Skip to content

Commit

Permalink
raise QGIS minimum to 3.34, config available for 3.40+
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Oct 7, 2024
1 parent 3cc814c commit 9935aca
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 106 deletions.
6 changes: 4 additions & 2 deletions swiss_locator/core/filters/swiss_locator_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
98 changes: 54 additions & 44 deletions swiss_locator/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
# ---------------------------------------------------------------------

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


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"), ""
)
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)
Expand 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
Expand All @@ -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()):
Expand Down
2 changes: 1 addition & 1 deletion swiss_locator/metadata.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
74 changes: 32 additions & 42 deletions swiss_locator/ui/config.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,17 @@
<string>Swiss locator filter configuration</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Language</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Coordinates system</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="crs"/>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="lang"/>
</item>
<item row="10" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="show_map_tip">
<property name="text">
<string>Show map tip on the map whenever possible</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="3">
<item row="3" column="0" colspan="3">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
Expand Down Expand Up @@ -273,7 +240,7 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="showSearchIcon" stdset="0">
<property name="showSearchIcon">
<bool>true</bool>
</property>
<property name="qgisRelation" stdset="0">
Expand Down Expand Up @@ -328,13 +295,36 @@
</widget>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="show_map_tip">
<item row="9" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Show map tip on the map whenever possible</string>
<string>Language</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
Expand Down

0 comments on commit 9935aca

Please sign in to comment.