From 74d4a589a628631de88cce97a52135757380367c Mon Sep 17 00:00:00 2001 From: Jakob Leben Date: Wed, 10 Feb 2010 09:48:49 +0100 Subject: [PATCH] Qt: simplify selected item deletion in playlist model --- .../components/playlist/playlist_model.cpp | 43 ++++++------------- .../components/playlist/playlist_model.hpp | 1 - 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp index 8ef12357f2..742c58cc93 100644 --- a/modules/gui/qt4/components/playlist/playlist_model.cpp +++ b/modules/gui/qt4/components/playlist/playlist_model.cpp @@ -757,18 +757,22 @@ void PLModel::doDelete( QModelIndexList selected ) { 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; + PLItem *item = getItem( index ); - if( item ) - { - if( item->children.size() ) - recurseDelete( item->children, &selected ); - doDeleteItem( item, &selected ); - } - if( i > selected.size() ) i = selected.size(); + if( item->children.size() ) + recurseDelete( item->children, &selected ); + + PL_LOCK; + playlist_DeleteFromInput( p_playlist, item->p_input, pl_Locked ); + PL_UNLOCK; + + removeItem( item ); } } @@ -779,29 +783,10 @@ void PLModel::recurseDelete( QList children, QModelIndexList *fullList PLItem *item = children[i]; if( item->children.size() ) 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 ********/ void PLModel::sort( int column, Qt::SortOrder order ) { diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp index cb5e68c3e0..67c8726ac6 100644 --- a/modules/gui/qt4/components/playlist/playlist_model.hpp +++ b/modules/gui/qt4/components/playlist/playlist_model.hpp @@ -120,7 +120,6 @@ private: /* Actions */ void recurseDelete( QList children, QModelIndexList *fullList ); - void doDeleteItem( PLItem *item, QModelIndexList *fullList ); void updateTreeItem( PLItem * ); void removeItem ( PLItem * ); void takeItem( PLItem * ); //will not delete item -- 2.39.2