Skip to content

Commit 5cdefbf

Browse files
committed
Select newly inserted rows in Profile model/view. This fixes a bug when adding a new custom profile and the context menu not updating correctly. Also, fixed the Profile comparison to use "is" since we just modified the Swig bindings for Profile equality operators.
1 parent 2845489 commit 5cdefbf

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/windows/models/profiles_model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def update_or_insert_row(self, profile):
9191
existing_index = None
9292
for row in range(self.model.rowCount()):
9393
index = self.model.index(row, 0) # Assuming key is in column 0
94-
if index.data(Qt.UserRole) == profile:
94+
if index.data(Qt.UserRole) is profile:
9595
existing_index = index
9696
break
9797

@@ -109,7 +109,7 @@ def remove_row(self, profile):
109109
# Find if the profile already exists in the model by key
110110
for row in range(self.model.rowCount()):
111111
index = self.model.index(row, 0) # Assuming key is in column 0
112-
if index.data(Qt.UserRole) == profile:
112+
if index.data(Qt.UserRole) is profile:
113113
# Remove the row from the model
114114
self.model.removeRow(row)
115115
break

src/windows/views/profiles_treeview.py

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ def selectionChanged(self, selected, deselected):
4646
self.selected_profile_object = selected.first().indexes()[0].data(Qt.UserRole)
4747
super().selectionChanged(selected, deselected)
4848

49+
def on_rows_inserted(self, parent, first, last):
50+
"""Handle row insertion and refresh view."""
51+
self.last_inserted_row_index = self.model().index(last, 0)
52+
53+
# Select the newly inserted row
54+
if self.last_inserted_row_index.isValid():
55+
self.selectionModel().clear()
56+
self.select_profile(self.last_inserted_row_index)
57+
self.selectionModel().select(self.last_inserted_row_index, QItemSelectionModel.Select)
58+
self.scrollTo(self.last_inserted_row_index)
59+
4960
def refresh_view(self, filter_text=""):
5061
"""Filter transitions with proxy class"""
5162
self.is_filter_running = True
@@ -126,6 +137,8 @@ def __init__(self, dialog, profiles, *args):
126137
self.setStyleSheet('QTreeView::item { padding-top: 2px; }')
127138
self.columns = 6
128139
self.selected_profile_object = None
140+
self.last_inserted_row_index = None
141+
self.model().rowsInserted.connect(self.on_rows_inserted)
129142

130143
# Refresh view
131144
self.profiles_model.update_model()

0 commit comments

Comments
 (0)