@@ -40,6 +40,13 @@ def setup_table(self):
4040 self .table .setAlternatingRowColors (False )
4141 self .table .setSortingEnabled (False )
4242
43+ self .model .rowsInserted .connect (self .merge_cells )
44+ self .model .rowsRemoved .connect (self .merge_cells )
45+ self .model .dataChanged .connect (self ._on_data_changed_commands )
46+ self .model .modelReset .connect (self .merge_cells )
47+
48+ self .merge_cells ()
49+
4350 def auto_adjust_cells (self ):
4451 self .table .resizeColumnsToContents ()
4552
@@ -163,3 +170,42 @@ def delete_rows(self):
163170 return
164171 if rows :
165172 self .deleteRowsRequested .emit (rows )
173+
174+ def merge_cells (self ):
175+ self .table .clearSpans ()
176+
177+ model = self .model
178+ command_col = 6
179+ desc_col = 3
180+
181+ blocks = []
182+ start_row_stack = []
183+
184+ start_row = 3
185+ end_row = model .rowCount () - 3
186+ if end_row < start_row :
187+ return
188+
189+ row = 3
190+ for row in range (row , end_row ):
191+ command_index = model .index (row , command_col )
192+ command = model .data (command_index , Qt .ItemDataRole .DisplayRole )
193+
194+ if command == "StartScenario" :
195+ start_row_stack .append (row )
196+
197+ elif command == "EndScenario" :
198+ if start_row_stack :
199+ start_row = start_row_stack .pop ()
200+ blocks .append ((start_row , row ))
201+
202+ for start , end in blocks :
203+ span_size = end - start + 1
204+ if span_size > 1 :
205+ self .table .setSpan (start , desc_col , span_size , 1 )
206+
207+ def _on_data_changed_commands (self , topLeft , bottomRight , roles ):
208+ command_col = 6
209+
210+ if topLeft .column () <= command_col <= bottomRight .column ():
211+ self .merge_cells ()
0 commit comments