Skip to content

Commit b087219

Browse files
committed
Styling for cells, insert row custom number of rows
1 parent ff24451 commit b087219

5 files changed

Lines changed: 83 additions & 22 deletions

File tree

core/table_controller.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def clear(self, model, selection):
105105
self.undo_stack.endMacro()
106106

107107
def generate_test_cases(self, model):
108+
test_case_generated = 0
108109
self.undo_stack.beginMacro("Generate Test Cases")
109110
for row in range(model.rowCount()):
110111
steps_performed_index = model.index(row, TestScenarioModel.STEPS_COL)
@@ -138,9 +139,11 @@ def generate_test_cases(self, model):
138139
if steps_performed_text != old_steps_performed:
139140
command_obj = EditCellCommand(model, steps_performed_index, steps_performed_text, old_steps_performed)
140141
self.undo_stack.push(command_obj)
142+
test_case_generated += 1
141143

142144
old_expected_result = model.data(expected_result_index, Qt.ItemDataRole.EditRole)
143145
if expected_result_text != old_expected_result:
144146
command_obj = EditCellCommand(model, expected_result_index, expected_result_text, old_expected_result)
145147
self.undo_stack.push(command_obj)
146148
self.undo_stack.endMacro()
149+
return test_case_generated

ui/delegates.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,32 +186,72 @@ def _get_objects(self):
186186
return self.cached_objects
187187

188188
def paint(self, painter, option, index):
189-
if index.row() == 0:
190-
super().paint(painter, option, index)
191-
return
192-
189+
model = index.model()
190+
current_row = index.row()
191+
current_col = index.column()
192+
total_rows = model.rowCount()
193193
option = QStyleOptionViewItem(option)
194+
is_special_row = False
195+
196+
if isinstance(model, TestScenarioModel):
197+
if (current_row == 0 or
198+
current_row == 1 or
199+
current_row == total_rows - 1 or
200+
current_row == total_rows - 2):
201+
option.font.setBold(True)
202+
is_special_row = True
203+
elif current_col in [TestScenarioModel.COMMAND_COL, TestScenarioModel.DESC_COL, TestScenarioModel.SKIP_COL]:
204+
option.font.setBold(True)
205+
if current_col == TestScenarioModel.STEPS_COL:
206+
value = model.data(index, Qt.ItemDataRole.DisplayRole)
207+
if value in ["Scenario Started", "Scenario Ended"]:
208+
option.font.setBold(True)
209+
210+
elif isinstance(model, ObjRepoModel):
211+
if (current_row == 0 or
212+
current_row == total_rows - 1):
213+
option.font.setBold(True)
214+
is_special_row = True
194215

195216
final_color = option.palette.color(QPalette.ColorRole.Text)
196217

197-
model = index.model()
198-
if isinstance(model, TestScenarioModel):
199-
col = index.column()
218+
if not is_special_row and isinstance(model, TestScenarioModel):
200219
value = index.data(Qt.ItemDataRole.DisplayRole)
201220

202221
if value:
203-
if col == TestScenarioModel.COMMAND_COL:
222+
if current_col == TestScenarioModel.COMMAND_COL:
204223
if value not in self.commands:
205224
final_color = QColor("#E57373")
206225

207-
elif TestScenarioModel.DATA1_COL <= col <= TestScenarioModel.DATA5_COL:
226+
elif TestScenarioModel.DATA1_COL <= current_col <= TestScenarioModel.DATA5_COL:
208227
objects = self._get_objects()
209228
if value not in objects:
210229
final_color = QColor("#64B5F6")
211230

212231
option.palette.setColor(QPalette.ColorRole.Text, final_color)
213232
option.palette.setColor(QPalette.ColorRole.HighlightedText, final_color)
214233

234+
# if not is_special_row and isinstance(model, TestScenarioModel):
235+
# command_index = model.index(current_row, TestScenarioModel.COMMAND_COL)
236+
# command_value = model.data(command_index, Qt.ItemDataRole.DisplayRole)
237+
238+
# if command_value == "StartScenario":
239+
# painter.save()
240+
# pen = painter.pen()
241+
# pen.setColor(QColor("#B0B0B0"))
242+
# pen.setWidth(1)
243+
# painter.setPen(pen)
244+
# painter.drawLine(option.rect.topLeft(), option.rect.topRight())
245+
# painter.restore()
246+
# if command_value == "EndScenario":
247+
# painter.save()
248+
# pen = painter.pen()
249+
# pen.setColor(QColor("#B0B0B0"))
250+
# pen.setWidth(1)
251+
# painter.setPen(pen)
252+
# painter.drawLine(option.rect.bottomLeft(), option.rect.bottomRight())
253+
# painter.restore()
254+
215255
super().paint(painter, option, index)
216256

217257

ui/menu.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ def generate_test_cases_action(self):
7878
if current_tab and hasattr(current_tab, 'controller'):
7979
current_table = self.main.get_current_table()
8080
if current_table:
81-
current_tab.controller.generate_test_cases(current_table.model)
81+
num_generated = current_tab.controller.generate_test_cases(current_table.model)
82+
if num_generated > 0:
83+
message = f"Generated {num_generated} test case(s)."
84+
self.main.show_status_message(message, "success", 5000)
85+
else:
86+
message = f"No empty fields found to generate."
87+
self.main.show_status_message(message, "info", 5000)
8288

8389
def auto_adjust_cells(self):
8490
table = self.main.get_current_table()

ui/styles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def get_stylesheet(theme_name="dark"):
6060
return f"""
6161
/* Global */
6262
QWidget {{
63-
font-family: "Segoe UI", "Calibri", "Arial";
63+
font-family "Courier New", "Calibri", "Arial", sans-serif;
6464
font-size: 16px;
6565
color: {colors["TEXT_MUTED"]};
6666
background-color: {colors["BG_DARK"]};

ui/table.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QTableView, QHeaderView, QMenu
1+
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QTableView, QHeaderView, QMenu, QInputDialog
22
from PyQt6.QtCore import Qt, pyqtSignal, QItemSelection, QModelIndex
33
from PyQt6.QtGui import QAction, QKeySequence, QShortcut
44

@@ -128,18 +128,30 @@ def clear_cells(self):
128128
self.clearRequested.emit(selection)
129129

130130
def insert_rows(self):
131-
current_index = self.table.currentIndex()
132131
selection = self.table.selectionModel().selection()
133-
if not selection.isEmpty():
134-
rows = sorted(set(index.row() for index in selection.indexes()))
135-
position = rows[0]
136-
rows_to_insert = len(rows)
137-
elif current_index.isValid():
138-
position = current_index.row()
139-
rows_to_insert = 1
140-
else:
132+
133+
rows = sorted(set(index.row() for index in selection.indexes()))
134+
num_rows = len(rows)
135+
if num_rows < 1:
141136
return
142-
self.insertRowsRequested.emit(position, rows_to_insert)
137+
position = rows[0]
138+
139+
if num_rows > 1:
140+
self.insertRowsRequested.emit(position, num_rows)
141+
if num_rows == 1:
142+
num, ok = QInputDialog.getInt(
143+
self,
144+
"Insert Rows",
145+
"No. of Rows:",
146+
1,
147+
1,
148+
100
149+
)
150+
if ok and num > 0:
151+
rows_to_insert = num
152+
self.insertRowsRequested.emit(position, rows_to_insert)
153+
else:
154+
return
143155

144156
def delete_rows(self):
145157
selection = self.table.selectionModel().selection()

0 commit comments

Comments
 (0)