]> git.sesse.net Git - vlc/commitdiff
qt4: move item removal from PLItem to PLModel...
authorJakob Leben <jleben@videolan.org>
Wed, 19 Aug 2009 12:13:46 +0000 (14:13 +0200)
committerJakob Leben <jleben@videolan.org>
Wed, 19 Aug 2009 12:13:46 +0000 (14:13 +0200)
...and fix memleak when removing..

modules/gui/qt4/components/playlist/playlist_item.cpp
modules/gui/qt4/components/playlist/playlist_item.hpp
modules/gui/qt4/components/playlist/playlist_model.cpp
modules/gui/qt4/components/playlist/playlist_model.hpp

index eb4c88f9121b4701532fda1325585dc15978fca0..ab223bf6e68efeead5cfff7eb7e976a5c9b577ad 100644 (file)
@@ -84,15 +84,6 @@ void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
     children.insert( i_pos, item );
 }
 
-void PLItem::remove( PLItem *removed, int i_depth )
-{
-    if( i_depth == 1 /* DEPTH_SEL */ || parentItem )
-    {
-        int i_index = parentItem->children.indexOf( removed );
-        parentItem->children.removeAt( i_index );
-    }
-}
-
 /* This function is used to get one's parent's row number in the model */
 int PLItem::row() const
 {
index 891e036945e8054a68c1055191e727e6972635a4..0ff3f2d51f893f37ec5b26d6565aaafdcf324f6f 100644 (file)
@@ -47,8 +47,6 @@ public:
         children.insert( children.count(), item );
     };
 
-    void remove( PLItem *removed, int i_depth );
-
     PLItem *child( int row ) { return children.value( row ); };
     int childCount() const { return children.count(); };
 
index 89bddb6ac2a6f7d3616cffdc400059719e332697..30f4c6023ed27475a488d983e9189784461d4105 100644 (file)
@@ -289,8 +289,7 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
 void PLModel::removeItem( int i_id )
 {
     PLItem *item = FindById( rootItem, i_id );
-    if( currentItem && item && currentItem->p_input == item->p_input ) currentItem = NULL;
-    if( item ) item->remove( item, i_depth );
+    RemoveItem( item );
 }
 
 /* callbacks and slots */
@@ -756,6 +755,20 @@ void PLModel::rebuild( playlist_item_t *p_root )
     addCallbacks();
 }
 
+void PLModel::RemoveItem( PLItem *item )
+{
+    if( !item ) return;
+    if( currentItem && currentItem->p_input == item->p_input )
+    {
+        currentItem = NULL;
+        emit currentChanged( QModelIndex() );
+    }
+    PLItem *parent = item->parentItem;
+    assert( parent );
+    int i_index = parent->children.indexOf( item );
+    parent->children.removeAt( i_index );
+    delete item;
+}
 void PLModel::RemoveChildren( PLItem *root )
 {
   if( root->children.size() )
@@ -853,7 +866,7 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
     /* And finally, remove it from the tree */
     int itemIndex = item->parentItem->children.indexOf( item );
     beginRemoveRows( index( item->parentItem, 0), itemIndex, itemIndex );
-    item->remove( item, i_depth );
+    RemoveItem( item );
     endRemoveRows();
 }
 
index d8c23634dabbfecddaeb53b43ce3ce6d59e99874..87bf98ccd7193cc6e9f3786d0f82e316fb670aaa 100644 (file)
@@ -152,6 +152,7 @@ private:
     void doDeleteItem( PLItem *item, QModelIndexList *fullList );
     void UpdateTreeItem( PLItem *, bool, bool force = false );
     /* The following actions will not signal the view! */
+    void RemoveItem ( PLItem * );
     void RemoveChildren( PLItem * );
     void UpdateChildren( PLItem * );
     void UpdateChildren( playlist_item_t *, PLItem * );