Commit 5dcf1434 authored by Jakob Leben's avatar Jakob Leben

qt4: fix playlist column show/hide

parent 9e3b53ac
...@@ -371,7 +371,7 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const ...@@ -371,7 +371,7 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
return QVariant(returninfo); return QVariant(returninfo);
} }
int metadata = metaColumn( index.column() ); int metadata = columnToMeta( index.column(), i_showflags );
if( metadata == COLUMN_END ) return QVariant(); if( metadata == COLUMN_END ) return QVariant();
QString returninfo; QString returninfo;
...@@ -420,7 +420,7 @@ QVariant PLModel::headerData( int section, Qt::Orientation orientation, ...@@ -420,7 +420,7 @@ QVariant PLModel::headerData( int section, Qt::Orientation orientation,
if( i_depth == DEPTH_SEL ) return QVariant( QString("") ); if( i_depth == DEPTH_SEL ) return QVariant( QString("") );
int meta_col = metaColumn( section ); int meta_col = columnToMeta( section, i_showflags );
if( meta_col == COLUMN_END ) return QVariant(); if( meta_col == COLUMN_END ) return QVariant();
...@@ -622,23 +622,48 @@ PLItem *PLModel::getItem( QModelIndex index ) ...@@ -622,23 +622,48 @@ PLItem *PLModel::getItem( QModelIndex index )
return static_cast<PLItem*>( index.internalPointer() ); return static_cast<PLItem*>( index.internalPointer() );
} }
/* computes column id of meta data from visible column index */ /*
int PLModel::metaColumn( int column ) const Computes meta data column id from shown column index and shown columns flags.
Returns COLUMN_END in case of failure.
*/
int PLModel::columnToMeta( int column, int shown_flags ) const
{ {
int metadata = 1; int meta = 1;
int running_index = -1; int index = -1;
while( metadata < COLUMN_END ) while( meta < COLUMN_END )
{ {
if( metadata & i_showflags ) if( meta & shown_flags )
running_index++; index++;
if( running_index == column ) if( index == column )
break; break;
metadata <<= 1; meta <<= 1;
}
return meta;
}
/*
Computes shown column index from meta data column id and shown columns flags.
meta_col must be contained in shown_flags!
*/
int PLModel::columnFromMeta( int meta_col, int shown_flags ) const
{
assert( meta & shown_flags );
int meta = 1;
int index = -1;
while( meta < COLUMN_END )
{
if( meta & shown_flags )
index++;
if( meta == meta_col )
break;
meta <<= 1;
} }
if( running_index != column ) return COLUMN_END; return index;
return metadata;
} }
/************************* Updates handling *****************************/ /************************* Updates handling *****************************/
...@@ -751,6 +776,7 @@ void PLModel::rebuild( playlist_item_t *p_root ) ...@@ -751,6 +776,7 @@ void PLModel::rebuild( playlist_item_t *p_root )
/* And signal the view */ /* And signal the view */
reset(); reset();
emit currentChanged( index( currentItem, 0 ) ); emit currentChanged( index( currentItem, 0 ) );
addCallbacks(); addCallbacks();
...@@ -1002,7 +1028,7 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list ) ...@@ -1002,7 +1028,7 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) ); menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
menu->addSeparator(); menu->addSeparator();
QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") + QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") +
qfu( psz_column_title( metaColumn( index.column() ) ) ) ); qfu( psz_column_title( columnToMeta( index.column(), i_showflags ) ) ) );
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" ),
...@@ -1018,36 +1044,30 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list ) ...@@ -1018,36 +1044,30 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
menu->popup( point ); menu->popup( point );
} }
void PLModel::viewchanged( int meta ) void PLModel::viewchanged( int meta )
{ {
assert( meta ); assert( meta );
int _meta = meta; int _meta = meta;
if( rootItem ) if( rootItem )
{ {
int index=-1;
while( _meta )
{
index++;
_meta >>= 1;
}
index = __MIN( index, columnCount() );
QModelIndex parent = createIndex( 0, 0, rootItem );
if( i_showflags & meta ) if( i_showflags & meta )
/* Removing columns */ /* Removing columns */
{ {
beginRemoveColumns( parent, index, index+1 ); int index = columnFromMeta( meta, i_showflags );
beginRemoveColumns( QModelIndex(), index, index );
i_showflags &= ~( meta ); i_showflags &= ~( meta );
getSettings()->setValue( "qt-pl-showflags", i_showflags ); getSettings()->setValue( "qt-pl-showflags", i_showflags );
endRemoveColumns(); endRemoveColumns();
} }
else else
{ {
int sf = i_showflags;
sf |= meta;
int index = columnFromMeta( meta, sf );
/* Adding columns */ /* Adding columns */
beginInsertColumns( parent, index, index+1 ); beginInsertColumns( QModelIndex(), index, index );
i_showflags |= meta; i_showflags = sf;
getSettings()->setValue( "qt-pl-showflags", i_showflags ); getSettings()->setValue( "qt-pl-showflags", i_showflags );
endInsertColumns(); endInsertColumns();
} }
......
...@@ -171,7 +171,8 @@ private: ...@@ -171,7 +171,8 @@ private:
PLItem *findByInput( PLItem *, int ); PLItem *findByInput( PLItem *, int );
PLItem *findInner( PLItem *, int , bool ); PLItem *findInner( PLItem *, int , bool );
static inline PLItem *getItem( QModelIndex index ); static inline PLItem *getItem( QModelIndex index );
int metaColumn ( int column ) const; int columnFromMeta( int meta_column, int shown_flags ) const;
int columnToMeta( int column, int shown_flags ) 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