From d6bb3d04d8ffbf4eb205c13611cbc3f8e7bf1ef0 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Tue, 15 Apr 2025 10:22:10 +0100 Subject: [PATCH] Row edit updates now handled in PlaylistRow --- app/playlistmodel.py | 21 +++++++++++---------- app/playlistrow.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/app/playlistmodel.py b/app/playlistmodel.py index a6b754b..8116f19 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -1309,7 +1309,10 @@ class PlaylistModel(QAbstractTableModel): role: int = Qt.ItemDataRole.EditRole, ) -> bool: """ - Update model with edited data + Update model with edited data. Here we simply update the + playlist_row in self.playlist_rows. The act of doing that will + trigger a database update in the @setter property in the + PlaylistRow class. """ if not index.isValid() or role != Qt.ItemDataRole.EditRole: @@ -1320,20 +1323,18 @@ class PlaylistModel(QAbstractTableModel): plr = self.playlist_rows[row_number] if column == Col.NOTE.value: - ds.playlistrow_update_note(plr.playlistrow_id, str(value)) - return True + plr.note = value - track_id = plr.track_id - if not track_id: - raise ApplicationError(f"No track_id when editing {plr=}") + elif column == Col.TITLE.value: + plr.title = value - if column == Col.TITLE.value: - ds.track_update(track_id, dict(title=str(value))) elif column == Col.ARTIST.value: - ds.track_update(track_id, dict(artist=str(value))) + plr.artist = value + elif column == Col.INTRO.value: intro = int(round(float(value), 1) * 1000) - ds.track_update(track_id, dict(intro=intro)) + plr.intro = intro + else: raise ApplicationError(f"setData called with unexpected column ({column=})") diff --git a/app/playlistrow.py b/app/playlistrow.py index 943d872..8b24c6f 100644 --- a/app/playlistrow.py +++ b/app/playlistrow.py @@ -70,6 +70,14 @@ class PlaylistRow: else: return "" + @artist.setter + def artist(self, artist: str) -> None: + if not self.dto.track: + raise ApplicationError(f"No track_id when trying to set artist ({self})") + + self.dto.track.artist = artist + ds.track_update(self.track_id, dict(artist=str(artist))) + @property def bitrate(self): if self.dto.track: @@ -98,6 +106,14 @@ class PlaylistRow: else: return 0 + @intro.setter + def intro(self, intro: int) -> None: + if not self.dto.track: + raise ApplicationError(f"No track_id when trying to set intro ({self})") + + self.dto.track.intro = intro + ds.track_update(self.track_id, dict(intro=str(intro))) + @property def lastplayed(self): if self.dto.track: @@ -133,6 +149,14 @@ class PlaylistRow: else: return "" + @title.setter + def title(self, title: str) -> None: + if not self.dto.track: + raise ApplicationError(f"No track_id when trying to set title ({self})") + + self.dto.track.title = title + ds.track_update(self.track_id, dict(title=str(title))) + @property def track_id(self): if self.dto.track: @@ -162,6 +186,11 @@ class PlaylistRow: def note(self): return self.dto.note + @note.setter + def note(self, note: str) -> None: + self.dto.note = note + ds.playlistrow_update_note(self.playlistrow_id, str(note)) + @property def played(self): return self.dto.played