Commit 7635e6e8 authored by Jakob Leben's avatar Jakob Leben

qt4 playlist: refactor meta data retrieval and show meta title for sorting in popup menu

parent 4b800920
...@@ -349,10 +349,6 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const ...@@ -349,10 +349,6 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
PLItem *item = static_cast<PLItem*>(index.internalPointer()); PLItem *item = static_cast<PLItem*>(index.internalPointer());
if( role == Qt::DisplayRole ) if( role == Qt::DisplayRole )
{ {
int running_index = -1;
int columncount = 0;
int metadata = 1;
if( i_depth == DEPTH_SEL ) if( i_depth == DEPTH_SEL )
{ {
vlc_mutex_lock( &item->p_input->lock ); vlc_mutex_lock( &item->p_input->lock );
...@@ -361,16 +357,8 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const ...@@ -361,16 +357,8 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
return QVariant(returninfo); return QVariant(returninfo);
} }
while( metadata < COLUMN_END ) int metadata = metaColumn( index.column() );
{ if( metadata == COLUMN_END ) return QVariant();
if( i_showflags & metadata )
running_index++;
if( running_index == index.column() )
break;
metadata <<= 1;
}
if( running_index != index.column() ) return QVariant();
QString returninfo; QString returninfo;
if( metadata == COLUMN_NUMBER ) if( metadata == COLUMN_NUMBER )
...@@ -378,7 +366,7 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const ...@@ -378,7 +366,7 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
else else
{ {
char *psz = psz_column_meta( item->p_input, metadata ); char *psz = psz_column_meta( item->p_input, metadata );
returninfo = QString( qfu( psz ) ); returninfo = qfu( psz );
free( psz ); free( psz );
} }
return QVariant( returninfo ); return QVariant( returninfo );
...@@ -415,25 +403,16 @@ int PLModel::itemId( const QModelIndex &index ) const ...@@ -415,25 +403,16 @@ int PLModel::itemId( const QModelIndex &index ) const
QVariant PLModel::headerData( int section, Qt::Orientation orientation, QVariant PLModel::headerData( int section, Qt::Orientation orientation,
int role ) const int role ) const
{ {
int metadata=1;
int running_index=-1;
if (orientation != Qt::Horizontal || role != Qt::DisplayRole) if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
return QVariant(); return QVariant();
if( i_depth == DEPTH_SEL ) return QVariant( QString("") ); if( i_depth == DEPTH_SEL ) return QVariant( QString("") );
while( metadata < COLUMN_END ) int meta_col = metaColumn( section );
{
if( metadata & i_showflags )
running_index++;
if( running_index == section )
break;
metadata <<= 1;
}
if( running_index != section ) return QVariant(); if( meta_col == COLUMN_END ) return QVariant();
return QVariant( qfu( psz_column_title( metadata ) ) ); return QVariant( qfu( psz_column_title( meta_col ) ) );
} }
QModelIndex PLModel::index( int row, int column, const QModelIndex &parent ) QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
...@@ -641,6 +620,24 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input ) ...@@ -641,6 +620,24 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
#undef CACHE #undef CACHE
#undef ICACHE #undef ICACHE
/* computes column id of meta data from visible column index */
int PLModel::metaColumn( int column ) const
{
int metadata = 1;
int running_index = -1;
while( metadata < COLUMN_END )
{
if( metadata & i_showflags )
running_index++;
if( running_index == column )
break;
metadata <<= 1;
}
if( running_index != column ) return COLUMN_END;
return metadata;
}
/************************* Updates handling *****************************/ /************************* Updates handling *****************************/
void PLModel::customEvent( QEvent *event ) void PLModel::customEvent( QEvent *event )
...@@ -966,7 +963,8 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list ) ...@@ -966,7 +963,8 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
if( node ) if( node )
{ {
menu->addSeparator(); menu->addSeparator();
QMenu *sort_menu = menu->addMenu( qtr(I_POP_SORT) ); QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") +
qfu( psz_column_title( metaColumn( index.column() ) ) ) );
sort_menu->addAction( qtr( "Ascending" ), sort_menu->addAction( qtr( "Ascending" ),
this, SLOT( popupSortAsc() ) ); this, SLOT( popupSortAsc() ) );
sort_menu->addAction( qtr( "Descending" ), sort_menu->addAction( qtr( "Descending" ),
......
...@@ -164,6 +164,7 @@ private: ...@@ -164,6 +164,7 @@ private:
PLItem *FindById( PLItem *, int ); PLItem *FindById( PLItem *, int );
PLItem *FindByInput( PLItem *, int ); PLItem *FindByInput( PLItem *, int );
PLItem *FindInner( PLItem *, int , bool ); PLItem *FindInner( PLItem *, int , bool );
int metaColumn ( int column ) const;
PLItem *p_cached_item; PLItem *p_cached_item;
PLItem *p_cached_item_bi; PLItem *p_cached_item_bi;
int i_cached_id; int i_cached_id;
......
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