Commit 74d4a589 authored by jpd's avatar jpd
Browse files

Qt: simplify selected item deletion in playlist model

parent a99d1a2c
...@@ -757,18 +757,22 @@ void PLModel::doDelete( QModelIndexList selected ) ...@@ -757,18 +757,22 @@ void PLModel::doDelete( QModelIndexList selected )
{ {
if( !canEdit() ) return; if( !canEdit() ) return;
for( int i = selected.size() -1 ; i >= 0; i-- ) while( !selected.isEmpty() )
{ {
QModelIndex index = selected[i]; QModelIndex index = selected[0];
selected.removeAt( 0 );
if( index.column() != 0 ) continue; if( index.column() != 0 ) continue;
PLItem *item = getItem( index ); PLItem *item = getItem( index );
if( item ) if( item->children.size() )
{ recurseDelete( item->children, &selected );
if( item->children.size() )
recurseDelete( item->children, &selected ); PL_LOCK;
doDeleteItem( item, &selected ); playlist_DeleteFromInput( p_playlist, item->p_input, pl_Locked );
} PL_UNLOCK;
if( i > selected.size() ) i = selected.size();
removeItem( item );
} }
} }
...@@ -779,29 +783,10 @@ void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList ...@@ -779,29 +783,10 @@ void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList
PLItem *item = children[i]; PLItem *item = children[i];
if( item->children.size() ) if( item->children.size() )
recurseDelete( item->children, fullList ); recurseDelete( item->children, fullList );
doDeleteItem( item, fullList ); fullList->removeAll( index( item, 0 ) );
} }
} }
void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
{
QModelIndex deleteIndex = index( item, 0 );
fullList->removeAll( deleteIndex );
PL_LOCK;
playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
if( !p_item )
{
PL_UNLOCK;
return;
}
playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
PL_UNLOCK;
/* And finally, remove it from the tree */
removeItem( item );
}
/******* Volume III: Sorting and searching ********/ /******* Volume III: Sorting and searching ********/
void PLModel::sort( int column, Qt::SortOrder order ) void PLModel::sort( int column, Qt::SortOrder order )
{ {
......
...@@ -120,7 +120,6 @@ private: ...@@ -120,7 +120,6 @@ private:
/* Actions */ /* Actions */
void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList ); void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
void doDeleteItem( PLItem *item, QModelIndexList *fullList );
void updateTreeItem( PLItem * ); void updateTreeItem( PLItem * );
void removeItem ( PLItem * ); void removeItem ( PLItem * );
void takeItem( PLItem * ); //will not delete item void takeItem( PLItem * ); //will not delete item
......
Markdown is supported
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