readme ideas and model caching and loading and such

This commit is contained in:
Billy 2025-10-02 19:20:47 +00:00
parent 7e7302528b
commit 93b73c9678
2 changed files with 87 additions and 68 deletions

View File

@ -85,3 +85,6 @@ QMultimedia.EncodingMode / Encoding quality...
- on save metadata modal, run save in another thread (freezing)
- on save metadata modal, return to previous state in table (jump to current song/restore scroll position)
- on add to playlist, check if song already exists - prompt user for duplicate?
- drag and drop song(s) onto PlaylistPane to add to playlist
- font sizing
- font choicing? :o

View File

@ -93,9 +93,10 @@ class MusicTable(QTableView):
# Set QTableView model to the Proxy model
# so it looks like the above note, i guess
# need a QStandardItemModel to do actions on cells
# need a QStandardItemModel to load data & do actions on cells
self.model2: QStandardItemModel = QStandardItemModel()
self.proxymodel: QSortFilterProxyModel = QSortFilterProxyModel()
self.cache_models: dict[int | None, QStandardItemModel]
self.search_string: str | None = None
self.headers = HeaderTags()
# db names of headers
@ -722,9 +723,22 @@ class MusicTable(QTableView):
)
params = ""
debug(f'playlist_id: {playlist_id}')
# Load a playlist
is_playlist = 0
if len(playlist_id) > 0:
self.selected_playlist_id = playlist_id[0]
is_playlist = 1
else:
self.selected_playlist_id = None
# Check cache for already loaded QTableView QStandardItemModel
try:
new_model = self.cache_models[self.selected_playlist_id]
self.model2 = new_model
except KeyError:
# Store the current loaded model
self.cache_models[self.selected_playlist_id] = self.model2
# Query for a playlist
if is_playlist:
debug('load music table a playlist')
try:
with DBA.DBAccess() as db:
@ -746,7 +760,7 @@ class MusicTable(QTableView):
except Exception as e:
error(f"load_music_table() | Unhandled exception 1: {e}")
return
# Load the entire library
# Query for the entire library
else:
debug('load music table a Whole Table')
try:
@ -767,7 +781,7 @@ class MusicTable(QTableView):
error(f"load_music_table() | Unhandled exception 2: {e}")
return
# Populate the model
row_count: int = 0
# row_count: int = 0
# TODO: total time of playlist
# but how do i want to do this if user doesn't choose to see length field?
# spawn new thread and calculate myself?
@ -775,7 +789,7 @@ class MusicTable(QTableView):
for row_data in data:
# print(row_data)
# if "length" in fields:
row_count += 1
# row_count += 1
id, *rest_of_data = row_data
# handle different datatypes
items = []
@ -807,7 +821,9 @@ class MusicTable(QTableView):
db_name: str = self.config.get("settings", "db").split("/").pop()
db_filename = self.config.get("settings", "db")
self.playlistStatsSignal.emit(f"Songs: {row_count} | Total time: {total_time} | {db_name} | {db_filename}")
# FIXME: total time implementation
total_time = 0
self.playlistStatsSignal.emit(f"Songs: {self.model2.rowCount()} | Total time: {total_time} | {db_name} | {db_filename}")
self.loadMusicTableSignal.emit()
self.connect_data_changed()
self.connect_layout_changed()