-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapplicationmodule.py
276 lines (256 loc) · 10.3 KB
/
applicationmodule.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# -*- coding: utf-8 -*-
from veriso.base.utils.utils import dynamic_import
from veriso.modules.applicationmodule_base import ApplicationModuleBase
from veriso.base.utils.utils import tr, get_default_db
from qgis.PyQt.QtWidgets import QMenu, QMenuBar
import os
class ApplicationModule(ApplicationModuleBase):
"""
This is the minimum required implementation to have your own module
"""
def __init__(self, veriso):
super(ApplicationModule, self).__init__(veriso)
self.module_dir = os.path.dirname(__file__)
def init_gui(self):
super(ApplicationModule, self).init_gui()
self.do_init_forest_defects_menu()
def do_init_forest_defects_menu(self):
tr_tag = self.module_name
forest_defects_menu_name = "VeriSO.Main.LoadForestDefectsMenu"
menubar = self.toolbar.findChild(
QMenuBar, 'VeriSO.Main.LoadDefectsMenuBar')
for action in menubar.actions():
if action.menu().objectName() == forest_defects_menu_name:
menubar.removeAction(action)
break
# Check whether the forest tables exists
try:
db = get_default_db()
for table_name in self.get_defects_table_names()["forest"].values():
query = db.exec_(
"""
SELECT ogc_fid FROM %s.%s;
""" % (self.settings.value("project/displayname"), table_name)
)
if query.record().indexOf("ogc_fid") == -1:
return
except:
return
# Specialized defects menu only for forest points
menu = QMenu(menubar)
menu.setObjectName(forest_defects_menu_name)
menu.setTitle(tr("Forest Defects", tr_tag))
# Add defects dock action from default defects menu
default_menu = menubar.findChild(QMenu, 'VeriSO.Main.LoadDefectsMenu')
for action in default_menu.actions():
if action.objectName() == "VeriSO.Main.LoadDefectsMenuBar.ShowDock":
menu.addAction(action)
break
self.add_defects_actions(menu, "forest")
menubar.addMenu(menu)
def do_load_defects(self, defects_type):
defects_module = 'veriso.modules.loaddefects_base'
defects_module = dynamic_import(defects_module)
tr_tag = self.module_name
d = defects_module.LoadDefectsBase(self.iface, tr_tag, defects_type)
if defects_type == "forest":
d.group = tr("Mängel Wald", tr_tag)
d.group += " (" + str(d.project_id) + ")"
fields = {
'ogc_fid': {'widget': 'TextEdit',
'readonly': True,
'config': {"Editable": False}},
'topic': {'widget': 'Enumeration',
'default': 'Bodenbedeckung',
'alias': 'Topic:',
'writable_only_by': ['agi', 'avor']},
'bezeichnun': {
'widget': 'Enumeration',
'alias': 'Bezeichnung:',
'writable_only_by': ['agi', 'avor']},
'abrechnung': {
'widget': 'Enumeration',
'default': 'PNF',
'alias': 'Abrechnung:',
'writable_only_by': ['agi', 'avor']},
'bem_avor': {
'widget': 'TextEdit',
'alias': 'Bemerkung AVOR:',
'config': {"IsMultiline": True},
'writable_only_by': ['agi', 'avor']},
'datum': {
'widget': 'Hidden',
'alias': tr('datum', tr_tag)
},
'bem_nfg': {
'widget': 'TextEdit',
'alias': 'Bemerkung NFG:',
'config': {"IsMultiline": True},
'writable_only_by': ['agi', 'geometer']},
'forstorgan': {
'widget': 'Enumeration',
'alias': 'Forstorgan:',
'writable_only_by': ['agi', 'forst']},
'bem_forst': {
'widget': 'TextEdit',
'alias': 'Bemerkung Forst:',
'config': {"IsMultiline": True},
'writable_only_by': ['agi', 'forst']},
'verifikati': {
'widget': 'Enumeration',
'alias': 'Verifikation:',
'writable_only_by': ['agi']},
'bem_verifi': {
'widget': 'TextEdit',
'alias': 'Bemerkung Verifikation:',
'config': {"IsMultiline": True},
'writable_only_by': ['agi']},
'erledigt': {
'widget': 'CheckBox',
'alias': 'Erledigt:',
'config': {
'CheckedState': 't',
'UncheckedState': 'f'},
'writable_only_by': ['agi']}
}
forest_fields = {
'ogc_fid': {'widget': 'TextEdit',
'readonly': True,
'config': {"Editable": False}},
'bezeichnung': {
'widget': 'Enumeration',
'alias': tr('Bezeichnung:', tr_tag),
'writable_only_by': ['agi', 'avor']},
'bem_av': {
'widget': 'TextEdit',
'alias': tr('Bemerkung AV:', tr_tag),
'config': {"IsMultiline": True},
'writable_only_by': ['agi', 'avor']},
'datum': {
'widget': 'Hidden',
'alias': tr('datum', tr_tag)
},
'bem_forst': {
'widget': 'TextEdit',
'alias': tr('Bemerkung Forst:', tr_tag),
'config': {"IsMultiline": True},
'writable_only_by': ['agi', 'forst']},
}
d.layers = {
'default': {
'point': {
"type": "postgres",
"title": tr("Mängelliste (Punkte)", tr_tag),
"featuretype": "t_maengel_punkt",
"geom": "the_geom",
"key": "ogc_fid",
"readonly": True,
"sql": "",
"group": d.group,
"style": "maengel/maengelliste_punkte.qml",
"fields": fields
},
'pointdesc': {
"type": "postgres",
"title": tr("Mängelliste (Punkte) Beschreibung", tr_tag),
"featuretype": "t_maengel_punkt",
"geom": "the_geom",
"key": "ogc_fid",
"readonly": True,
"sql": "",
"group": d.group,
"style": "maengel/maengelliste_punkte_beschreibung.qml",
"fields": fields
},
'line': {
"type": "postgres",
"title": tr("Mängelliste (Linien)", tr_tag),
"featuretype": "t_maengel_linie",
"geom": "the_geom",
"key": "ogc_fid",
"readonly": True,
"sql": "",
"group": d.group,
"style": "maengel/maengelliste_linien.qml",
"fields": fields
},
'linedesc': {
"type": "postgres",
"title": tr("Mängelliste (Linien) Beschreibung", tr_tag),
"featuretype": "t_maengel_linie",
"geom": "the_geom",
"key": "ogc_fid",
"readonly": True,
"sql": "",
"group": d.group,
"style": "maengel/maengelliste_linien_beschreibung.qml",
"fields": fields
},
'polygon': {
"type": "postgres",
"title": tr("Mängelliste (Polygone)", tr_tag),
"featuretype": "t_maengel_polygon",
"geom": "the_geom",
"key": "ogc_fid",
"readonly": True,
"sql": "",
"group": d.group,
"style": "maengel/maengelliste_polygone.qml",
"fields": fields
},
'polygondesc': {
"type": "postgres",
"title": tr("Mängelliste (Polygone) Beschreibung", tr_tag),
"featuretype": "t_maengel_polygon",
"geom": "the_geom",
"key": "ogc_fid",
"readonly": True,
"sql": "",
"group": d.group,
"style": "maengel/maengelliste_polygone_beschreibung.qml",
"fields": fields
}
},
'forest': {
'point': {
"type": "postgres",
"title": tr("Mängelliste (Punkte)", tr_tag),
"featuretype": "t_forest_maengel_punkt",
"geom": "the_geom",
"key": "ogc_fid",
"readonly": True,
"sql": "",
"group": d.group,
"style": "maengel/maengelliste_wald_punkte.qml",
"fields": forest_fields
},
'pointdesc': {
"type": "postgres",
"title": tr("Mängelliste (Punkte) Beschreibung", tr_tag),
"featuretype": "t_forest_maengel_punkt",
"geom": "the_geom",
"key": "ogc_fid",
"readonly": True,
"sql": "",
"group": d.group,
"style": "maengel/maengelliste_wald_punkte_beschreibung.qml",
"fields": forest_fields
}
}
}
return d.run()
def get_defects_table_names(self):
"""Return the table names of the defects tables
Returns:
dict: dict containing the default table names
"""
return {
'default': {
"point": "t_maengel_punkt",
"line": "t_maengel_linie",
"polygon": "t_maengel_polygon"
},
'forest': {
"point": "t_forest_maengel_punkt"
}
}