55from PyQt5 .QtWidgets import QMessageBox , QWidget
66from qgis .PyQt import uic
77
8+ from ...main .helpers import ColumnMatcher , get_layer_names
9+
810
911class ThicknessCalculatorWidget (QWidget ):
1012 """Widget for configuring and running the thickness calculator.
@@ -55,13 +57,50 @@ def __init__(self, parent=None, data_manager=None):
5557 self .geologyLayerComboBox .layerChanged .connect (self ._on_geology_layer_changed )
5658 self .structureLayerComboBox .layerChanged .connect (self ._on_structure_layer_changed )
5759 self .runButton .clicked .connect (self ._run_calculator )
58-
60+ self . _guess_layers ()
5961 # Set up field combo boxes
6062 self ._setup_field_combo_boxes ()
6163
6264 # Initial state update
6365 self ._on_calculator_type_changed ()
6466
67+ def _guess_layers (self ):
68+ """Attempt to auto-select layers based on common naming conventions."""
69+ if not self .data_manager :
70+ return
71+
72+ # Attempt to find geology layer
73+ geology_layer_names = get_layer_names (self .geologyLayerComboBox )
74+ geology_matcher = ColumnMatcher (geology_layer_names )
75+ geology_layer_match = geology_matcher .find_match ('GEOLOGY' )
76+ if geology_layer_match :
77+ geology_layer = self .data_manager .find_layer_by_name (geology_layer_match )
78+ self .geologyLayerComboBox .setLayer (geology_layer )
79+
80+ # Attempt to find basal contacts layer
81+ basal_contacts_names = get_layer_names (self .basalContactsComboBox )
82+ basal_matcher = ColumnMatcher (basal_contacts_names )
83+ basal_layer_match = basal_matcher .find_match ('BASAL_CONTACTS' )
84+ if basal_layer_match :
85+ basal_layer = self .data_manager .find_layer_by_name (basal_layer_match )
86+ self .basalContactsComboBox .setLayer (basal_layer )
87+
88+ # Attempt to find sampled contacts layer
89+ sampled_contacts_names = get_layer_names (self .sampledContactsComboBox )
90+ sampled_matcher = ColumnMatcher (sampled_contacts_names )
91+ sampled_layer_match = sampled_matcher .find_match ('SAMPLED_CONTACTS' )
92+ if sampled_layer_match :
93+ sampled_layer = self .data_manager .find_layer_by_name (sampled_layer_match )
94+ self .sampledContactsComboBox .setLayer (sampled_layer )
95+
96+ # Attempt to find structure layer
97+ structure_layer_names = get_layer_names (self .structureLayerComboBox )
98+ structure_matcher = ColumnMatcher (structure_layer_names )
99+ structure_layer_match = structure_matcher .find_match ('STRUCTURE' )
100+ if structure_layer_match :
101+ structure_layer = self .data_manager .find_layer_by_name (structure_layer_match )
102+ self .structureLayerComboBox .setLayer (structure_layer )
103+
65104 def _setup_field_combo_boxes (self ):
66105 """Set up field combo boxes to link to their respective layers."""
67106 self .unitNameFieldComboBox .setLayer (self .geologyLayerComboBox .currentLayer ())
@@ -70,15 +109,38 @@ def _setup_field_combo_boxes(self):
70109
71110 def _on_geology_layer_changed (self ):
72111 """Update field combo boxes when geology layer changes."""
112+
73113 layer = self .geologyLayerComboBox .currentLayer ()
74114 self .unitNameFieldComboBox .setLayer (layer )
75115
116+ # Auto-detect appropriate fields
117+ if layer :
118+ fields = [field .name () for field in layer .fields ()]
119+ matcher = ColumnMatcher (fields )
120+
121+ # Auto-select UNITNAME field
122+ if unit_match := matcher .find_match ('UNITNAME' ):
123+ self .unitNameFieldComboBox .setField (unit_match )
124+
76125 def _on_structure_layer_changed (self ):
77126 """Update field combo boxes when structure layer changes."""
127+
78128 layer = self .structureLayerComboBox .currentLayer ()
79129 self .dipFieldComboBox .setLayer (layer )
80130 self .dipDirFieldComboBox .setLayer (layer )
81131
132+ # Auto-detect appropriate fields
133+ if layer :
134+ fields = [field .name () for field in layer .fields ()]
135+ matcher = ColumnMatcher (fields )
136+
137+ # Auto-select DIP and DIPDIR fields
138+ if dip_match := matcher .find_match ('DIP' ):
139+ self .dipFieldComboBox .setField (dip_match )
140+
141+ if dipdir_match := matcher .find_match ('DIPDIR' ):
142+ self .dipDirFieldComboBox .setField (dipdir_match )
143+
82144 def _on_calculator_type_changed (self ):
83145 """Update UI based on selected calculator type."""
84146 calculator_type = self .calculatorTypeComboBox .currentText ()
0 commit comments