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