Move rows works.
This commit is contained in:
parent
444c3e4fb4
commit
647e7d478a
@ -797,6 +797,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
# Identify destination playlist
|
# Identify destination playlist
|
||||||
visible_tab = self.visible_playlist_tab()
|
visible_tab = self.visible_playlist_tab()
|
||||||
source_playlist = visible_tab.playlist_id
|
source_playlist = visible_tab.playlist_id
|
||||||
|
|
||||||
|
# Get destination playlist id
|
||||||
playlists = []
|
playlists = []
|
||||||
for playlist in Playlists.get_all(session):
|
for playlist in Playlists.get_all(session):
|
||||||
if playlist.id == source_playlist:
|
if playlist.id == source_playlist:
|
||||||
@ -804,17 +806,17 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
else:
|
else:
|
||||||
playlists.append(playlist)
|
playlists.append(playlist)
|
||||||
|
|
||||||
# Get destination playlist id
|
|
||||||
dlg = SelectPlaylistDialog(self, playlists=playlists, session=session)
|
dlg = SelectPlaylistDialog(self, playlists=playlists, session=session)
|
||||||
dlg.exec()
|
dlg.exec()
|
||||||
if not dlg.playlist:
|
if not dlg.playlist:
|
||||||
return
|
return
|
||||||
destination_playlist_id = dlg.playlist.id
|
destination_playlist_id = dlg.playlist.id
|
||||||
|
|
||||||
# Remove moved rows from display
|
# Remove moved rows from display and save
|
||||||
visible_tab.remove_rows([plr.row_number for plr in playlistrows])
|
visible_tab.remove_rows([plr.row_number for plr in playlistrows])
|
||||||
|
visible_tab.save_playlist(session)
|
||||||
|
|
||||||
# Update playlist for the rows in the database
|
# Update destination playlist in the database
|
||||||
last_row = PlaylistRows.get_last_used_row(session,
|
last_row = PlaylistRows.get_last_used_row(session,
|
||||||
destination_playlist_id)
|
destination_playlist_id)
|
||||||
if last_row is not None:
|
if last_row is not None:
|
||||||
@ -836,7 +838,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
destination_playlist_tab = self.tabPlaylist.widget(tab)
|
destination_playlist_tab = self.tabPlaylist.widget(tab)
|
||||||
break
|
break
|
||||||
if destination_playlist_tab:
|
if destination_playlist_tab:
|
||||||
destination_playlist_tab.populate(session, dlg.playlist.id)
|
destination_playlist_tab.populate_display(session, dlg.playlist.id)
|
||||||
|
|
||||||
def move_selected(self) -> None:
|
def move_selected(self) -> None:
|
||||||
"""
|
"""
|
||||||
@ -918,17 +920,17 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
playlist_tab = self.visible_playlist_tab()
|
playlist_tab = self.visible_playlist_tab()
|
||||||
dst_playlist_id = playlist_tab.playlist_id
|
dst_playlist_id = playlist_tab.playlist_id
|
||||||
|
dst_row = self.visible_playlist_tab().get_new_row_number()
|
||||||
|
|
||||||
with Session() as session:
|
with Session() as session:
|
||||||
# Create space in destination playlist
|
# Create space in destination playlist
|
||||||
if playlist_tab.selectionModel().hasSelection():
|
PlaylistRows.move_rows_down(session, dst_playlist_id,
|
||||||
row = playlist_tab.currentRow()
|
dst_row, len(self.selected_plrs))
|
||||||
PlaylistRows.move_rows_down(session, dst_playlist_id,
|
session.commit()
|
||||||
row, len(self.selected_plrs))
|
|
||||||
session.commit()
|
|
||||||
|
|
||||||
|
# Update plrs
|
||||||
|
row = dst_row
|
||||||
src_playlist_id = None
|
src_playlist_id = None
|
||||||
dst_row = row
|
|
||||||
for plr in self.selected_plrs:
|
for plr in self.selected_plrs:
|
||||||
# Update moved rows
|
# Update moved rows
|
||||||
session.add(plr)
|
session.add(plr)
|
||||||
@ -941,8 +943,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
# Update display
|
# Update display
|
||||||
self.visible_playlist_tab().populate(session, dst_playlist_id,
|
self.visible_playlist_tab().populate_display(
|
||||||
scroll_to_top=False)
|
session, dst_playlist_id, scroll_to_top=False)
|
||||||
|
|
||||||
# If source playlist is not destination playlist, fixup row
|
# If source playlist is not destination playlist, fixup row
|
||||||
# numbers and update display
|
# numbers and update display
|
||||||
@ -957,8 +959,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
source_playlist_tab = self.tabPlaylist.widget(tab)
|
source_playlist_tab = self.tabPlaylist.widget(tab)
|
||||||
break
|
break
|
||||||
if source_playlist_tab:
|
if source_playlist_tab:
|
||||||
source_playlist_tab.populate(session, src_playlist_id,
|
source_playlist_tab.populate_display(
|
||||||
scroll_to_top=False)
|
session, src_playlist_id, scroll_to_top=False)
|
||||||
|
|
||||||
# Reset so rows can't be repasted
|
# Reset so rows can't be repasted
|
||||||
self.selected_plrs = None
|
self.selected_plrs = None
|
||||||
|
|||||||
@ -557,6 +557,17 @@ class PlaylistTab(QTableWidget):
|
|||||||
self.clearSelection()
|
self.clearSelection()
|
||||||
self.setDragEnabled(False)
|
self.setDragEnabled(False)
|
||||||
|
|
||||||
|
def get_new_row_number(self) -> int:
|
||||||
|
"""
|
||||||
|
Return the selected row or the row count if no row selected
|
||||||
|
(ie, new row will be appended)
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.selectionModel().hasSelection():
|
||||||
|
return self.currentRow()
|
||||||
|
else:
|
||||||
|
return self.rowCount()
|
||||||
|
|
||||||
def get_selected_playlistrow_ids(self) -> Optional[List]:
|
def get_selected_playlistrow_ids(self) -> Optional[List]:
|
||||||
"""
|
"""
|
||||||
Return a list of PlaylistRow ids of the selected rows
|
Return a list of PlaylistRow ids of the selected rows
|
||||||
@ -1607,6 +1618,20 @@ class PlaylistTab(QTableWidget):
|
|||||||
new_metadata = self._meta_get(row) | (1 << attribute)
|
new_metadata = self._meta_get(row) | (1 << attribute)
|
||||||
self.item(row, USERDATA).setData(self.ROW_FLAGS, new_metadata)
|
self.item(row, USERDATA).setData(self.ROW_FLAGS, new_metadata)
|
||||||
|
|
||||||
|
def _move_row(self, session: Session, plr: PlaylistRows,
|
||||||
|
new_row_number: int) -> None:
|
||||||
|
"""Move playlist row to new_row_number using parent copy/paste"""
|
||||||
|
|
||||||
|
# Remove source row
|
||||||
|
self.removeRow(plr.row_number)
|
||||||
|
# Fixup plr row number
|
||||||
|
if plr.row_number < new_row_number:
|
||||||
|
plr.row_number = new_row_number - 1
|
||||||
|
else:
|
||||||
|
plr.row_number = new_row_number
|
||||||
|
self.insert_row(session, plr)
|
||||||
|
self.save_playlist(session)
|
||||||
|
|
||||||
def _mplayer_play(self, track_id: int) -> None:
|
def _mplayer_play(self, track_id: int) -> None:
|
||||||
"""Play track with mplayer"""
|
"""Play track with mplayer"""
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user