Qt4: cache currentItem index

Not sure if it's the best way, but this enables
to show the current item even when input is stopped.
This commit is contained in:
Ilkka Ollakka 2010-06-23 12:42:08 +03:00
parent 15745ba514
commit 0455f98598
2 changed files with 12 additions and 5 deletions

View File

@ -73,6 +73,7 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
i_cached_input_id = -1;
i_popup_item = i_popup_parent = -1;
sortingMenu = NULL;
current_index = QModelIndex();
rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
@ -98,6 +99,8 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
this, processItemAppend( int, int ) );
CONNECT( THEMIM, playlistItemRemoved( int ),
this, processItemRemoval( int ) );
CONNECT( this, currentChanged( const QModelIndex &) ,
this, cacheCurrent( const QModelIndex &) );
}
PLModel::~PLModel()
@ -380,7 +383,7 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
bool PLModel::isCurrent( const QModelIndex &index ) const
{
return getItem( index )->p_input == THEMIM->currentInputItem();
return index == current_index;
}
int PLModel::itemId( const QModelIndex &index ) const
@ -429,12 +432,14 @@ QModelIndex PLModel::index( PLItem *item, int column ) const
return QModelIndex();
}
void PLModel::cacheCurrent( const QModelIndex &current )
{
current_index = current;
}
QModelIndex PLModel::currentIndex()
{
input_thread_t *p_input_thread = THEMIM->getInput();
if( !p_input_thread ) return QModelIndex();
PLItem *item = findByInput( rootItem, input_GetItem( p_input_thread )->i_id );
return index( item, 0 );
return current_index;
}
QModelIndex PLModel::parent( const QModelIndex &index ) const

View File

@ -161,6 +161,7 @@ private:
PLItem *p_cached_item_bi;
int i_cached_id;
int i_cached_input_id;
QModelIndex current_index;
private slots:
void popupPlay();
@ -175,6 +176,7 @@ private slots:
void processInputItemUpdate( input_thread_t* p_input );
void processItemRemoval( int i_id );
void processItemAppend( int item, int parent );
void cacheCurrent( const QModelIndex & );
};
class PlMimeData : public QMimeData