Skip to content

Commit

Permalink
limit number of results (configurable)
Browse files Browse the repository at this point in the history
priority is also configurable
  • Loading branch information
3nids committed Jun 27, 2018
1 parent dfcd6be commit 0445b94
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 64 deletions.
11 changes: 10 additions & 1 deletion swiss_locator/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#
# ---------------------------------------------------------------------

from swiss_locator.qgissettingmanager import SettingManager, Scope, Bool, String, Stringlist

from qgis.core import QgsLocatorFilter
from swiss_locator.qgissettingmanager import SettingManager, Scope, Bool, String, Stringlist, Integer, Enum

pluginName = "swiss_locator_plugin"

Expand All @@ -40,6 +42,13 @@ def __init__(self):
self.add_setting(String("crs", Scope.Global, 'project', value_list=('2056', '21781', 'project')))
self.add_setting(Bool("show_map_tip", Scope.Global, True))

self.add_setting(Enum('locations_priority', Scope.Global, QgsLocatorFilter.Highest))
self.add_setting(Integer('locations_limit', Scope.Global, 8))
self.add_setting(Enum('featuresearch_priority', Scope.Global, QgsLocatorFilter.Medium))
self.add_setting(Integer('featuresearch_limit', Scope.Global, 8))
self.add_setting(Enum('layers_priority', Scope.Global, QgsLocatorFilter.High))
self.add_setting(Integer('layers_limit', Scope.Global, 5))

self.add_setting(Bool("feature_search_restrict", Scope.Global, False))
self.add_setting(Stringlist("feature_search_layers_list", Scope.Global, None))

Expand Down
17 changes: 11 additions & 6 deletions swiss_locator/gui/config_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@

import os
from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtWidgets import QDialog, QTableWidgetItem, QAbstractItemView
from PyQt5.QtWidgets import QDialog, QTableWidgetItem, QAbstractItemView, QComboBox
from qgis.PyQt.uic import loadUiType
from qgis.core import QgsLocatorFilter

from ..qgissettingmanager.setting_dialog import SettingDialog, UpdateMode
from ..core.settings import Settings
Expand All @@ -42,18 +43,22 @@ def __init__(self, parent=None):
self.setupUi(self)

self.lang.addItem(self.tr('use the application locale, defaults to English'), '')
from ..swiss_locator_filter import AVAILABLE_LANGUAGES
from ..swiss_locator_filter import AVAILABLE_LANGUAGES, FilterType
for key, val in AVAILABLE_LANGUAGES.items():
self.lang.addItem(key, val)
for filter_type in FilterType:
cb = self.findChild(QComboBox, '{}_priority'.format(filter_type.value))
cb.addItem(self.tr('Highest'), QgsLocatorFilter.Highest)
cb.addItem(self.tr('High'), QgsLocatorFilter.High)
cb.addItem(self.tr('Medium'), QgsLocatorFilter.Medium)
cb.addItem(self.tr('Low'), QgsLocatorFilter.Low)
cb.addItem(self.tr('Lowest'), QgsLocatorFilter.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')

self.search_line_edit.textChanged.connect(self.filter_rows)
self.feature_search_restrict.toggled.connect(self.feature_search_layers_list.setEnabled)
self.feature_search_restrict.toggled.connect(self.search_line_edit.setEnabled)
self.feature_search_restrict.toggled.connect(self.select_all_button.setEnabled)
self.feature_search_restrict.toggled.connect(self.unselect_all_button.setEnabled)
self.select_all_button.pressed.connect(self.select_all)
self.unselect_all_button.pressed.connect(lambda: self.select_all(False))

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.0
qgisMinimumVersion=3.2
description=A locator filter for Swiss Geoportal (geo.admin.ch)
about=Search for locations, WMS layers of features in the whole Swiss Geoportal catalog
version=dev
Expand Down
2 changes: 1 addition & 1 deletion swiss_locator/qgissettingmanager
28 changes: 7 additions & 21 deletions swiss_locator/swiss_locator_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from PyQt5.QtWidgets import QLabel, QWidget
from PyQt5.QtCore import QUrl, QUrlQuery, pyqtSignal, QEventLoop

from qgis.core import Qgis, QgsMessageLog, QgsLocatorFilter, QgsLocatorResult, QgsRectangle, QgsApplication, \
from qgis.core import Qgis, QgsLocatorFilter, QgsLocatorResult, QgsRectangle, QgsApplication, \
QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsProject, QgsGeometry, QgsWkbTypes, QgsPointXY, \
QgsLocatorContext, QgsFeedback, QgsRasterLayer
from qgis.gui import QgsRubberBand, QgisInterface
Expand Down Expand Up @@ -157,14 +157,7 @@ def clone(self):
return SwissLocatorFilter(self.type, crs=self.crs)

def priority(self):
if self.type is FilterType.Location:
return QgsLocatorFilter.High
elif self.type is FilterType.WMS:
return QgsLocatorFilter.Highest
elif self.type is FilterType.Feature:
return QgsLocatorFilter.Medium
else:
raise NameError('Filter type is not valid.')
return self.settings.value('{type}_priority'.format(type=self.type.value))

def displayName(self):
if self.type is FilterType.Location:
Expand Down Expand Up @@ -290,7 +283,7 @@ def fetchResults(self, search: str, context: QgsLocatorContext, feedback: QgsFee
'returnGeometry': 'true',
'lang': self.lang,
'sr': self.crs,

'limit': str(self.settings.value('{type}_limit'.format(type=self.type.value)))
# bbox Must be provided if the searchText is not.
# A comma separated list of 4 coordinates representing
# the bounding box on which features should be filtered (SRID: 21781).
Expand Down Expand Up @@ -411,11 +404,8 @@ def handle_response(self, response):
self.info(self.tr('Layer {} is not in the list of searchable layers.'
' Please report issue.'.format(layer)), Qgis.Warning)
layer_display = layer
if Qgis.QGIS_VERSION_INT >= 30100:
result.group = layer_display
result.displayString = loc['attrs']['detail']
else:
result.displayString = '{}, {}'.format(layer_display, loc['attrs']['detail'])
result.group = layer_display
result.displayString = loc['attrs']['detail']
result.userData = FeatureResult(point=point,
layer=layer,
feature_id=loc['attrs']['feature_id'])
Expand All @@ -438,8 +428,7 @@ def handle_response(self, response):
# result.description = loc['attrs']['detail']
# if 'featureId' in loc['attrs']:
# result.description = loc['attrs']['featureId']
if Qgis.QGIS_VERSION_INT >= 30100:
result.group = group_name
result.group = group_name
result.userData = LocationResult(point=QgsPointXY(loc['attrs']['y'], loc['attrs']['x']),
bbox=self.box2geometry(loc['attrs']['geom_st_box2d']),
layer=group_layer,
Expand Down Expand Up @@ -607,10 +596,7 @@ def parse_map_tip_response(self, response, point):
self.map_tip.closed.connect(self.clearPreviousResults)

def info(self, msg="", level=Qgis.Info, emit_message: bool = False):
if Qgis.QGIS_VERSION_INT >= 30100:
self.logMessage(str(msg), level)
else:
QgsMessageLog.logMessage('{} {}'.format(self.name(), str(msg)), 'Locator bar', level)
self.logMessage(str(msg), level)
if emit_message:
self.message_emitted.emit(msg, level)

Expand Down
Loading

0 comments on commit 0445b94

Please sign in to comment.