Merge pull request #4204 from abika/master

correct selection after removing rows in playlist
This commit is contained in:
John Maguire 2014-02-11 15:49:42 +01:00
commit 858cfce9ff
1 changed files with 14 additions and 18 deletions

View File

@ -576,10 +576,9 @@ void PlaylistView::keyPressEvent(QKeyEvent* event) {
} else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
if (currentIndex().isValid()) emit PlayItem(currentIndex());
event->accept();
} else if (event->modifiers() !=
Qt::ControlModifier // Ctrl+Space selects the item
&&
event->key() == Qt::Key_Space) {
} else if (event->modifiers() != Qt::ControlModifier // Ctrl+Space selects
// the item
&& event->key() == Qt::Key_Space) {
emit PlayPause();
event->accept();
} else if (event->key() == Qt::Key_Left) {
@ -615,15 +614,15 @@ void PlaylistView::RemoveSelected() {
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
// 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();
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());
}
@ -634,22 +633,19 @@ void PlaylistView::RemoveSelected() {
// 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
// Workaround to update keyboard selected row, if it's not the first row
// (this also triggers selection)
if (new_row != 0)
keyPressEvent(
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 {
// 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);
model()->index(model()->rowCount() - 1, 0),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
}
}