Fix moving of timing starts and subtotals

This commit is contained in:
Keith Edmunds 2023-10-20 13:07:30 +01:00
parent 48d26d80df
commit ab8da0a312

View File

@ -249,18 +249,30 @@ class PlaylistTab(QTableWidget):
else:
rowMapping[row + len(rows)] = targetRow + idx
colCount = self.columnCount()
for srcRow, tgtRow in sorted(rowMapping.items()):
if self._get_row_track_id(srcRow):
# This is a track row
with Session() as session:
for srcRow, tgtRow in sorted(rowMapping.items()):
# Messy: will be fixed with model/view implementation.
# If we just move the row, the displayed text will be
# used. That is incorrect for timing starts, ends and
# subtotals, so take text from database and use that.
is_header_row = self._get_row_track_id(srcRow) == 0
if is_header_row:
# This is a header row so save original text from db
source_plr = self._get_row_plr(session, srcRow)
if not source_plr:
print("Can't get source_plr in playlists:dropEvent()")
return
note_text = source_plr.note
# Copy to new locations
for col in range(0, colCount):
self.setItem(tgtRow, col, self.takeItem(srcRow, col))
else:
self.setItem(
tgtRow,
HEADER_NOTES_COLUMN,
self.takeItem(srcRow, HEADER_NOTES_COLUMN),
)
self.setSpan(tgtRow, HEADER_NOTES_COLUMN, 1, len(columns) - 1)
# Fixup header text
if is_header_row:
target_item = self.item(tgtRow, HEADER_NOTES_COLUMN)
if target_item:
target_item.setText(note_text)
self.setSpan(tgtRow, HEADER_NOTES_COLUMN, 1, len(columns) - 1)
for row in reversed(sorted(rowMapping.keys())):
self.removeRow(row)
self.resizeRowsToContents()