WIP V3: better handle row order changing
This commit is contained in:
parent
48b180e280
commit
80c363c316
@ -85,6 +85,7 @@ class MusicMusterSignals(QObject):
|
||||
enable_escape_signal = pyqtSignal(bool)
|
||||
end_reset_model_signal = pyqtSignal(int)
|
||||
next_track_changed_signal = pyqtSignal()
|
||||
row_order_changed_signal = pyqtSignal(int)
|
||||
search_songfacts_signal = pyqtSignal(str)
|
||||
search_wikipedia_signal = pyqtSignal(str)
|
||||
show_warning_signal = pyqtSignal(str, str)
|
||||
@ -138,10 +139,10 @@ class PlaylistTrack:
|
||||
Update with new plr information
|
||||
"""
|
||||
|
||||
session.add(plr)
|
||||
self.plr_rownum = plr.plr_rownum
|
||||
if not plr.track:
|
||||
return
|
||||
|
||||
session.add(plr)
|
||||
track = plr.track
|
||||
|
||||
self.artist = track.artist
|
||||
@ -151,7 +152,6 @@ class PlaylistTrack:
|
||||
self.path = track.path
|
||||
self.playlist_id = plr.playlist_id
|
||||
self.plr_id = plr.id
|
||||
self.plr_rownum = plr.plr_rownum
|
||||
self.silence_at = track.silence_at
|
||||
self.start_gap = track.start_gap
|
||||
self.start_time = None
|
||||
|
||||
@ -315,6 +315,7 @@ class Playlists(Base):
|
||||
"""Mark playlist as loaded and used now"""
|
||||
|
||||
self.open = True
|
||||
self.last_used = datetime.now()
|
||||
|
||||
@staticmethod
|
||||
def name_is_available(session: scoped_session, name: str) -> bool:
|
||||
|
||||
@ -127,6 +127,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
self.signals.add_track_to_playlist_signal.connect(self.add_track)
|
||||
self.signals.begin_reset_model_signal.connect(self.begin_reset_model)
|
||||
self.signals.end_reset_model_signal.connect(self.end_reset_model)
|
||||
self.signals.row_order_changed_signal.connect(self.row_order_changed)
|
||||
|
||||
with Session() as session:
|
||||
# Ensure row numbers in playlist are contiguous
|
||||
@ -796,7 +797,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
self.refresh_data(session)
|
||||
|
||||
# Update display
|
||||
self.update_track_times()
|
||||
self.signals.row_order_changed_signal.emit(self.playlist_id)
|
||||
self.invalidate_rows(list(row_map.keys()))
|
||||
|
||||
def move_rows_between_playlists(
|
||||
@ -849,6 +850,8 @@ class PlaylistModel(QAbstractTableModel):
|
||||
self.refresh_data(session)
|
||||
|
||||
# Reset of model must come after session has been closed
|
||||
self.signals.row_order_changed_signal.emit(self.playlist_id)
|
||||
self.signals.row_order_changed_signal.emit(to_playlist_id)
|
||||
self.signals.end_reset_model_signal.emit(to_playlist_id)
|
||||
self.update_track_times()
|
||||
|
||||
@ -960,6 +963,30 @@ class PlaylistModel(QAbstractTableModel):
|
||||
|
||||
return len(self.playlist_rows)
|
||||
|
||||
def row_order_changed(self, playlist_id: int) -> None:
|
||||
"""
|
||||
Signal handler for when row ordering has changed
|
||||
"""
|
||||
|
||||
if playlist_id != self.playlist_id:
|
||||
return
|
||||
|
||||
with Session() as session:
|
||||
if track_sequence.next.plr_rownum:
|
||||
next_plr = session.get(PlaylistRows, track_sequence.next.plr_rownum)
|
||||
if next_plr:
|
||||
track_sequence.next.plr_rownum = next_plr.plr_rownum
|
||||
if track_sequence.now.plr_rownum:
|
||||
now_plr = session.get(PlaylistRows, track_sequence.now.plr_rownum)
|
||||
if now_plr:
|
||||
track_sequence.now.plr_rownum = now_plr.plr_rownum
|
||||
if track_sequence.previous.plr_rownum:
|
||||
previous_plr = session.get(PlaylistRows, track_sequence.previous.plr_rownum)
|
||||
if previous_plr:
|
||||
track_sequence.previous.plr_rownum = previous_plr.plr_rownum
|
||||
|
||||
self.update_track_times()
|
||||
|
||||
def selection_is_sortable(self, row_numbers: List[int]) -> bool:
|
||||
"""
|
||||
Return True if the selection is sortable. That means:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user