-
Notifications
You must be signed in to change notification settings - Fork 5
/
local_config.py
58 lines (48 loc) · 1.65 KB
/
local_config.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
from PyQt5.QtCore import QFile, QIODevice
from .qlr_file import QlrFile
class LocalConfig:
"""
Handles the layers in the user's custom QLR file if it is provided
in the plugin settings
"""
def __init__(self, settings):
self.settings = settings
self.qlr_file = None
self.categories = []
self.load()
def load(self):
self.local_qlr_file_path = self.settings.value("custom_qlr_file")
if self.local_qlr_file_path and os.path.exists(
self.local_qlr_file_path
):
self.qlr_file = self._load_qlr_file()
self.categories = (
self._parse_local_categories() if self.qlr_file else []
)
def _load_qlr_file(self):
"""Read and load the QLR file from the local path."""
f = QFile(self.local_qlr_file_path)
f.open(QIODevice.ReadOnly)
return QlrFile(f.readAll())
def _parse_local_categories(self):
"""Parse categories and layers from the loaded QLR file."""
return [
{
"name": group["name"],
"selectables": [
{
"type": "layer",
"source": "local",
"name": layer["name"],
"id": layer["id"],
}
for layer in group["layers"]
],
}
for group in self.qlr_file.get_groups_with_layers()
]
def get_categories(self):
return self.categories
def get_maplayer_node(self, layer_id):
return self.qlr_file.get_maplayer_node(layer_id)