forked from WMS-Engineering/AusMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal_config.py
66 lines (54 loc) · 1.94 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
59
60
61
62
63
64
65
66
from PyQt4.QtCore import (
QFile,
QIODevice
)
import os.path
from qlr_file import QlrFile
class LocalConfig:
def __init__(self, settings):
self.settings = settings
self.reload()
def reload(self):
self.categories = []
if self.settings.value('use_custom_qlr_file'):
self.local_qlr_filename = self.settings.value('custom_qlr_file')
self.qlr_file = self.get_local_qlr_file()
if self.qlr_file:
self.categories = self.get_local_categories()
def get_local_qlr_file(self):
config = None
if self.settings.value('use_custom_qlr_file'):
local_file_exists = os.path.exists(self.local_qlr_filename)
if local_file_exists:
config = self.read_local_qlr()
if config:
return QlrFile(config)
else:
return None
def read_local_qlr(self):
f = QFile(self.local_qlr_filename)
f.open(QIODevice.ReadOnly)
return f.readAll()
def get_local_categories(self):
local_categories = []
groups_with_layers = self.qlr_file.get_groups_with_layers()
for group in groups_with_layers:
local_category = {
'name': group['name'],
'selectables': []
}
for layer in group['layers']:
local_category['selectables'].append({
'type': 'layer',
'source': 'local',
'name': layer['name'],
'id': layer['id']
}
)
if len(local_category['selectables']) > 0:
local_categories.append(local_category)
return local_categories
def get_categories(self):
return self.categories
def get_maplayer_node(self, id):
return self.qlr_file.get_maplayer_node(id)