When deleting items in playlist, select the next one. Fixes issue 1279
This commit is contained in:
parent
012eeee46a
commit
9a31eb7fd4
|
@ -470,22 +470,39 @@ void PlaylistView::contextMenuEvent(QContextMenuEvent* e) {
|
|||
}
|
||||
|
||||
void PlaylistView::RemoveSelected() {
|
||||
int rows_removed = 0;
|
||||
QItemSelection selection(selectionModel()->selection());
|
||||
|
||||
// Sort the selection so we remove the items at the *bottom* first, ensuring
|
||||
// we don't have to mess around with changing row numbers
|
||||
qSort(selection.begin(), selection.end(), CompareSelectionRanges);
|
||||
|
||||
// Store the last selected row, which is the first in the list
|
||||
int last_row = selection.first().bottom();
|
||||
|
||||
foreach (const QItemSelectionRange& range, selection) {
|
||||
rows_removed += range.height();
|
||||
model()->removeRows(range.top(), range.height(), range.parent());
|
||||
}
|
||||
|
||||
// Select the new current item
|
||||
if (currentIndex().isValid())
|
||||
selectionModel()->select(
|
||||
QItemSelection(currentIndex().sibling(currentIndex().row(), 0),
|
||||
currentIndex().sibling(currentIndex().row(), model()->columnCount()-1)),
|
||||
QItemSelectionModel::Select);
|
||||
int new_row = last_row-rows_removed+1;
|
||||
// Index of the first column for the row to select
|
||||
QModelIndex new_index = model()->index(new_row, 0);
|
||||
|
||||
// Select the new current item, we want always the item after the last selected
|
||||
if (new_index.isValid()) {
|
||||
// Update visual selection with the entire row
|
||||
selectionModel()->select(QItemSelection(new_index, model()->index(new_row, model()->columnCount()-1)),
|
||||
QItemSelectionModel::Select);
|
||||
// Update keyboard selected row, if it's not the first row
|
||||
if (new_row != 0)
|
||||
keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier));
|
||||
} else {
|
||||
// We're removing the last item, select the new last row
|
||||
selectionModel()->select(QItemSelection(model()->index(model()->rowCount()-1, 0),
|
||||
model()->index(model()->rowCount()-1, model()->columnCount()-1)),
|
||||
QItemSelectionModel::Select);
|
||||
}
|
||||
}
|
||||
|
||||
QList<int> PlaylistView::GetEditableColumns() {
|
||||
|
|
Loading…
Reference in New Issue