@@ -228,17 +228,37 @@ def onFaultTraceLayerChanged(self, layer):
228228
229229 def onUnitFieldChanged (self , field ):
230230 unique_values = set ()
231+ attributes = {}
231232 layer = self .unitNameField .layer ()
232233 if layer :
234+ fields = {}
235+ fields ['unitname' ] = layer .fields ().indexFromName (field )
236+ if 'LS_thickness' in [field .name () for field in layer .fields ()]:
237+ fields ['thickness' ] = layer .fields ().indexFromName ('LS_thickness' )
238+ if 'LS_order' in [field .name () for field in layer .fields ()]:
239+ fields ['order' ] = layer .fields ().indexFromName ('LS_order' )
240+ if 'LS_colour' in [field .name () for field in layer .fields ()]:
241+ fields ['colour' ] = layer .fields ().indexFromName ('LS_colour' )
233242 field_index = layer .fields ().indexFromName (field )
243+
234244 for feature in layer .getFeatures ():
235245 unique_values .add (str (feature [field_index ]))
246+ attributes [str (feature [field_index ])] = {}
247+ for k in fields :
248+ attributes [str (feature [field_index ])][k ] = feature [fields [k ]]
236249 colours = random_hex_colour (n = len (unique_values ))
237250 self ._units = dict (
238251 zip (
239252 list (unique_values ),
240253 [
241- {'thickness' : 10.0 , 'order' : i , 'name' : u , 'color' : colours [i ]}
254+ {
255+ 'thickness' : attributes [u ]['thickness' ]
256+ if 'thickness' in attributes [u ]
257+ else 10.0 ,
258+ 'order' : attributes [u ]['order' ] if 'order' in attributes [u ] else i ,
259+ 'name' : u ,
260+ 'colour' : attributes [u ]['colour' ] if 'colour' in attributes [u ] else colours [i ],
261+ }
242262 for i , u in enumerate (unique_values )
243263 ],
244264 )
@@ -361,7 +381,7 @@ def create_color_picker(unit):
361381 def pick_color ():
362382 color = QColorDialog .getColor ()
363383 if color .isValid ():
364- self ._units [unit ]['color ' ] = color .name ()
384+ self ._units [unit ]['colour ' ] = color .name ()
365385 self ._initialiseStratigraphicColumn ()
366386
367387 return pick_color
@@ -376,7 +396,7 @@ def pick_color():
376396 down = QPushButton ("↓" )
377397 color_picker = QPushButton ("Pick Colour" )
378398 # Set background color for the row
379- background_color = value .get ('color ' , "#ffffff" )
399+ background_color = value .get ('colour ' , "#ffffff" )
380400 label .setStyleSheet (f"background-color: { background_color } ;" )
381401 spin_box .setStyleSheet (f"background-color: { background_color } ;" )
382402 order .setStyleSheet (f"background-color: { background_color } ;" )
@@ -438,7 +458,7 @@ def onSaveModel(self):
438458 def saveThicknessOrder (self ):
439459 layer = self .basalContactsLayer .currentLayer ()
440460 layer .startEditing ()
441- field_names = ["LS_thickness" , "LS_order" ]
461+ field_names = ["LS_thickness" , "LS_order" , "LS_colour" ]
442462 for field_name in field_names :
443463
444464 if field_name not in [field .name () for field in layer .fields ()]:
@@ -450,11 +470,11 @@ def saveThicknessOrder(self):
450470 if feature .attributeMap ().get (self .unitNameField .currentField ()) == unit :
451471 feature [field_names [0 ]] = value ['thickness' ]
452472 feature [field_names [1 ]] = value ['order' ]
453-
473+ feature [ field_names [ 2 ]] = value [ 'colour' ]
454474 layer .updateFeature (feature )
455475 layer .commitChanges ()
456476 layer .updateFields ()
457- self .logger (message = f"Thickness and order saved to { layer .name ()} " , log_level = 1 , push = True )
477+ self .logger (message = f"Thickness, colour and order saved to { layer .name ()} " , log_level = 1 , push = True )
458478
459479 def onPathTextChanged (self , text ):
460480 self .outputPath = text
0 commit comments