Preserve row order when moving rows
This commit is contained in:
parent
7cfd2a45a2
commit
4c420d01ca
@ -831,26 +831,27 @@ class PlaylistModel(QAbstractTableModel):
|
||||
# endRemoveRows and the row range must be contiguous. Process
|
||||
# the highest rows first so the lower row numbers are unchanged
|
||||
row_groups = self._reversed_contiguous_row_groups(from_rows)
|
||||
next_to_row = to_row_number
|
||||
|
||||
# Prepare destination playlist for a reset
|
||||
self.signals.begin_reset_model_signal.emit(to_playlist_id)
|
||||
|
||||
with db.Session() as session:
|
||||
# Make room in destination playlist
|
||||
max_destination_row_number = PlaylistRows.get_last_used_row(
|
||||
session, to_playlist_id
|
||||
)
|
||||
if (
|
||||
max_destination_row_number
|
||||
and to_row_number <= max_destination_row_number
|
||||
):
|
||||
# Move the destination playlist rows down to make room.
|
||||
PlaylistRows.move_rows_down(
|
||||
session, to_playlist_id, to_row_number, len(from_rows)
|
||||
)
|
||||
|
||||
for row_group in row_groups:
|
||||
# Make room in destination playlist
|
||||
max_destination_row_number = PlaylistRows.get_last_used_row(
|
||||
session, to_playlist_id
|
||||
)
|
||||
if (
|
||||
max_destination_row_number
|
||||
and to_row_number <= max_destination_row_number
|
||||
):
|
||||
# Move the destination playlist rows down to make room.
|
||||
PlaylistRows.move_rows_down(
|
||||
session, to_playlist_id, to_row_number, len(row_group)
|
||||
)
|
||||
next_to_row = to_row_number
|
||||
|
||||
super().beginRemoveRows(QModelIndex(), min(row_group), max(row_group))
|
||||
for playlist_row in PlaylistRows.plrids_to_plrs(
|
||||
session,
|
||||
|
||||
@ -387,9 +387,9 @@ class TestMMMiscRowMove(unittest.TestCase):
|
||||
assert [int(a) for a in row_notes] == [
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
3,
|
||||
4,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user