Commit d47d8127 authored by Matěj Laitl's avatar Matěj Laitl
Browse files

Collection browser: don't add duplicate tracks in mimeData

That could have happened when you selected e.g. both album and a track
from that album -> the track would be added twice.

The implemented algorithm is done at QModelIntex level and is O(n)
where n is the number of selected tracks so this should be okay.

There is an unrelated bug with the Various Artists item that behaves
as entire collection when dragged. This will be fixed soon.

 * Don't add duplicates to playlist when dragging from collection

BUG: 254411
DIGEST: Bugfix: Amarok now doesn't add unwanted duplicates to playlist
parent 924a2bc8
......@@ -86,6 +86,7 @@ VERSION 2.6-Beta 1
"1.2 GB free" is shown instead of "85% used"; thicker capacity bar.
* Don't add duplicates to playlist when dragging from collection. (BR 254411)
* Fix crash related to DAAP collection. (BR 280774)
* Fix crash on startup related to Audio CD collection. (BR 256585)
* When turning dynamic playlist on, immediately populate playlist and clear
......@@ -399,14 +399,32 @@ CollectionTreeItemModelBase::mimeTypes() const
CollectionTreeItemModelBase::mimeData(const QModelIndexList & indices) const
CollectionTreeItemModelBase::mimeData( const QModelIndexList &indices ) const
if ( indices.isEmpty() )
return 0;
QList<CollectionTreeItem*> items;
// first, filter out duplicate entries that may arise when both parent and child are selected
QSet<QModelIndex> indexSet = QSet<QModelIndex>::fromList( indices );
QMutableSetIterator<QModelIndex> it( indexSet );
while( it.hasNext() )
// we go up in parent hierarchy searching whether some parent indices are already in set
QModelIndex parentIndex = it.value();
while( parentIndex.isValid() ) // leave the root (top, invalid) index intact
parentIndex = parentIndex.parent(); // yes, we start from the parent of current index
if( indexSet.contains( parentIndex ) )
it.remove(); // parent already in selected set, remove child
break; // no need to continue inner loop, already deleted
foreach( const QModelIndex &index, indices )
QList<CollectionTreeItem*> items;
foreach( const QModelIndex &index, indexSet )
if( index.isValid() )
items << static_cast<CollectionTreeItem*>( index.internalPointer() );
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment