Commit 26201e1c authored by Jakob Leben's avatar Jakob Leben

qt4 playlist: simplify view notification, don't rebuild on popup sort

parent c149ea80
...@@ -708,11 +708,9 @@ void PLModel::ProcessItemAppend( const playlist_add_t *p_add ) ...@@ -708,11 +708,9 @@ void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
newItem = new PLItem( p_item, nodeItem ); newItem = new PLItem( p_item, nodeItem );
PL_UNLOCK; PL_UNLOCK;
emit layoutAboutToBeChanged(); beginInsertRows( index( nodeItem, 0 ), nodeItem->childCount(), nodeItem->childCount() );
emit beginInsertRows( index( newItem, 0 ), nodeItem->childCount(), nodeItem->childCount()+1 );
nodeItem->appendChild( newItem ); nodeItem->appendChild( newItem );
emit endInsertRows(); endInsertRows();
emit layoutChanged();
UpdateTreeItem( newItem, true ); UpdateTreeItem( newItem, true );
return; return;
end: end:
...@@ -734,20 +732,8 @@ void PLModel::rebuild( playlist_item_t *p_root ) ...@@ -734,20 +732,8 @@ void PLModel::rebuild( playlist_item_t *p_root )
/* Invalidate cache */ /* Invalidate cache */
i_cached_id = i_cached_input_id = -1; i_cached_id = i_cached_input_id = -1;
emit layoutAboutToBeChanged(); if( rootItem ) RemoveChildren( rootItem );
/* Clear the tree */
if( rootItem )
{
if( rootItem->children.size() )
{
emit beginRemoveRows( index( rootItem, 0 ), 0,
rootItem->children.size() -1 );
qDeleteAll( rootItem->children );
rootItem->children.clear();
emit endRemoveRows();
}
}
PL_LOCK; PL_LOCK;
if( p_root ) if( p_root )
{ {
...@@ -756,7 +742,7 @@ void PLModel::rebuild( playlist_item_t *p_root ) ...@@ -756,7 +742,7 @@ void PLModel::rebuild( playlist_item_t *p_root )
} }
assert( rootItem ); assert( rootItem );
/* Recreate from root */ /* Recreate from root */
UpdateNodeChildren( rootItem ); UpdateChildren( rootItem );
if( (p_item = playlist_CurrentPlayingItem(p_playlist)) ) if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
currentItem = FindByInput( rootItem, p_item->p_input->i_id ); currentItem = FindByInput( rootItem, p_item->p_input->i_id );
else else
...@@ -764,33 +750,38 @@ void PLModel::rebuild( playlist_item_t *p_root ) ...@@ -764,33 +750,38 @@ void PLModel::rebuild( playlist_item_t *p_root )
PL_UNLOCK; PL_UNLOCK;
/* And signal the view */ /* And signal the view */
reset();
emit currentChanged( index( currentItem, 0 ) ); emit currentChanged( index( currentItem, 0 ) );
emit layoutChanged();
addCallbacks(); addCallbacks();
} }
void PLModel::RemoveChildren( PLItem *root )
{
if( root->children.size() )
{
qDeleteAll( root->children );
root->children.clear();
}
}
/* This function must be entered WITH the playlist lock */ /* This function must be entered WITH the playlist lock */
void PLModel::UpdateNodeChildren( PLItem *root ) void PLModel::UpdateChildren( PLItem *root )
{ {
emit layoutAboutToBeChanged();
playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id ); playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
UpdateNodeChildren( p_node, root ); UpdateChildren( p_node, root );
emit layoutChanged();
} }
/* This function must be entered WITH the playlist lock */ /* This function must be entered WITH the playlist lock */
void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root ) void PLModel::UpdateChildren( playlist_item_t *p_node, PLItem *root )
{ {
for( int i = 0; i < p_node->i_children ; i++ ) for( int i = 0; i < p_node->i_children ; i++ )
{ {
if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue; if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
PLItem *newItem = new PLItem( p_node->pp_children[i], root ); PLItem *newItem = new PLItem( p_node->pp_children[i], root );
emit beginInsertRows( index( newItem, 0 ), root->childCount(), root->childCount()+1 );
root->appendChild( newItem ); root->appendChild( newItem );
emit endInsertRows();
UpdateTreeItem( newItem, true, true );
if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 ) if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
UpdateNodeChildren( p_node->pp_children[i], newItem ); UpdateChildren( p_node->pp_children[i], newItem );
} }
} }
...@@ -860,10 +851,10 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList ) ...@@ -860,10 +851,10 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
playlist_NodeDelete( p_playlist, p_item, true, false ); playlist_NodeDelete( p_playlist, p_item, true, false );
PL_UNLOCK; PL_UNLOCK;
/* And finally, remove it from the tree */ /* And finally, remove it from the tree */
emit beginRemoveRows( index( item->parentItem, 0), item->parentItem->children.indexOf( item ), int itemIndex = item->parentItem->children.indexOf( item );
item->parentItem->children.indexOf( item )+1 ); beginRemoveRows( index( item->parentItem, 0), itemIndex, itemIndex );
item->remove( item, i_depth ); item->remove( item, i_depth );
emit endRemoveRows(); endRemoveRows();
} }
/******* Volume III: Sorting and searching ********/ /******* Volume III: Sorting and searching ********/
...@@ -885,12 +876,21 @@ void PLModel::sort( int i_root_id, int column, Qt::SortOrder order ) ...@@ -885,12 +876,21 @@ void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
if( column == i_index ) if( column == i_index )
{ {
i_flag = i_column; i_flag = i_column;
goto next; break;
} }
} }
PLItem *item = FindById( rootItem, i_root_id );
if( !item ) return;
QModelIndex qIndex = index( item, 0 );
int count = item->children.size();
if( count )
{
beginRemoveRows( qIndex, 0, count - 1 );
RemoveChildren( item );
endRemoveRows( );
}
next:
PL_LOCK; PL_LOCK;
{ {
playlist_item_t *p_root = playlist_ItemGetById( p_playlist, playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
...@@ -903,8 +903,13 @@ next: ...@@ -903,8 +903,13 @@ next:
ORDER_NORMAL : ORDER_REVERSE ); ORDER_NORMAL : ORDER_REVERSE );
} }
} }
if( count )
{
beginInsertRows( qIndex, 0, count - 1 );
UpdateChildren( item );
endInsertRows( );
}
PL_UNLOCK; PL_UNLOCK;
rebuild();
} }
void PLModel::search( const QString& search_text ) void PLModel::search( const QString& search_text )
...@@ -991,32 +996,27 @@ void PLModel::viewchanged( int meta ) ...@@ -991,32 +996,27 @@ void PLModel::viewchanged( int meta )
_meta >>= 1; _meta >>= 1;
} }
/* UNUSED emit layoutAboutToBeChanged(); */
index = __MIN( index, columnCount() ); index = __MIN( index, columnCount() );
QModelIndex parent = createIndex( 0, 0, rootItem ); QModelIndex parent = createIndex( 0, 0, rootItem );
emit layoutAboutToBeChanged();
if( i_showflags & meta ) if( i_showflags & meta )
/* Removing columns */ /* Removing columns */
{ {
emit beginRemoveColumns( parent, index, index+1 ); beginRemoveColumns( parent, index, index+1 );
i_showflags &= ~( meta ); i_showflags &= ~( meta );
getSettings()->setValue( "qt-pl-showflags", i_showflags ); getSettings()->setValue( "qt-pl-showflags", i_showflags );
emit endRemoveColumns(); endRemoveColumns();
} }
else else
{ {
/* Adding columns */ /* Adding columns */
emit beginInsertColumns( parent, index, index+1 ); beginInsertColumns( parent, index, index+1 );
i_showflags |= meta; i_showflags |= meta;
getSettings()->setValue( "qt-pl-showflags", i_showflags ); getSettings()->setValue( "qt-pl-showflags", i_showflags );
emit endInsertColumns(); endInsertColumns();
} }
emit columnsChanged( meta ); emit columnsChanged( meta );
emit layoutChanged();
} }
} }
......
...@@ -147,13 +147,14 @@ private: ...@@ -147,13 +147,14 @@ private:
void ProcessItemRemoval( int i_id ); void ProcessItemRemoval( int i_id );
void ProcessItemAppend( const playlist_add_t *p_add ); void ProcessItemAppend( const playlist_add_t *p_add );
void UpdateTreeItem( PLItem *, bool, bool force = false );
void UpdateNodeChildren( PLItem * );
void UpdateNodeChildren( playlist_item_t *, PLItem * );
/* Actions */ /* Actions */
void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList ); void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
void doDeleteItem( PLItem *item, QModelIndexList *fullList ); void doDeleteItem( PLItem *item, QModelIndexList *fullList );
void UpdateTreeItem( PLItem *, bool, bool force = false );
/* The following actions will not signal the view! */
void RemoveChildren( PLItem * );
void UpdateChildren( PLItem * );
void UpdateChildren( playlist_item_t *, PLItem * );
/* Popup */ /* Popup */
int i_popup_item, i_popup_parent, i_popup_column; int i_popup_item, i_popup_parent, i_popup_column;
......
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