get selected songs based on proxymodel, as things could be sorted differently

This commit is contained in:
tsi-billypom 2025-04-14 11:21:12 -04:00
parent fcaa8d9f05
commit 7ee1026421

View File

@ -24,6 +24,7 @@ from PyQt5.QtWidgets import (
QAbstractItemView, QAbstractItemView,
) )
from PyQt5.QtCore import ( from PyQt5.QtCore import (
QItemSelectionModel,
QSortFilterProxyModel, QSortFilterProxyModel,
Qt, Qt,
QModelIndex, QModelIndex,
@ -795,18 +796,23 @@ class MusicTable(QTableView):
return audio_files return audio_files
def get_selected_rows(self) -> list[int]: def get_selected_rows(self) -> list[int]:
"""Returns a list of indexes for every selected row""" """
selection_model = self.selectionModel() Returns a list of indexes for every selected row, agnostic of proxy model
This gets the actual index in the root table
"""
selection_model: QItemSelectionModel | None = self.selectionModel()
assert selection_model is not None # begone linter error
return [index.row() for index in selection_model.selectedRows()] return [index.row() for index in selection_model.selectedRows()]
def get_selected_songs_filepaths(self) -> list[str]: def get_selected_songs_filepaths(self) -> list[str]:
""" """
Returns a list of the filepaths for the currently selected songs Returns a list of the filepaths for the currently selected songs, based on the proxy model
(things could be sorted differently)
""" """
selected_rows = self.get_selected_rows() selected_rows = self.get_selected_rows()
filepaths = [] filepaths = []
for row in selected_rows: for row in selected_rows:
idx = self.model2.index(row, self.table_headers.index("path")) idx = self.proxymodel.index(row, self.table_headers.index("path"))
filepaths.append(idx.data()) filepaths.append(idx.data())
return filepaths return filepaths