proxymodel invalidateFilter() instead of model.layoutChanged.emit()
This commit is contained in:
parent
2ec1f0b7a7
commit
c4e5105f91
@ -376,52 +376,6 @@ class MusicTable(QTableView):
|
|||||||
debug(f'- logicalIndex: {logicalIndex}')
|
debug(f'- logicalIndex: {logicalIndex}')
|
||||||
self.on_sort()
|
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):
|
def on_cell_clicked(self, index):
|
||||||
"""
|
"""
|
||||||
@ -785,6 +739,7 @@ class MusicTable(QTableView):
|
|||||||
|
|
||||||
def jump_to_current_song(self):
|
def jump_to_current_song(self):
|
||||||
"""Moves screen to the currently playing song, then selects the row"""
|
"""Moves screen to the currently playing song, then selects the row"""
|
||||||
|
debug('jump_to_current_song()')
|
||||||
# get the proxy model index
|
# get the proxy model index
|
||||||
try:
|
try:
|
||||||
proxy_index = self.proxymodel.mapFromSource(self.current_song_qmodel_index)
|
proxy_index = self.proxymodel.mapFromSource(self.current_song_qmodel_index)
|
||||||
@ -999,7 +954,8 @@ class MusicTable(QTableView):
|
|||||||
self.populate_model(data)
|
self.populate_model(data)
|
||||||
# self.sort_table_by_multiple_columns()
|
# self.sort_table_by_multiple_columns()
|
||||||
self.current_playlist_id = self.selected_playlist_id
|
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_name: str = self.config.get("settings", "db").split("/").pop()
|
||||||
db_filename = self.config.get("settings", "db")
|
db_filename = self.config.get("settings", "db")
|
||||||
self.playlistStatsSignal.emit(f"Songs: {self.model2.rowCount()} | {db_name} | {db_filename}")
|
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
|
# `len(config_sort_orders)` number of SELECTs
|
||||||
# self.on_sort()
|
# self.on_sort()
|
||||||
# self.horizontal_header.sortIndicatorChanged.connect(self.on_user_sort_change)
|
# 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]]):
|
def save_sort_config(self, fields: list[tuple[str, Qt.SortOrder]]):
|
||||||
"""
|
"""
|
||||||
@ -1145,8 +1102,10 @@ class MusicTable(QTableView):
|
|||||||
continue
|
continue
|
||||||
self.sortByColumn(col_index, new_order)
|
self.sortByColumn(col_index, new_order)
|
||||||
debug(f'- sorted column index {col_index} by {new_order}')
|
debug(f'- sorted column index {col_index} by {new_order}')
|
||||||
self.model2.layoutChanged.emit()
|
# self.model2.layoutChanged.emit()
|
||||||
debug('- emitted layoutChanged signal')
|
# debug('- emitted layoutChanged signal')
|
||||||
|
self.proxymodel.invalidateFilter()
|
||||||
|
debug('- proxymodel invalidateFilter()')
|
||||||
# self.on_sort()
|
# self.on_sort()
|
||||||
|
|
||||||
def get_audio_files_recursively(self, directories: list[str], progress_callback=None) -> list[str]:
|
def get_audio_files_recursively(self, directories: list[str], progress_callback=None) -> list[str]:
|
||||||
@ -1296,20 +1255,6 @@ class MusicTable(QTableView):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
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
|
# QT Roles
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user