@@ -229,11 +229,49 @@ def get_df(self):
229229
230230 def add_invalid_cell (self , row , column ):
231231 """Add an invalid cell to the set."""
232+ # check that the index is valid
233+ if not self .index (row , column ).isValid ():
234+ return
235+ # return if it is the last row
236+ if row == self ._data_frame .shape [0 ]:
237+ return
238+ # return if it is already invalid
239+ if (row , column ) in self ._invalid_cells :
240+ return
232241 self ._invalid_cells .add ((row , column ))
242+ self .dataChanged .emit (
243+ self .index (row , column ),
244+ self .index (row , column ),
245+ [Qt .BackgroundRole ]
246+ )
233247
234248 def discard_invalid_cell (self , row , column ):
235249 """Discard an invalid cell from the set."""
236250 self ._invalid_cells .discard ((row , column ))
251+ self .dataChanged .emit (
252+ self .index (row , column ),
253+ self .index (row , column ),
254+ [Qt .BackgroundRole ]
255+ )
256+
257+ def update_invalid_cells (self , selected , mode : str = "rows" ):
258+ """Edits the invalid cells when values are deleted."""
259+ old_invalid_cells = self ._invalid_cells .copy ()
260+ new_invalid_cells = set ()
261+ sorted_to_del = sorted (selected )
262+ for a , b in old_invalid_cells :
263+ if mode == "rows" :
264+ to_be_change = a
265+ not_changed = b
266+ elif mode == "columns" :
267+ to_be_change = b
268+ not_changed = a
269+ if to_be_change in selected :
270+ continue
271+ smaller_count = sum (1 for x in sorted_to_del if x < to_be_change )
272+ new_val = to_be_change - smaller_count
273+ new_invalid_cells .add ((new_val , not_changed ))
274+ self ._invalid_cells = new_invalid_cells
237275
238276 def notify_data_color_change (self , row , column ):
239277 """Notify the view to change the color of some cells"""
0 commit comments