Skip to content

Commit

Permalink
fixup! Playlists: move tracks with Alt + Up/Down/PageUp/PageDown/Home…
Browse files Browse the repository at this point in the history
…/End
  • Loading branch information
ronso0 committed Apr 15, 2024
1 parent 56aca5e commit 7305d1b
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,8 @@ void WTrackTableView::moveRows(QList<int> selectedRowsIn, int destRow) {
// Sorting the indices first means we don't have to worry about this.
QList<int> selectedRows = std::move(selectedRowsIn);

// An invalid destination row means we're supposed to move the selection to the end.
// Happens when we drop tracks into the void below the last track.
destRow = destRow < 0 ? model()->rowCount() : destRow;
// Required for refocusing the correct column and restoring the selection
// after we moved. Use 0 if the index is invalid for some reason.
Expand All @@ -887,20 +889,19 @@ void WTrackTableView::moveRows(QList<int> selectedRowsIn, int destRow) {

// Adjust first row of new selection
if (destRow >= firstSelRow && destRow <= lastSelRow) {
bool continuous = selectedRowCount == lastSelRow - firstSelRow + 1;
qWarning() << " destRow in selection, cont:" << QString(continuous ? "YES" : "NO");
// If we drag a contiguous selection of multiple tracks and drop them
// somewhere inside that same selection, we obviously have nothing to do.
// This is also a good way to abort accidental drags.
if (continuous) {
// Destination is inside the selection.
if (selectedRowCount == lastSelRow - firstSelRow + 1) {
// If we drag a contiguous selection of multiple tracks and drop them
// somewhere inside that same selection, we obviously have nothing to do.
// This is also a good way to abort accidental drags.
return;
}
// Non-continuous selection:
// consolidate selection at firstSelRow
if (destRow == firstSelRow) {
// Consolidate selection at first selected row.
// Remove consecutive rows (they are already in place) until we find
// the first gap in the selection.
// Use the reow after that continuous part of the selection as destination.
// Use the row after that continuous part as destination.
while (destRow == firstSelRow) {
selectedRows.removeFirst();
firstSelRow = selectedRows.first();
Expand All @@ -912,14 +913,14 @@ void WTrackTableView::moveRows(QList<int> selectedRowsIn, int destRow) {
}

if (destRow < firstSelRow) {
// If we're moving the tracks _up_, reverse the order of the row selection
// If we're moving the tracks UP, reverse the order of the row selection
// to make the algorithm below work as it is
std::sort(selectedRows.begin(),
selectedRows.end(),
std::greater<int>());
} else {
} else { // Down
if (destRow > lastSelRow) {
// If we're moving the tracks _down_, adjust the first row to reselect
// If we're moving the tracks DOWN, adjust the first row to reselect
selectionRestoreStartRow =
selectionRestoreStartRow - selectedRowCount;
}
Expand All @@ -944,8 +945,6 @@ void WTrackTableView::moveRows(QList<int> selectedRowsIn, int destRow) {
}
}

// TODO Try to make all moved rows visible?

// Set current index.
// TODO If we moved down, pick the last selected row?
// int idxRow = destRow < firstSelRow
Expand All @@ -958,7 +957,7 @@ void WTrackTableView::moveRows(QList<int> selectedRowsIn, int destRow) {
QItemSelectionModel::SelectCurrent | QItemSelectionModel::Select);
}

// Highlight the moved rows again (restoring the selection)
// Select the moved rows (restore previous selection)
for (int i = 0; i < selectedRowCount; i++) {
selectionModel()->select(model()->index(selectionRestoreStartRow + i, idxCol),
QItemSelectionModel::Select | QItemSelectionModel::Rows);
Expand Down

0 comments on commit 7305d1b

Please sign in to comment.