5
5
6
6
from qgis .gui import QgsDockWidget
7
7
from qgis .PyQt import uic
8
- from qgis .PyQt .QtCore import QStringListModel
9
8
from qgis .utils import iface
10
9
11
10
from arho_feature_template .core .lambda_service import LambdaService
12
11
from arho_feature_template .utils .misc_utils import get_active_plan_id
13
12
14
13
if TYPE_CHECKING :
15
- from qgis .PyQt .QtWidgets import QListView , QProgressBar
14
+ from qgis .PyQt .QtWidgets import QProgressBar , QPushButton
15
+
16
+ from arho_feature_template .gui .validation_tree_view import ValidationTreeView
16
17
17
18
ui_path = resources .files (__package__ ) / "validation_dock.ui"
18
19
DockClass , _ = uic .loadUiType (ui_path )
19
20
20
21
21
22
class ValidationDock (QgsDockWidget , DockClass ): # type: ignore
22
- error_list_view : QListView
23
23
progress_bar : QProgressBar
24
+ validation_result_tree_view : ValidationTreeView
25
+ validate_button : QPushButton
24
26
25
- def __init__ (self ):
26
- super ().__init__ ()
27
+ def __init__ (self , parent = None ):
28
+ super ().__init__ (parent )
27
29
self .setupUi (self )
30
+
28
31
self .lambda_service = LambdaService ()
29
32
self .lambda_service .validation_received .connect (self .list_validation_errors )
30
- self .error_list_model = QStringListModel ()
31
- self .error_list_view .setModel (self .error_list_model )
32
33
self .validate_button .clicked .connect (self .validate )
33
34
34
35
def validate (self ):
35
36
"""Handles the button press to trigger the validation process."""
37
+
38
+ # Clear the existing errors from the list view
39
+ self .validation_result_tree_view .clear_errors ()
40
+
36
41
active_plan_id = get_active_plan_id ()
37
42
if not active_plan_id :
38
43
iface .messageBar ().pushMessage ("Virhe" , "Ei aktiivista kaavaa." , level = 3 )
@@ -49,38 +54,33 @@ def list_validation_errors(self, validation_json):
49
54
if not validation_json :
50
55
iface .messageBar ().pushMessage ("Virhe" , "Validaatio json puuttuu." , level = 1 )
51
56
return
52
- # Clear the existing errors from the list view
53
- self .error_list_model .setStringList ([])
54
-
55
- new_errors = []
56
57
57
58
if not validation_json :
58
59
# If no errors or warnings, display a message and exit
59
60
iface .messageBar ().pushMessage ("Virhe" , "Ei virheitä havaittu." , level = 1 )
60
61
return
61
62
62
63
for error_data in validation_json .values ():
63
- if isinstance (error_data , dict ):
64
- # Get the errors for this plan
65
- errors = error_data .get ("errors" , [])
66
- for error in errors :
67
- rule_id = error .get ("ruleId" , "Tuntematon sääntö" )
68
- message = error .get ("message" , "Ei viestiä" )
69
- instance = error .get ("instance" , "Tuntematon instance" )
70
- error_message = f"Validointivirhe - Sääntö: { rule_id } , Viesti: { message } , Instance: { instance } "
71
- new_errors .append (error_message )
72
-
73
- # Get any warnings for this plan using list comprehension
74
- warnings = error_data .get ("warnings" , [])
75
- new_errors .extend ([f"Varoitus: { warning } " for warning in warnings ])
76
-
77
- # If no errors or warnings, display a message
78
- if not new_errors :
79
- new_errors .append ("Kaava on validi. Ei virheitä tai varoituksia havaittu." )
80
- return
64
+ if not isinstance (error_data , dict ):
65
+ continue
66
+ errors = error_data .get ("errors" , [])
67
+ for error in errors :
68
+ self .validation_result_tree_view .add_error (
69
+ error .get ("ruleId" , "" ),
70
+ error .get ("instance" , "" ),
71
+ error .get ("message" , "" ),
72
+ )
73
+
74
+ warnings = error_data .get ("warnings" , [])
75
+ for warning in warnings :
76
+ self .validation_result_tree_view .add_warning (
77
+ warning .get ("ruleId" , "" ),
78
+ warning .get ("instance" , "" ),
79
+ warning .get ("message" , "" ),
80
+ )
81
81
82
- # Update the list view with the new errors and warnings
83
- self .error_list_model .setStringList (new_errors )
84
82
# Hide progress bar and re-enable the button
85
83
self .progress_bar .setVisible (False )
86
84
self .validate_button .setEnabled (True )
85
+ self .validation_result_tree_view .expandAll ()
86
+ self .validation_result_tree_view .resizeColumnToContents (0 )
0 commit comments