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 @@ ...@@ -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 */ parentItem = parent; /* Can be NULL, but only for the rootItem */
i_id = _i_id; /* Playlist item specific id */ i_id = _playlist_item->i_id; /* Playlist item specific id */
i_input_id = _i_input_id; /* Identifier of the input */ i_input_id = _playlist_item->p_input->i_id; /* Identifier of the input */
model = m; /* PLModel (QAbsmodel) */ model = m; /* PLModel (QAbsmodel) */
i_type = -1; /* Item type - Avoid segfault */ i_type = -1; /* Item type - Avoid segfault */
b_current = false; /* Is the item the current Item or not */ 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 */ 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 ...@@ -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 */ if( model->i_depth == DEPTH_SEL ) /* Selector Panel */
{ {
i_showflags = 0; i_showflags = 0;
item_col_strings.append( "" );
} }
else else
{ {
...@@ -83,7 +84,6 @@ void PLItem::init( int _i_id, int _i_input_id, bool _is_node, PLItem *parent, PL ...@@ -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; i_showflags = parentItem->i_showflags;
//Add empty string and update() handles data appending //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 ...@@ -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 Call the above function init
So far the first constructor isn't used... 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 ); init( p_item, 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 );
} }
PLItem::PLItem( playlist_item_t * p_item, QSettings *settings, PLModel *m ) 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, init( p_item, NULL, m, settings );
NULL, m, settings );
} }
PLItem::~PLItem() PLItem::~PLItem()
...@@ -118,15 +111,7 @@ PLItem::~PLItem() ...@@ -118,15 +111,7 @@ PLItem::~PLItem()
/* Column manager */ /* Column manager */
void PLItem::updateColumnHeaders() void PLItem::updateColumnHeaders()
{ {
item_col_strings.clear();
assert( i_showflags < COLUMN_END ); 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. /* So far signal is always true.
...@@ -179,31 +164,6 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent ) ...@@ -179,31 +164,6 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
b_current = iscurrent; b_current = iscurrent;
b_is_node = p_item->i_children > -1; 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; 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: ...@@ -60,22 +60,20 @@ public:
PLItem *parent() { return parentItem; }; PLItem *parent() { return parentItem; };
QString columnString( int col ) { return item_col_strings.value( col ); };
void update( playlist_item_t *, bool ); void update( playlist_item_t *, bool );
protected: protected:
QList<PLItem*> children; QList<PLItem*> children;
QList<QString> item_col_strings;
bool b_current; bool b_current;
int i_type; int i_type;
int i_id; int i_id;
int i_input_id; int i_input_id;
int i_showflags; int i_showflags;
bool b_is_node; bool b_is_node;
input_item_t *p_input;
private: private:
void init( int, int, bool, PLItem *, PLModel *, QSettings * ); void init( playlist_item_t *, PLItem *, PLModel *, QSettings * );
void updateColumnHeaders(); void updateColumnHeaders();
PLItem *parentItem; PLItem *parentItem;
PLModel *model; PLModel *model;
......
...@@ -317,7 +317,34 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const ...@@ -317,7 +317,34 @@ 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 )
{ {
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 ) else if( role == Qt::DecorationRole && index.column() == 0 )
{ {
...@@ -350,9 +377,25 @@ int PLModel::itemId( const QModelIndex &index ) const ...@@ -350,9 +377,25 @@ 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
{ {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) int metadata=1;
return QVariant( rootItem->columnString( section ) ); int running_index=-1;
return QVariant(); 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 ) QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
...@@ -407,7 +450,17 @@ QModelIndex PLModel::parent( const QModelIndex &index ) const ...@@ -407,7 +450,17 @@ QModelIndex PLModel::parent( const QModelIndex &index ) const
int PLModel::columnCount( const QModelIndex &i) 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 int PLModel::childrenCount( const QModelIndex &parent ) const
...@@ -874,7 +927,7 @@ void PLModel::viewchanged( int meta ) ...@@ -874,7 +927,7 @@ void PLModel::viewchanged( int meta )
} }
/* UNUSED emit layoutAboutToBeChanged(); */ /* UNUSED emit layoutAboutToBeChanged(); */
index = __MIN( index, rootItem->item_col_strings.count() ); index = __MIN( index, columnCount() );
QModelIndex parent = createIndex( 0, 0, rootItem ); QModelIndex parent = createIndex( 0, 0, rootItem );
if( rootItem->i_showflags & meta ) if( rootItem->i_showflags & meta )
...@@ -883,7 +936,6 @@ void PLModel::viewchanged( int meta ) ...@@ -883,7 +936,6 @@ void PLModel::viewchanged( int meta )
beginRemoveColumns( parent, index, index+1 ); beginRemoveColumns( parent, index, index+1 );
rootItem->i_showflags &= ~( meta ); rootItem->i_showflags &= ~( meta );
getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags ); getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
rootItem->updateColumnHeaders();
endRemoveColumns(); endRemoveColumns();
} }
else else
...@@ -892,7 +944,6 @@ void PLModel::viewchanged( int meta ) ...@@ -892,7 +944,6 @@ void PLModel::viewchanged( int meta )
beginInsertColumns( parent, index, index+1 ); beginInsertColumns( parent, index, index+1 );
rootItem->i_showflags |= meta; rootItem->i_showflags |= meta;
getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags ); getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
rootItem->updateColumnHeaders();
endInsertColumns(); endInsertColumns();
} }
emit columnsChanged( meta ); 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