Commit 53cd4ad4 authored by Jakob Leben's avatar Jakob Leben

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

...and fix memleak when removing..
parent 26201e1c
...@@ -84,15 +84,6 @@ void PLItem::insertChild( PLItem *item, int i_pos, bool signal ) ...@@ -84,15 +84,6 @@ void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
children.insert( i_pos, item ); 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 */ /* This function is used to get one's parent's row number in the model */
int PLItem::row() const int PLItem::row() const
{ {
......
...@@ -47,8 +47,6 @@ public: ...@@ -47,8 +47,6 @@ public:
children.insert( children.count(), item ); children.insert( children.count(), item );
}; };
void remove( PLItem *removed, int i_depth );
PLItem *child( int row ) { return children.value( row ); }; PLItem *child( int row ) { return children.value( row ); };
int childCount() const { return children.count(); }; int childCount() const { return children.count(); };
......
...@@ -289,8 +289,7 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action, ...@@ -289,8 +289,7 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
void PLModel::removeItem( int i_id ) void PLModel::removeItem( int i_id )
{ {
PLItem *item = FindById( rootItem, i_id ); PLItem *item = FindById( rootItem, i_id );
if( currentItem && item && currentItem->p_input == item->p_input ) currentItem = NULL; RemoveItem( item );
if( item ) item->remove( item, i_depth );
} }
/* callbacks and slots */ /* callbacks and slots */
...@@ -756,6 +755,20 @@ void PLModel::rebuild( playlist_item_t *p_root ) ...@@ -756,6 +755,20 @@ void PLModel::rebuild( playlist_item_t *p_root )
addCallbacks(); 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 ) void PLModel::RemoveChildren( PLItem *root )
{ {
if( root->children.size() ) if( root->children.size() )
...@@ -853,7 +866,7 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList ) ...@@ -853,7 +866,7 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
/* And finally, remove it from the tree */ /* And finally, remove it from the tree */
int itemIndex = item->parentItem->children.indexOf( item ); int itemIndex = item->parentItem->children.indexOf( item );
beginRemoveRows( index( item->parentItem, 0), itemIndex, itemIndex ); beginRemoveRows( index( item->parentItem, 0), itemIndex, itemIndex );
item->remove( item, i_depth ); RemoveItem( item );
endRemoveRows(); endRemoveRows();
} }
......
...@@ -152,6 +152,7 @@ private: ...@@ -152,6 +152,7 @@ private:
void doDeleteItem( PLItem *item, QModelIndexList *fullList ); void doDeleteItem( PLItem *item, QModelIndexList *fullList );
void UpdateTreeItem( PLItem *, bool, bool force = false ); void UpdateTreeItem( PLItem *, bool, bool force = false );
/* The following actions will not signal the view! */ /* The following actions will not signal the view! */
void RemoveItem ( PLItem * );
void RemoveChildren( PLItem * ); void RemoveChildren( PLItem * );
void UpdateChildren( PLItem * ); void UpdateChildren( PLItem * );
void UpdateChildren( playlist_item_t *, PLItem * ); void UpdateChildren( playlist_item_t *, PLItem * );
......
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