[vlc-devel] commit: qt4: move item removal from PLItem to PLModel... (Jakob Leben )

git version control git at videolan.org
Wed Aug 19 14:15:40 CEST 2009


vlc | branch: master | Jakob Leben <jleben at videolan.org> | Wed Aug 19 14:13:46 2009 +0200| [53cd4ad45297105bc7e8a8f9addb53f2b48beeda] | committer: Jakob Leben 

qt4: move item removal from PLItem to PLModel...

...and fix memleak when removing..

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=53cd4ad45297105bc7e8a8f9addb53f2b48beeda
---

 .../gui/qt4/components/playlist/playlist_item.cpp  |    9 ---------
 .../gui/qt4/components/playlist/playlist_item.hpp  |    2 --
 .../gui/qt4/components/playlist/playlist_model.cpp |   19 ++++++++++++++++---
 .../gui/qt4/components/playlist/playlist_model.hpp |    1 +
 4 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/playlist_item.cpp b/modules/gui/qt4/components/playlist/playlist_item.cpp
index eb4c88f..ab223bf 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.cpp
@@ -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
 {
diff --git a/modules/gui/qt4/components/playlist/playlist_item.hpp b/modules/gui/qt4/components/playlist/playlist_item.hpp
index 891e036..0ff3f2d 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.hpp
@@ -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(); };
 
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 89bddb6..30f4c60 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -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();
 }
 
diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp
index d8c2363..87bf98c 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.hpp
@@ -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 * );




More information about the vlc-devel mailing list