Row edit updates now handled in PlaylistRow

This commit is contained in:
Keith Edmunds 2025-04-15 10:22:10 +01:00
parent a0ded4b73d
commit d6bb3d04d8
2 changed files with 40 additions and 10 deletions

View File

@ -1309,7 +1309,10 @@ class PlaylistModel(QAbstractTableModel):
role: int = Qt.ItemDataRole.EditRole, role: int = Qt.ItemDataRole.EditRole,
) -> bool: ) -> 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: if not index.isValid() or role != Qt.ItemDataRole.EditRole:
@ -1320,20 +1323,18 @@ class PlaylistModel(QAbstractTableModel):
plr = self.playlist_rows[row_number] plr = self.playlist_rows[row_number]
if column == Col.NOTE.value: if column == Col.NOTE.value:
ds.playlistrow_update_note(plr.playlistrow_id, str(value)) plr.note = value
return True
track_id = plr.track_id elif column == Col.TITLE.value:
if not track_id: plr.title = value
raise ApplicationError(f"No track_id when editing {plr=}")
if column == Col.TITLE.value:
ds.track_update(track_id, dict(title=str(value)))
elif column == Col.ARTIST.value: elif column == Col.ARTIST.value:
ds.track_update(track_id, dict(artist=str(value))) plr.artist = value
elif column == Col.INTRO.value: elif column == Col.INTRO.value:
intro = int(round(float(value), 1) * 1000) intro = int(round(float(value), 1) * 1000)
ds.track_update(track_id, dict(intro=intro)) plr.intro = intro
else: else:
raise ApplicationError(f"setData called with unexpected column ({column=})") raise ApplicationError(f"setData called with unexpected column ({column=})")

View File

@ -70,6 +70,14 @@ class PlaylistRow:
else: else:
return "" 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 @property
def bitrate(self): def bitrate(self):
if self.dto.track: if self.dto.track:
@ -98,6 +106,14 @@ class PlaylistRow:
else: else:
return 0 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 @property
def lastplayed(self): def lastplayed(self):
if self.dto.track: if self.dto.track:
@ -133,6 +149,14 @@ class PlaylistRow:
else: else:
return "" 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 @property
def track_id(self): def track_id(self):
if self.dto.track: if self.dto.track:
@ -162,6 +186,11 @@ class PlaylistRow:
def note(self): def note(self):
return self.dto.note 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 @property
def played(self): def played(self):
return self.dto.played return self.dto.played