mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-28 10:30:38 +01:00
Merge pull request #4204 from abika/master
correct selection after removing rows in playlist
This commit is contained in:
commit
858cfce9ff
@ -576,10 +576,9 @@ void PlaylistView::keyPressEvent(QKeyEvent* event) {
|
|||||||
} else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
|
} else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
|
||||||
if (currentIndex().isValid()) emit PlayItem(currentIndex());
|
if (currentIndex().isValid()) emit PlayItem(currentIndex());
|
||||||
event->accept();
|
event->accept();
|
||||||
} else if (event->modifiers() !=
|
} else if (event->modifiers() != Qt::ControlModifier // Ctrl+Space selects
|
||||||
Qt::ControlModifier // Ctrl+Space selects the item
|
// the item
|
||||||
&&
|
&& event->key() == Qt::Key_Space) {
|
||||||
event->key() == Qt::Key_Space) {
|
|
||||||
emit PlayPause();
|
emit PlayPause();
|
||||||
event->accept();
|
event->accept();
|
||||||
} else if (event->key() == Qt::Key_Left) {
|
} else if (event->key() == Qt::Key_Left) {
|
||||||
@ -615,15 +614,15 @@ void PlaylistView::RemoveSelected() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store the last selected row, which is the last in the list
|
||||||
|
int last_row = selection.last().top();
|
||||||
|
|
||||||
// Sort the selection so we remove the items at the *bottom* first, ensuring
|
// Sort the selection so we remove the items at the *bottom* first, ensuring
|
||||||
// we don't have to mess around with changing row numbers
|
// we don't have to mess around with changing row numbers
|
||||||
qSort(selection.begin(), selection.end(), CompareSelectionRanges);
|
qSort(selection.begin(), selection.end(), CompareSelectionRanges);
|
||||||
|
|
||||||
// Store the last selected row, which is the first in the list
|
|
||||||
int last_row = selection.first().bottom();
|
|
||||||
|
|
||||||
for (const QItemSelectionRange& range : selection) {
|
for (const QItemSelectionRange& range : selection) {
|
||||||
rows_removed += range.height();
|
if (range.top() < last_row) rows_removed += range.height();
|
||||||
model()->removeRows(range.top(), range.height(), range.parent());
|
model()->removeRows(range.top(), range.height(), range.parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,22 +633,19 @@ void PlaylistView::RemoveSelected() {
|
|||||||
// Select the new current item, we want always the item after the last
|
// Select the new current item, we want always the item after the last
|
||||||
// selected
|
// selected
|
||||||
if (new_index.isValid()) {
|
if (new_index.isValid()) {
|
||||||
// Update visual selection with the entire row
|
// Workaround to update keyboard selected row, if it's not the first row
|
||||||
selectionModel()->select(
|
// (this also triggers selection)
|
||||||
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)
|
if (new_row != 0)
|
||||||
keyPressEvent(
|
keyPressEvent(
|
||||||
new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier));
|
new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier));
|
||||||
|
// Update visual selection with the entire row
|
||||||
|
selectionModel()->select(new_index, QItemSelectionModel::ClearAndSelect |
|
||||||
|
QItemSelectionModel::Rows);
|
||||||
} else {
|
} else {
|
||||||
// We're removing the last item, select the new last row
|
// We're removing the last item, select the new last row
|
||||||
selectionModel()->select(
|
selectionModel()->select(
|
||||||
QItemSelection(model()->index(model()->rowCount() - 1, 0),
|
model()->index(model()->rowCount() - 1, 0),
|
||||||
model()->index(model()->rowCount() - 1,
|
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||||
model()->columnCount() - 1)),
|
|
||||||
QItemSelectionModel::Select);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user