diff --git a/app/musicmuster.py b/app/musicmuster.py index 1b11e02..e1d12f0 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -1022,18 +1022,18 @@ class Window(QMainWindow, Ui_MainWindow): if self.move_source_rows is None or self.move_source_model is None: return - to_playlist_id = self.active_tab().playlist_id + to_playlist_model = self.active_tab().data_model selected_rows = self.active_tab().get_selected_rows() if selected_rows: destination_row = selected_rows[0] else: destination_row = self.active_model().rowCount() - if to_playlist_id == self.move_source_model.data_model.playlist_id: + if to_playlist_model.playlist_id == self.move_source_model.data_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 + self.move_source_rows, destination_row, to_playlist_model ) self.move_source_rows = self.move_source_model = None diff --git a/app/playlistmodel.py b/app/playlistmodel.py index 6d2b886..115e68e 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -1,3 +1,5 @@ +# Allow forward reference to PlaylistModel +from __future__ import annotations import obsws_python as obs # type: ignore import re from dataclasses import dataclass @@ -718,6 +720,14 @@ class PlaylistModel(QAbstractTableModel): new_row_number = self._get_new_row_number(proposed_row_number) + # We need to check for header rows at and below where we are + # inserting a row and reset column spanning. + for row_number in range(new_row_number, len(self.playlist_rows)): + if self.is_header_row(row_number): + self.signals.span_cells_signal.emit( + self.playlist_id, row_number, HEADER_NOTES_COLUMN, 1, 1 + ) + with Session() as session: super().beginInsertRows(QModelIndex(), new_row_number, new_row_number) plr = PlaylistRows.insert_row(session, self.playlist_id, new_row_number) @@ -779,6 +789,21 @@ class PlaylistModel(QAbstractTableModel): return None + def mark_unplayed(self, row_numbers: List[int]) -> None: + """ + Mark row as unplayed + """ + + with Session() as session: + for row_number in row_numbers: + plr = session.get(PlaylistRows, self.playlist_rows[row_number].plrid) + if not plr: + return + plr.played = False + self.refresh_row(session, row_number) + + self.invalidate_rows(row_numbers) + def move_rows(self, from_rows: List[int], to_row_number: int) -> None: """ Move the playlist rows given to to_row and below. @@ -846,28 +871,15 @@ class PlaylistModel(QAbstractTableModel): self.reset_track_sequence_row_numbers() self.invalidate_rows(list(row_map.keys())) - def mark_unplayed(self, row_numbers: List[int]) -> None: - """ - Mark row as unplayed - """ - - with Session() as session: - for row_number in row_numbers: - plr = session.get(PlaylistRows, self.playlist_rows[row_number].plrid) - if not plr: - return - plr.played = False - self.refresh_row(session, row_number) - - self.invalidate_rows(row_numbers) - def move_rows_between_playlists( - self, from_rows: List[int], to_row_number: int, to_playlist_id: int + self, from_rows: List[int], to_row_number: int, to_playlist_model: PlaylistModel ) -> None: """ Move the playlist rows given to to_row and below of to_playlist. """ + to_playlist_id = to_playlist_model.playlist_id + # Row removal must be wrapped in beginRemoveRows .. # endRemoveRows and the row range must be contiguous. Process # the highest rows first so the lower row numbers are unchanged @@ -886,6 +898,14 @@ class PlaylistModel(QAbstractTableModel): max_destination_row_number and to_row_number <= max_destination_row_number ): + # Move the destination playlist rows down to make room. + # If any of the rows moving are header rows, reset the + # column spanning. + for row_number in range(to_row_number, to_row_number + len(from_rows)): + if to_playlist_model.is_header_row(row_number): + self.signals.span_cells_signal.emit( + to_playlist_id, row_number, HEADER_NOTES_COLUMN, 1, 1 + ) PlaylistRows.move_rows_down( session, to_playlist_id, to_row_number, len(from_rows) ) diff --git a/test_playlistmodel.py b/test_playlistmodel.py index 16ca91e..c1b09cc 100644 --- a/test_playlistmodel.py +++ b/test_playlistmodel.py @@ -303,7 +303,7 @@ def test_move_one_row_between_playlists_to_end(monkeypatch, session): model_src = create_model_with_playlist_rows(session, create_rowcount, name="source") model_dst = create_model_with_playlist_rows(session, create_rowcount, name="destination") - model_src.move_rows_between_playlists(from_rows, to_row, model_dst.playlist_id) + model_src.move_rows_between_playlists(from_rows, to_row, model_dst) model_dst.refresh_data(session) assert len(model_src.playlist_rows) == create_rowcount - len(from_rows) @@ -323,7 +323,7 @@ def test_move_one_row_between_playlists_to_middle(monkeypatch, session): model_src = create_model_with_playlist_rows(session, create_rowcount, name="source") model_dst = create_model_with_playlist_rows(session, create_rowcount, name="destination") - model_src.move_rows_between_playlists(from_rows, to_row, model_dst.playlist_id) + model_src.move_rows_between_playlists(from_rows, to_row, model_dst) model_dst.refresh_data(session) # Check the rows of the destination model @@ -347,7 +347,7 @@ def test_move_multiple_rows_between_playlists_to_end(monkeypatch, session): model_src = create_model_with_playlist_rows(session, create_rowcount, name="source") model_dst = create_model_with_playlist_rows(session, create_rowcount, name="destination") - model_src.move_rows_between_playlists(from_rows, to_row, model_dst.playlist_id) + model_src.move_rows_between_playlists(from_rows, to_row, model_dst) model_dst.refresh_data(session) # Check the rows of the destination model