[vlc-devel] commit: qt4 playlist: refactor meta data retrieval and show meta title for sorting in popup menu (Jakob Leben )
git version control
git at videolan.org
Wed Aug 19 09:42:26 CEST 2009
vlc | branch: master | Jakob Leben <jleben at videolan.org> | Wed Aug 19 09:38:48 2009 +0200| [7635e6e85bd5eef07dcefb4ab0b9906940440073] | committer: Jakob Leben
qt4 playlist: refactor meta data retrieval and show meta title for sorting in popup menu
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7635e6e85bd5eef07dcefb4ab0b9906940440073
---
.../gui/qt4/components/playlist/playlist_model.cpp | 54 +++++++++----------
.../gui/qt4/components/playlist/playlist_model.hpp | 1 +
2 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 72e55a2..028f4be 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -349,10 +349,6 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
PLItem *item = static_cast<PLItem*>(index.internalPointer());
if( role == Qt::DisplayRole )
{
- int running_index = -1;
- int columncount = 0;
- int metadata = 1;
-
if( i_depth == DEPTH_SEL )
{
vlc_mutex_lock( &item->p_input->lock );
@@ -361,16 +357,8 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
return QVariant(returninfo);
}
- while( metadata < COLUMN_END )
- {
- if( i_showflags & metadata )
- running_index++;
- if( running_index == index.column() )
- break;
- metadata <<= 1;
- }
-
- if( running_index != index.column() ) return QVariant();
+ int metadata = metaColumn( index.column() );
+ if( metadata == COLUMN_END ) return QVariant();
QString returninfo;
if( metadata == COLUMN_NUMBER )
@@ -378,7 +366,7 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
else
{
char *psz = psz_column_meta( item->p_input, metadata );
- returninfo = QString( qfu( psz ) );
+ returninfo = qfu( psz );
free( psz );
}
return QVariant( returninfo );
@@ -415,25 +403,16 @@ int PLModel::itemId( const QModelIndex &index ) const
QVariant PLModel::headerData( int section, Qt::Orientation orientation,
int role ) const
{
- 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 & i_showflags )
- running_index++;
- if( running_index == section )
- break;
- metadata <<= 1;
- }
+ int meta_col = metaColumn( section );
- 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 )
@@ -641,6 +620,24 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
#undef CACHE
#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 *****************************/
void PLModel::customEvent( QEvent *event )
@@ -966,7 +963,8 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
if( node )
{
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" ),
this, SLOT( popupSortAsc() ) );
sort_menu->addAction( qtr( "Descending" ),
diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp
index caa4386..f8ee052 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.hpp
@@ -164,6 +164,7 @@ private:
PLItem *FindById( PLItem *, int );
PLItem *FindByInput( PLItem *, int );
PLItem *FindInner( PLItem *, int , bool );
+ int metaColumn ( int column ) const;
PLItem *p_cached_item;
PLItem *p_cached_item_bi;
int i_cached_id;
More information about the vlc-devel
mailing list