WIP V3: copy and paste rows to same or other playlist works
This commit is contained in:
parent
551a574eac
commit
c626d91f26
@ -221,6 +221,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
self.active_tab = lambda: self.tabPlaylist.currentWidget()
|
||||
self.active_model = lambda: self.tabPlaylist.currentWidget().model()
|
||||
self.move_source_rows: Optional[List[int]] = None
|
||||
self.move_source_model: Optional[PlaylistModel] = None
|
||||
|
||||
self.load_last_playlists()
|
||||
if Config.CARTS_HIDE:
|
||||
@ -612,7 +614,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
# Save the selected PlaylistRows items ready for a later
|
||||
# paste
|
||||
self.selected_rows = self.active_tab().get_selected_rows()
|
||||
self.move_source_rows = self.active_tab().get_selected_rows()
|
||||
self.move_source_model = self.active_model()
|
||||
|
||||
def debug(self):
|
||||
"""Invoke debugger"""
|
||||
@ -955,7 +958,9 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
to_row = 0
|
||||
|
||||
# Move rows
|
||||
self.active_model().move_rows_between_playlists(row_numbers, to_row, to_playlist_id)
|
||||
self.active_model().move_rows_between_playlists(
|
||||
row_numbers, to_row, to_playlist_id
|
||||
)
|
||||
|
||||
def move_selected(self) -> None:
|
||||
"""
|
||||
@ -1017,69 +1022,25 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
def paste_rows(self) -> None:
|
||||
"""
|
||||
Paste earlier cut rows.
|
||||
|
||||
Process:
|
||||
- ensure we have some cut rows
|
||||
- if not pasting at end of playlist, move later rows down
|
||||
- update plrs with correct playlist and row
|
||||
- if moving between playlists: renumber source playlist rows
|
||||
- else: check integrity of playlist rows
|
||||
"""
|
||||
|
||||
if not self.selected_plrs:
|
||||
if self.move_source_rows is None or self.move_source_model is None:
|
||||
return
|
||||
|
||||
playlist_tab = self.active_tab()
|
||||
dst_playlist_id = playlist_tab.playlist_id
|
||||
dst_row = self.active_tab().get_new_row_number()
|
||||
to_playlist_id = self.active_tab().playlist_id
|
||||
selected_rows = self.active_tab().get_selected_rows()
|
||||
if selected_rows:
|
||||
destination_row = selected_rows[0]
|
||||
else:
|
||||
destination_row = self.active_model().rowCount()
|
||||
|
||||
with Session() as session:
|
||||
# Create space in destination playlist
|
||||
PlaylistRows.move_rows_down(
|
||||
session, dst_playlist_id, dst_row, len(self.selected_plrs)
|
||||
if to_playlist_id == self.move_source_model.playlist_id:
|
||||
self.move_source_model.move_rows(self.move_source_rows, destination_row)
|
||||
else:
|
||||
self.move_source_model.move_rows_between_playlists(
|
||||
self.move_source_rows, destination_row, to_playlist_id
|
||||
)
|
||||
session.commit()
|
||||
|
||||
# Update plrs
|
||||
row = dst_row
|
||||
src_playlist_id = None
|
||||
for plr in self.selected_plrs:
|
||||
# Update moved rows
|
||||
session.add(plr)
|
||||
if not src_playlist_id:
|
||||
src_playlist_id = plr.playlist_id
|
||||
plr.playlist_id = dst_playlist_id
|
||||
plr.plr_rownum = row
|
||||
row += 1
|
||||
|
||||
if not src_playlist_id:
|
||||
return
|
||||
|
||||
session.flush()
|
||||
|
||||
# Update display
|
||||
self.active_tab().populate_display(
|
||||
session, dst_playlist_id, scroll_to_top=False
|
||||
)
|
||||
|
||||
# If source playlist is not destination playlist, fixup row
|
||||
# numbers and update display
|
||||
if src_playlist_id != dst_playlist_id:
|
||||
PlaylistRows.fixup_rownumbers(session, src_playlist_id)
|
||||
# Update source playlist_tab if visible (if not visible, it
|
||||
# will be re-populated when it is opened)
|
||||
source_playlist_tab = None
|
||||
for tab in range(self.tabPlaylist.count()):
|
||||
if self.tabPlaylist.widget(tab).playlist_id == src_playlist_id:
|
||||
source_playlist_tab = self.tabPlaylist.widget(tab)
|
||||
break
|
||||
if source_playlist_tab:
|
||||
source_playlist_tab.populate_display(
|
||||
session, src_playlist_id, scroll_to_top=False
|
||||
)
|
||||
|
||||
# Reset so rows can't be repasted
|
||||
self.selected_plrs = None
|
||||
self.move_source_rows = self.move_source_model = None
|
||||
|
||||
def play_next(self, position: Optional[float] = None) -> None:
|
||||
"""
|
||||
|
||||
@ -366,7 +366,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
|
||||
PlaylistRows.fixup_rownumbers(session, self.playlist_id)
|
||||
self.refresh_data(session)
|
||||
self.update_track_times()
|
||||
self.row_order_changed(self.playlist_id)
|
||||
|
||||
def display_role(self, row: int, column: int, prd: PlaylistRowData) -> QVariant:
|
||||
"""
|
||||
@ -422,6 +422,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
with Session() as session:
|
||||
self.refresh_data(session)
|
||||
super().endResetModel()
|
||||
self.row_order_changed(self.playlist_id)
|
||||
|
||||
def get_duplicate_rows(self) -> List[int]:
|
||||
"""
|
||||
@ -702,7 +703,8 @@ class PlaylistModel(QAbstractTableModel):
|
||||
self.refresh_data(session)
|
||||
super().endInsertRows()
|
||||
|
||||
self.invalidate_rows(list(range(plr.plr_rownum, len(self.playlist_rows))))
|
||||
self.row_order_changed(self.playlist_id)
|
||||
self.invalidate_rows(list(range(plr.plr_rownum, len(self.playlist_rows))))
|
||||
|
||||
return plr
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user