mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-15 10:48:33 +01:00
Fix persistent indexes when rearranging the playlist
This commit is contained in:
parent
d9727f2731
commit
8da8b04813
@ -182,11 +182,25 @@ bool Playlist::dropMimeData(const QMimeData* data, Qt::DropAction action, int ro
|
|||||||
const int start = row == -1 ? items_.count() : row;
|
const int start = row == -1 ? items_.count() : row;
|
||||||
for (int i=start ; i<start+moved_items.count() ; ++i) {
|
for (int i=start ; i<start+moved_items.count() ; ++i) {
|
||||||
items_.insert(i, moved_items[i - start]);
|
items_.insert(i, moved_items[i - start]);
|
||||||
|
}
|
||||||
|
|
||||||
// Update persistent indexes
|
// Update persistent indexes
|
||||||
for (int column=0 ; column<ColumnCount ; ++column)
|
foreach (const QModelIndex& pidx, persistentIndexList()) {
|
||||||
changePersistentIndex(index(source_rows[i-start], column, QModelIndex()),
|
const int dest_offset = source_rows.indexOf(pidx.row());
|
||||||
index(i, column, QModelIndex()));
|
if (dest_offset != -1) {
|
||||||
|
// This index was moved
|
||||||
|
changePersistentIndex(pidx, index(start + dest_offset, pidx.column(), QModelIndex()));
|
||||||
|
} else {
|
||||||
|
int d = 0;
|
||||||
|
foreach (int source_row, source_rows) {
|
||||||
|
if (pidx.row() > source_row)
|
||||||
|
d --;
|
||||||
|
}
|
||||||
|
if (pidx.row() + d >= start)
|
||||||
|
d += source_rows.count();
|
||||||
|
|
||||||
|
changePersistentIndex(pidx, index(pidx.row() + d, pidx.column(), QModelIndex()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutChanged();
|
layoutChanged();
|
||||||
|
Loading…
Reference in New Issue
Block a user