1818)
1919
2020from ..C import COLUMN , INDEX
21+ from ..commands import RenameValueCommand
2122from ..models .pandas_table_model import (
2223 PandasTableFilterProxy ,
2324 PandasTableModel ,
@@ -588,6 +589,25 @@ def save_table(self, file_name):
588589 f"Failed to save table: { str (e )} " ,
589590 )
590591
592+ def rename_value (
593+ self , old_id : str , new_id : str , column_names : str | list [str ]
594+ ):
595+ """Rename the values in the dataframe.
596+
597+ Triggered by changes in the original observable_df or condition_df id.
598+
599+ Parameters
600+ ----------
601+ old_id:
602+ The old id, which was changed.
603+ new_id:
604+ The new id.
605+ column_names:
606+ The column or list of columns in which the id should be changed.
607+ """
608+ command = RenameValueCommand (self .model , old_id , new_id , column_names )
609+ self .undo_stack .push (command )
610+
591611
592612class MeasurementController (TableController ):
593613 """Controller of the Measurement table."""
@@ -608,45 +628,6 @@ def check_petab_lint(
608628 observable_df = observable_df ,
609629 )
610630
611- def rename_value (
612- self , old_id : str , new_id : str , column_names : str | list [str ]
613- ):
614- """Rename the values in the measurement_df.
615-
616- Triggered by changes in the original observable_df or condition_df id.
617-
618- Parameters
619- ----------
620- old_id:
621- The old id, which was changed.
622- new_id:
623- The new id.
624- """
625- if not isinstance (column_names , list ):
626- column_names = [column_names ]
627-
628- for col_name in column_names :
629- # Find occurrences
630- mask = self .model ._data_frame [col_name ].eq (old_id )
631- if not mask .any ():
632- continue
633-
634- self .model ._data_frame .loc [mask , col_name ] = new_id
635- first_row , last_row = (
636- mask .idxmax (),
637- mask [::- 1 ].idxmax (),
638- )
639- top_left = self .model .index (first_row , 1 )
640- bottom_right = self .model .index (
641- last_row , self .model .columnCount () - 1
642- )
643- self .model .dataChanged .emit (
644- top_left , bottom_right , [Qt .DisplayRole , Qt .EditRole ]
645- )
646-
647- # Emit change signal
648- self .model .something_changed .emit (True )
649-
650631 def copy_noise_parameters (
651632 self , observable_id : str , condition_id : str | None = None
652633 ) -> str :
0 commit comments