Skip to content

Commit 617ca58

Browse files
committed
added objects duplication syntax highlighting
1 parent 10f32e3 commit 617ca58

5 files changed

Lines changed: 58 additions & 193 deletions

File tree

config.json

Lines changed: 0 additions & 176 deletions
This file was deleted.

models/obj_repo.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .model import TableModel
33

44
from PyQt6.QtCore import QModelIndex, Qt
5-
from typing import Optional
5+
from typing import Optional, Any
66

77
class ObjRepoModel(TableModel):
88

@@ -50,6 +50,25 @@ def setData(self, index, value, role=Qt.ItemDataRole.EditRole):
5050
break
5151
return result
5252

53+
def headerData(self, section: int, orientation: Qt.Orientation, role: int = Qt.ItemDataRole.DisplayRole) -> Any:
54+
if role == Qt.ItemDataRole.DisplayRole and orientation == Qt.Orientation.Vertical:
55+
return str(section + 1)
56+
return super().headerData(section, orientation, role)
57+
58+
def get_duplicate_names(self):
59+
if self.df.empty:
60+
return set()
61+
# Ensure we're working with string types, and handle potential float NaNs
62+
names = self.df.iloc[:, self.NAME_COL].astype(str)
63+
# Filter out empty strings and 'END'
64+
names = names[names.str.strip() != '']
65+
names = names[names != 'END']
66+
names = names[names != 'User friendly name of Object']
67+
68+
# Find duplicates
69+
duplicates = names[names.duplicated()].unique()
70+
return set(duplicates)
71+
5372
def insertRows(self, position, rows, parent=QModelIndex()):
5473
success = super().insertRows(position, rows, parent)
5574
if success:
@@ -61,7 +80,7 @@ def insertRows(self, position, rows, parent=QModelIndex()):
6180
if row_index < len(self.df):
6281
self.df.iat[row_index, self.XPATH_COL] = "XPATH"
6382
self.dataChanged.emit(xpath_index, xpath_index, [Qt.ItemDataRole.EditRole])
64-
self.layoutChangedSignal.emit()
83+
self.layoutChanged.emit()
6584
except Exception as e:
6685
print(f"Error setting type or updating IDs after insert: {e}")
6786
return False

ui/delegates.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def __init__(self, parent, undo_stack, commands, colors):
1616
self.colors = colors
1717
self.cached_objects = [] # Cache for objects
1818
self.objects_dirty = True
19+
self.duplicate_names_cache = set()
20+
self.duplicate_names_dirty = True
1921

2022
self.editor = None
2123
self.current_model = None
@@ -188,6 +190,9 @@ def update_command_list(self, new_commands):
188190
def invalidate_objects_cache(self):
189191
self.objects_dirty = True
190192

193+
def invalidate_duplicate_names_cache(self):
194+
self.duplicate_names_dirty = True
195+
191196
def _get_objects(self):
192197
if self.objects_dirty:
193198
obj_repo_model = self.parent_tab.model2
@@ -199,6 +204,12 @@ def _get_objects(self):
199204
self.objects_dirty = False
200205
return self.cached_objects
201206

207+
def _get_duplicate_names(self, model):
208+
if self.duplicate_names_dirty:
209+
self.duplicate_names_cache = model.get_duplicate_names()
210+
self.duplicate_names_dirty = False
211+
return self.duplicate_names_cache
212+
202213
def paint(self, painter, option, index):
203214
model = index.model()
204215
current_row = index.row()
@@ -235,18 +246,26 @@ def paint(self, painter, option, index):
235246

236247
final_color = option.palette.color(QPalette.ColorRole.Text)
237248

238-
if not is_special_row and isinstance(model, TestScenarioModel):
239-
value = index.data(Qt.ItemDataRole.DisplayRole)
240-
241-
if value:
242-
if current_col == TestScenarioModel.COMMAND_COL:
243-
if value not in self.commands:
244-
final_color = QColor("#E57373")
245-
246-
elif TestScenarioModel.DATA1_COL <= current_col <= TestScenarioModel.DATA5_COL:
247-
objects = self._get_objects()
248-
if value not in objects:
249-
final_color = QColor("#64B5F6")
249+
if not is_special_row:
250+
if isinstance(model, TestScenarioModel):
251+
value = index.data(Qt.ItemDataRole.DisplayRole)
252+
253+
if value:
254+
if current_col == TestScenarioModel.COMMAND_COL:
255+
if value not in self.commands:
256+
final_color = QColor("#E57373")
257+
258+
elif TestScenarioModel.DATA1_COL <= current_col <= TestScenarioModel.DATA5_COL:
259+
objects = self._get_objects()
260+
if value not in objects:
261+
final_color = QColor("#64B5F6")
262+
elif isinstance(model, ObjRepoModel):
263+
if current_col == ObjRepoModel.NAME_COL:
264+
value = index.data(Qt.ItemDataRole.DisplayRole)
265+
if value:
266+
duplicate_names = self._get_duplicate_names(model)
267+
if value in duplicate_names:
268+
final_color = QColor("#E57373")
250269

251270
option.palette.setColor(QPalette.ColorRole.Text, final_color)
252271
option.palette.setColor(QPalette.ColorRole.HighlightedText, final_color)

ui/tab.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, module_name, main, project_name=None):
3030
self.delegate = ComboBoxDelegate(self, self.undo_stack, commands, colors)
3131

3232
self.table1 = Table(model=self.model1, undo_stack=self.undo_stack, delegate=self.delegate, parent_tab=self)
33-
self.table2 = Table(model=self.model2, undo_stack=self.undo_stack, delegate=self.delegate)
33+
self.table2 = Table(model=self.model2, undo_stack=self.undo_stack, delegate=self.delegate, show_vertical_header=True)
3434

3535
self.controller = TableController(main, self.undo_stack)
3636

@@ -128,6 +128,7 @@ def update_delegate_commands(self, commands):
128128

129129
def on_object_model_changed(self):
130130
self.delegate.invalidate_objects_cache()
131+
self.delegate.invalidate_duplicate_names_cache()
131132

132133
def is_object_in_repository(self, object_name):
133134
if not object_name:

ui/table.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ class Table(QWidget):
1313
skipRequested = pyqtSignal(list)
1414
unskipRequested = pyqtSignal(list)
1515

16-
def __init__(self, model, undo_stack=None, delegate=None, parent_tab=None):
16+
def __init__(self, model, undo_stack=None, delegate=None, parent_tab=None, show_vertical_header=False):
1717
super().__init__()
1818
self.model = model
1919
self.undo_stack = undo_stack
2020
self.delegate = delegate
2121
self.parent_tab = parent_tab
22+
self.show_vertical_header = show_vertical_header
2223

2324
layout = QVBoxLayout()
2425
layout.setContentsMargins(0, 0, 0, 0)
@@ -39,7 +40,8 @@ def setup_table(self):
3940
v_header = self.table.verticalHeader()
4041
h_header.setSectionResizeMode(QHeaderView.ResizeMode.Interactive)
4142
h_header.setMinimumHeight(20)
42-
v_header.hide()
43+
if not self.show_vertical_header:
44+
v_header.hide()
4345
self.auto_adjust_cells()
4446
self.table.setWordWrap(True)
4547
self.table.setAlternatingRowColors(False)

0 commit comments

Comments
 (0)