Commit a714732f authored by Erwan Tulou's avatar Erwan Tulou

skins2: some optimisation for playlist

limit rebuilding the playlist control only when the notified item is
 expected to be visible. This improves responsiveness when playlists
are very large.
parent bc83704f
......@@ -143,33 +143,36 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree,
if( arg->i_type == 0 ) // Item update
{
if( arg->b_active_item )
{
autoScroll();
///\todo We should make image if we are visible in the view
makeImage();
}
makeImage();
notifyLayout();
}
/// \todo handle delete in a more clever way
else if ( arg->i_type == 1 ) // Global change or deletion
{
m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
makeImage();
notifyLayout();
}
else if ( arg->i_type == 2 ) // Item-append
{
if( m_flat && m_firstPos->size() )
{
m_firstPos = m_rTree.getNextLeaf( m_firstPos );
/// \todo Check if the item is really visible in the view
// (we only check if it in the document)
if( arg->b_visible == true )
makeImage();
notifyLayout();
}
else if( isItemVisible( arg->i_id ) )
{
makeImage();
notifyLayout();
}
}
else if( arg->i_type == 3 ) // item-del
{
/* Make sure firstPos is valid */
VarTree::Iterator it_old = m_firstPos;
while( m_firstPos->isDeleted() &&
m_firstPos != (m_flat ? m_rTree.firstLeaf()
: m_rTree.begin()) )
......@@ -180,12 +183,12 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree,
if( m_firstPos->isDeleted() )
m_firstPos = m_rTree.begin();
if( arg->b_visible == true )
if( m_firstPos != it_old || isItemVisible( arg->i_id ) )
{
makeImage();
notifyLayout();
}
}
notifyLayout();
}
void CtrlTree::onUpdate( Subject<VarPercent> &rPercent, void* arg)
......@@ -880,3 +883,12 @@ VarTree::Iterator CtrlTree::findItemAtPos( int pos )
return it;
}
bool CtrlTree::isItemVisible( int id )
{
VarTree::Iterator it = m_rTree.findById( id );
int rank1 = m_rTree.getRank( m_firstPos, m_flat );
int rank2 = m_rTree.getRank( it, m_flat );
return ( rank2 >= rank1 && rank2 <= rank1 + maxItems() -1 );
}
......@@ -147,6 +147,9 @@ private:
* n too big)
*/
VarTree::Iterator findItemAtPos( int n );
/// check if id is within the visible control
bool isItemVisible( int id );
};
#endif
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