Skip to content

Commit

Permalink
Select newly inserted rows in Profile model/view. This fixes a bug wh…
Browse files Browse the repository at this point in the history
…en 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.
  • Loading branch information
jonoomph committed Oct 11, 2024
1 parent 2845489 commit 5cdefbf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/windows/models/profiles_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def update_or_insert_row(self, profile):
existing_index = None
for row in range(self.model.rowCount()):
index = self.model.index(row, 0) # Assuming key is in column 0
if index.data(Qt.UserRole) == profile:
if index.data(Qt.UserRole) is profile:
existing_index = index
break

Expand All @@ -109,7 +109,7 @@ def remove_row(self, profile):
# Find if the profile already exists in the model by key
for row in range(self.model.rowCount()):
index = self.model.index(row, 0) # Assuming key is in column 0
if index.data(Qt.UserRole) == profile:
if index.data(Qt.UserRole) is profile:
# Remove the row from the model
self.model.removeRow(row)
break
Expand Down
13 changes: 13 additions & 0 deletions src/windows/views/profiles_treeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ def selectionChanged(self, selected, deselected):
self.selected_profile_object = selected.first().indexes()[0].data(Qt.UserRole)
super().selectionChanged(selected, deselected)

def on_rows_inserted(self, parent, first, last):
"""Handle row insertion and refresh view."""
self.last_inserted_row_index = self.model().index(last, 0)

# Select the newly inserted row
if self.last_inserted_row_index.isValid():
self.selectionModel().clear()
self.select_profile(self.last_inserted_row_index)
self.selectionModel().select(self.last_inserted_row_index, QItemSelectionModel.Select)
self.scrollTo(self.last_inserted_row_index)

def refresh_view(self, filter_text=""):
"""Filter transitions with proxy class"""
self.is_filter_running = True
Expand Down Expand Up @@ -126,6 +137,8 @@ def __init__(self, dialog, profiles, *args):
self.setStyleSheet('QTreeView::item { padding-top: 2px; }')
self.columns = 6
self.selected_profile_object = None
self.last_inserted_row_index = None
self.model().rowsInserted.connect(self.on_rows_inserted)

# Refresh view
self.profiles_model.update_model()
Expand Down

0 comments on commit 5cdefbf

Please sign in to comment.