[vlc-devel] commit: Qt4: store input_item_t* in plitem and handle metadata in model ( Ilkka Ollakka )
git version control
git at videolan.org
Thu Aug 13 14:48:20 CEST 2009
vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Thu Aug 13 15:42:23 2009 +0300| [b3b361b083b2ed50df10b7269d6b72787f8bb305] | committer: 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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b3b361b083b2ed50df10b7269d6b72787f8bb305
---
.../gui/qt4/components/playlist/playlist_item.cpp | 58 +++--------------
.../gui/qt4/components/playlist/playlist_item.hpp | 6 +-
.../gui/qt4/components/playlist/playlist_model.cpp | 67 +++++++++++++++++---
3 files changed, 70 insertions(+), 61 deletions(-)
diff --git a/modules/gui/qt4/components/playlist/playlist_item.cpp b/modules/gui/qt4/components/playlist/playlist_item.cpp
index b0436f0..4b54806 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.cpp
@@ -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 );
- }
- }
}
diff --git a/modules/gui/qt4/components/playlist/playlist_item.hpp b/modules/gui/qt4/components/playlist/playlist_item.hpp
index c9d186b..daa831a 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.hpp
@@ -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;
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 8329279..c6fc9a4 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -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 ) );
- return QVariant();
+ 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 );
More information about the vlc-devel
mailing list