@@ -105,15 +105,14 @@ def _get_cached_df(self, table_name, proxy_model):
105105
106106 def _connect_proxy_signals (self , proxy , cache_key ):
107107 """Connect proxy signals for cache invalidation and plotting."""
108- for signal in [
109- proxy .dataChanged ,
110- proxy .rowsInserted ,
111- proxy .rowsRemoved ,
112- ]:
113- signal .connect (
114- lambda * , key = cache_key : self ._invalidate_cache (key )
115- )
116- signal .connect (self ._debounced_plot )
108+
109+ def on_data_change (* args , ** kwargs ):
110+ self ._invalidate_cache (cache_key )
111+ self ._debounced_plot ()
112+
113+ proxy .dataChanged .connect (on_data_change )
114+ proxy .rowsInserted .connect (on_data_change )
115+ proxy .rowsRemoved .connect (on_data_change )
117116
118117 def initialize (
119118 self , meas_proxy , sim_proxy , cond_proxy , vis_proxy , petab_model
@@ -124,6 +123,10 @@ def initialize(
124123 self .vis_proxy = vis_proxy
125124 self .petab_model = petab_model
126125
126+ # Clear all cache when reinitializing
127+ for key in self ._cache_valid :
128+ self ._cache_valid [key ] = False
129+
127130 # Connect cache invalidation and data changes
128131 self .options_manager .option_changed .connect (self ._debounced_plot )
129132
@@ -218,6 +221,9 @@ def _render_on_main_thread(self, payload):
218221 self ._update_tabs (fig )
219222
220223 def _update_tabs (self , fig : plt .Figure ):
224+ # Save current tab index before clearing
225+ current_tab_index = self .tab_widget .currentIndex ()
226+
221227 # Clean previous tabs
222228 self .tab_widget .clear ()
223229 # Clear Highlighter
@@ -329,6 +335,10 @@ def _update_tabs(self, fig: plt.Figure):
329335 # Plot residuals if necessary
330336 self .plot_residuals ()
331337
338+ # Restore the previously selected tab (if valid)
339+ if 0 <= current_tab_index < self .tab_widget .count ():
340+ self .tab_widget .setCurrentIndex (current_tab_index )
341+
332342 def highlight_from_selection (
333343 self , selected_rows : list [int ], proxy = None , y_axis_col = "measurement"
334344 ):
@@ -556,8 +566,13 @@ def __init__(self, canvas, parent):
556566 self .addWidget (self .settings_btn )
557567
558568 def update_checked_state (self , selected_option ):
559- for action in self .groupy_by_options .values ():
560- action .setChecked (action .text () == f"Groupy by { selected_option } " )
569+ for grp , action in self .groupy_by_options .items ():
570+ if grp == "vis_df" :
571+ action .setChecked (selected_option == "vis_df" )
572+ else :
573+ action .setChecked (
574+ action .text () == f"Group by { selected_option } "
575+ )
561576
562577
563578def create_plot_tab (
0 commit comments