From c4e5105f91152204fa777ea24bfc3414323ed063 Mon Sep 17 00:00:00 2001 From: "billy@pom" Date: Sat, 10 Jan 2026 09:18:53 -0500 Subject: [PATCH] proxymodel invalidateFilter() instead of model.layoutChanged.emit() --- components/MusicTable.py | 73 +++++----------------------------------- 1 file changed, 9 insertions(+), 64 deletions(-) diff --git a/components/MusicTable.py b/components/MusicTable.py index 64c31bb..74e2e4c 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -376,52 +376,6 @@ class MusicTable(QTableView): debug(f'- logicalIndex: {logicalIndex}') self.on_sort() - def on_user_sort_change(self, column: int, order: Qt.SortOrder): - """ - Called when user clicks a column header to sort. - Updates the multi-sort config based on interaction. - """ - debug('on_user_sort_change()') - debug(f'- args: column = {column}') - debug(f'- args: order = {order}') - try: - db_field = self.headers.db_list[column] - debug(f'on_user_sort_change() - db_field = {db_field}') - except IndexError: - error(f"on_user_sort_change() - Invalid column index: {column}") - return - - raw = self.config["table"].get(option="sort_order", fallback="") - debug(f'on_user_sort_change() - raw = {raw}') - sort_list = [] - - # Parse current sort_order from config - if raw: - for item in raw.split(","): - if ":" not in item: - continue - field, dir_str = item.strip().split(":") - direction = int(dir_str) - if dir_str == "1": - direction = Qt.SortOrder.AscendingOrder - elif dir_str == "2": - direction = Qt.SortOrder.DescendingOrder - else: - direction = None - sort_list.append((field, direction)) - - # Update or insert the new sort field at the end (highest priority) - sort_list = [(f, d) for f, d in sort_list if f != db_field] # remove if exists - # sort_list.append((db_field, order)) - - debug(f'on_user_sort_change() - sort list updated (field, direction): {sort_list}') - - # Save back to config - self.save_sort_config(sort_list) - - # Re-apply the updated sort order - self.sort_by_logical_fields() - def on_cell_clicked(self, index): """ @@ -785,6 +739,7 @@ class MusicTable(QTableView): def jump_to_current_song(self): """Moves screen to the currently playing song, then selects the row""" + debug('jump_to_current_song()') # get the proxy model index try: proxy_index = self.proxymodel.mapFromSource(self.current_song_qmodel_index) @@ -999,7 +954,8 @@ class MusicTable(QTableView): self.populate_model(data) # self.sort_table_by_multiple_columns() self.current_playlist_id = self.selected_playlist_id - self.model2.layoutChanged.emit() # emits a signal that the view should be updated + # self.model2.layoutChanged.emit() # emits a signal that the view should be updated + self.proxymodel.invalidateFilter() db_name: str = self.config.get("settings", "db").split("/").pop() db_filename = self.config.get("settings", "db") self.playlistStatsSignal.emit(f"Songs: {self.model2.rowCount()} | {db_name} | {db_filename}") @@ -1082,7 +1038,8 @@ class MusicTable(QTableView): # `len(config_sort_orders)` number of SELECTs # self.on_sort() # self.horizontal_header.sortIndicatorChanged.connect(self.on_user_sort_change) - self.model2.layoutChanged.emit() + # self.model2.layoutChanged.emit() + self.proxymodel.invalidateFilter() def save_sort_config(self, fields: list[tuple[str, Qt.SortOrder]]): """ @@ -1145,8 +1102,10 @@ class MusicTable(QTableView): continue self.sortByColumn(col_index, new_order) debug(f'- sorted column index {col_index} by {new_order}') - self.model2.layoutChanged.emit() - debug('- emitted layoutChanged signal') + # self.model2.layoutChanged.emit() + # debug('- emitted layoutChanged signal') + self.proxymodel.invalidateFilter() + debug('- proxymodel invalidateFilter()') # self.on_sort() def get_audio_files_recursively(self, directories: list[str], progress_callback=None) -> list[str]: @@ -1296,20 +1255,6 @@ class MusicTable(QTableView): except Exception: pass - # def disconnect_layout_changed(self): - # """Disconnects the layoutChanged signal from QTableView.model""" - # try: - # self.model2.layoutChanged.disconnect() - # except Exception: - # pass - - # def connect_layout_changed(self): - # """Connects the layoutChanged signal from QTableView.model""" - # try: - # pass - # _ = self.model2.layoutChanged.connect(self.restore_scroll_position) - # except Exception: - # pass # QT Roles