-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlayer_locator_filter.py
36 lines (28 loc) · 1.19 KB
/
layer_locator_filter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from qgis.core import QgsLocatorFilter, QgsLocatorResult
from .constants import PLUGIN_NAME
class LayerLocatorFilter(QgsLocatorFilter):
def __init__(self, iface, layer_action_map):
super().__init__()
self.iface = iface
self.layer_action_map = layer_action_map
def name(self):
return "ausmap_layer_locator_filter"
def displayName(self):
return f"{PLUGIN_NAME} Layers"
def clone(self):
return LayerLocatorFilter(self.iface, self.layer_action_map)
def fetchResults(self, search_string, context, feedback):
search_string = search_string.lower()
for layer_name in self.layer_action_map.keys():
if search_string in layer_name.lower():
result = QgsLocatorResult()
result.filter = self
result.displayString = layer_name
result.userData = layer_name
self.resultFetched.emit(result)
def triggerResult(self, result):
layer_name = result.userData
if layer_name in self.layer_action_map:
# Get the QAction for the selected layer
action = self.layer_action_map[layer_name]
action.trigger()