Commit b3b361b0 authored by Ilkka Ollakka's avatar Ilkka Ollakka

Qt4: store input_item_t* in plitem and handle metadata in model

No need to store/recreate metadata on plitem anymore, as we can get
it now on the fly, also separate headerData and Data. Hopefully
that vlc_gc_incref/vlc_gc_decref is sufficient for that input_item_t
pointer protection.

Feel free to fix/revert/comment if that pointer shouldn't really be
there, or if it's not safe it to be there thisway.
parent 0c8124fd
......@@ -48,15 +48,17 @@
*/
void PLItem::init( int _i_id, int _i_input_id, bool _is_node, PLItem *parent, PLModel *m, QSettings *settings )
void PLItem::init( playlist_item_t *_playlist_item, PLItem *parent, PLModel *m, QSettings *settings )
{
parentItem = parent; /* Can be NULL, but only for the rootItem */
i_id = _i_id; /* Playlist item specific id */
i_input_id = _i_input_id; /* Identifier of the input */
i_id = _playlist_item->i_id; /* Playlist item specific id */
i_input_id = _playlist_item->p_input->i_id; /* Identifier of the input */
model = m; /* PLModel (QAbsmodel) */
i_type = -1; /* Item type - Avoid segfault */
b_current = false; /* Is the item the current Item or not */
b_is_node = _is_node;
b_is_node = _playlist_item->i_children > 1;
p_input = _playlist_item->p_input;
vlc_gc_incref( p_input );
assert( model ); /* We need a model */
......@@ -66,7 +68,6 @@ void PLItem::init( int _i_id, int _i_input_id, bool _is_node, PLItem *parent, PL
if( model->i_depth == DEPTH_SEL ) /* Selector Panel */
{
i_showflags = 0;
item_col_strings.append( "" );
}
else
{
......@@ -83,7 +84,6 @@ void PLItem::init( int _i_id, int _i_input_id, bool _is_node, PLItem *parent, PL
{
i_showflags = parentItem->i_showflags;
//Add empty string and update() handles data appending
item_col_strings.append( "" );
}
}
......@@ -92,21 +92,14 @@ void PLItem::init( int _i_id, int _i_input_id, bool _is_node, PLItem *parent, PL
Call the above function init
So far the first constructor isn't used...
*/
PLItem::PLItem( int _i_id, int _i_input_id, bool _is_node, PLItem *parent, PLModel *m )
PLItem::PLItem( playlist_item_t *p_item, PLItem *parent, PLModel *m )
{
init( _i_id, _i_input_id, _is_node, parent, m, NULL );
}
PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
{
init( p_item->i_id, p_item->p_input->i_id, p_item->i_children > -1,
parent, m, NULL );
init( p_item, parent, m, NULL );
}
PLItem::PLItem( playlist_item_t * p_item, QSettings *settings, PLModel *m )
{
init( p_item->i_id, p_item->p_input->i_id, p_item->i_children > -1,
NULL, m, settings );
init( p_item, NULL, m, settings );
}
PLItem::~PLItem()
......@@ -118,15 +111,7 @@ PLItem::~PLItem()
/* Column manager */
void PLItem::updateColumnHeaders()
{
item_col_strings.clear();
assert( i_showflags < COLUMN_END );
for( uint32_t i_index=1; i_index < COLUMN_END; i_index <<= 1 )
{
if( i_showflags & i_index )
item_col_strings.append( qfu( psz_column_title( i_index ) ) );
}
}
/* So far signal is always true.
......@@ -179,31 +164,6 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
b_current = iscurrent;
b_is_node = p_item->i_children > -1;
item_col_strings.clear();
if( model->i_depth == 1 ) /* Selector Panel */
{
item_col_strings.append( qfu( p_item->p_input->psz_name ) );
return;
}
i_showflags = parentItem ? parentItem->i_showflags : i_showflags;
/* Meta: ID */
if( i_showflags & COLUMN_NUMBER )
{
QModelIndex idx = model->index( this, 0 );
item_col_strings.append( QString::number( idx.row() + 1 ) );
}
/* Other meta informations */
for( uint32_t i_index=2; i_index < COLUMN_END; i_index <<= 1 )
{
if( i_showflags & i_index )
{
char *psz = psz_column_meta( p_item->p_input, i_index );
item_col_strings.append( qfu( psz ) );
free( psz );
}
}
}
......@@ -60,22 +60,20 @@ public:
PLItem *parent() { return parentItem; };
QString columnString( int col ) { return item_col_strings.value( col ); };
void update( playlist_item_t *, bool );
protected:
QList<PLItem*> children;
QList<QString> item_col_strings;
bool b_current;
int i_type;
int i_id;
int i_input_id;
int i_showflags;
bool b_is_node;
input_item_t *p_input;
private:
void init( int, int, bool, PLItem *, PLModel *, QSettings * );
void init( playlist_item_t *, PLItem *, PLModel *, QSettings * );
void updateColumnHeaders();
PLItem *parentItem;
PLModel *model;
......
......@@ -317,7 +317,34 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
PLItem *item = static_cast<PLItem*>(index.internalPointer());
if( role == Qt::DisplayRole )
{
return QVariant( item->columnString( index.column() ) );
int running_index = -1;
int columncount = 0;
int metadata = 1;
if( item->model->i_depth == DEPTH_SEL )
return QVariant( QString( qfu( item->p_input->psz_name ) ) );
while( metadata < COLUMN_END )
{
if( item->i_showflags & metadata )
running_index++;
if( running_index == index.column() )
break;
metadata <<= 1;
}
if( running_index != index.column() ) return QVariant();
QString returninfo;
if( metadata == COLUMN_NUMBER )
returninfo = QString::number( index.row() + 1 );
else
{
char *psz = psz_column_meta( item->p_input, metadata );
returninfo = QString( qfu( psz ) );
free( psz );
}
return QVariant( returninfo );
}
else if( role == Qt::DecorationRole && index.column() == 0 )
{
......@@ -350,9 +377,25 @@ int PLModel::itemId( const QModelIndex &index ) const
QVariant PLModel::headerData( int section, Qt::Orientation orientation,
int role ) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return QVariant( rootItem->columnString( section ) );
int metadata=1;
int running_index=-1;
if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
return QVariant();
if( i_depth == DEPTH_SEL ) return QVariant( QString("") );
while( metadata < COLUMN_END )
{
if( metadata & rootItem->i_showflags )
running_index++;
if( running_index == section )
break;
metadata <<= 1;
}
if( running_index != section ) return QVariant();
return QVariant( qfu( psz_column_title( metadata ) ) );
}
QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
......@@ -407,7 +450,17 @@ QModelIndex PLModel::parent( const QModelIndex &index ) const
int PLModel::columnCount( const QModelIndex &i) const
{
return rootItem->item_col_strings.count();
int columnCount=0;
int metadata=1;
if( i_depth == DEPTH_SEL ) return 1;
while( metadata < COLUMN_END )
{
if( metadata & rootItem->i_showflags )
columnCount++;
metadata <<= 1;
}
return columnCount;
}
int PLModel::childrenCount( const QModelIndex &parent ) const
......@@ -874,7 +927,7 @@ void PLModel::viewchanged( int meta )
}
/* UNUSED emit layoutAboutToBeChanged(); */
index = __MIN( index, rootItem->item_col_strings.count() );
index = __MIN( index, columnCount() );
QModelIndex parent = createIndex( 0, 0, rootItem );
if( rootItem->i_showflags & meta )
......@@ -883,7 +936,6 @@ void PLModel::viewchanged( int meta )
beginRemoveColumns( parent, index, index+1 );
rootItem->i_showflags &= ~( meta );
getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
rootItem->updateColumnHeaders();
endRemoveColumns();
}
else
......@@ -892,7 +944,6 @@ void PLModel::viewchanged( int meta )
beginInsertColumns( parent, index, index+1 );
rootItem->i_showflags |= meta;
getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
rootItem->updateColumnHeaders();
endInsertColumns();
}
emit columnsChanged( meta );
......
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