Skip to content

Commit

Permalink
fixup! DEBUG Track move with Alt+Up/Down
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Apr 11, 2024
1 parent 1bdc1f4 commit c41be0a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,10 @@ void WTrackTableView::cutSelectedTracks() {
const QModelIndex newIndex = calculateCutIndex(currentIndex(), indices);
getTrackModel()->cutTracks(indices);
setCurrentIndex(newIndex);
qWarning() << " .";
qWarning() << " Cut. currIndex:" << currentIndex().row() + 1 << "/"
<< model()->rowCount();
qWarning() << " .";
}

void WTrackTableView::copySelectedTracks() {
Expand Down Expand Up @@ -971,6 +975,8 @@ void WTrackTableView::keyPressEvent(QKeyEvent* event) {
if ((event->key() == Qt::Key_Up || event->key() == Qt::Key_Down) &&
event->modifiers().testFlag(Qt::AltModifier) &&
pTrackModel->hasCapabilities(TrackModel::Capability::Reorder)) {
qWarning() << " .";
qWarning() << " Alt move";
// Move selection
QModelIndexList indices = getSelectedRows(true);
if (indices.isEmpty()) {
Expand All @@ -983,11 +989,18 @@ void WTrackTableView::keyPressEvent(QKeyEvent* event) {
int lastSelRow = indices.last().row();
int rowCount = model()->rowCount();
bool continuous = indices.length() == lastSelRow - firstSelRow + 1;
qWarning() << " rows:" << indices.length()
<< "[" << firstSelRow + 1 << "-" << lastSelRow + 1 << "]"
<< "continuous" << QString(continuous ? "YES" : "NO");
if (continuous &&
((up && firstSelRow == 0) || (down && lastSelRow == rowCount - 1))) {
// Continuous selection with no more rows to skip in the desired
// direction, further Up/Down would wrap around the current index.
// Ignore.
qWarning().noquote() << " (ignore move"
<< QString(up ? "Up" : "Down")
<< ": continuous selection already at"
<< QString(up ? "top" : "botom");
return;
}

Expand All @@ -1003,20 +1016,29 @@ void WTrackTableView::keyPressEvent(QKeyEvent* event) {
// With currentIndex in the last row, Down would wrap around to first row
// and we'd paste at the top which is not the intention.
// Invalidate the paste index in order to move the selection to the end.
qWarning() << " non-cont at end + Down: ignore, paste at end";
pasteIndex = pasteIndex.siblingAtRow(-1);
} else if (continuous) {
// Continuous selection with rows above/below: move
QTableView::keyPressEvent(event);
pasteIndex = currentIndex();
qWarning() << " cont with rows above/below: move to" << pasteIndex.row() + 1;
} else if (up) {
// non-continuous:
// Up shall consolidate selection at firstSelRow first, then move.
qWarning() << " non-cont Up, pasteIndex:" << pasteIndex.row() + 1;
pasteIndex = pasteIndex.siblingAtRow(firstSelRow);
qWarning() << " >> mod. pasteIndex:" << pasteIndex.row() + 1;
} else { // Key_Down
// Down shall consolidate selection at lastSelRow first, then move.
// How many tracks below end of selection?
int prevDist = rowCount - lastSelRow - 1;
qWarning() << " non-cont Down, pasteIndex:" << pasteIndex.row() + 1;
qWarning() << " prev dist to bottom:" << prevDist;
pasteIndex = pasteIndex.siblingAtRow(model()->rowCount() - prevDist);
qWarning() << " >> mod. pasteIndex:"
<< pasteIndex.row() + 1 << "/"
<< model()->rowCount();
}

pasteTracks(pasteIndex);
Expand Down

0 comments on commit c41be0a

Please sign in to comment.