Row edit updates now handled in PlaylistRow
This commit is contained in:
parent
a0ded4b73d
commit
d6bb3d04d8
@ -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=})")
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user