[vlc-devel] [PATCH 2/3] gui/qt: use QTableWidget instead of QTreeWidget for extra-metadata
Filip Roséen
filip at atch.se
Sat Feb 25 07:36:16 CET 2017
In terms of applicability, it makes more sense to store the extra
metadata in a table than in a tree, especially given that we don't
support nested metadata in either case.
---
modules/gui/qt/components/info_panels.cpp | 66 +++++++++++++++----------------
modules/gui/qt/components/info_panels.hpp | 3 +-
2 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/modules/gui/qt/components/info_panels.cpp b/modules/gui/qt/components/info_panels.cpp
index 340e524d9f..111474da64 100644
--- a/modules/gui/qt/components/info_panels.cpp
+++ b/modules/gui/qt/components/info_panels.cpp
@@ -39,6 +39,7 @@
#include <vlc_meta.h>
#include <QTreeWidget>
+#include <QTableWidget>
#include <QHeaderView>
#include <QList>
#include <QStringList>
@@ -396,11 +397,11 @@ ExtraMetaPanel::ExtraMetaPanel( QWidget *parent ) : QWidget( parent )
topLabel->setWordWrap( true );
layout->addWidget( topLabel, 0, 0 );
- extraMeta = new QTreeWidget( this );
+ extraMeta = new QTableWidget( this );
extraMeta->setAlternatingRowColors( true );
extraMeta->setColumnCount( 2 );
- extraMeta->resizeColumnToContents( 0 );
- extraMeta->setHeaderHidden( true );
+ extraMeta->horizontalHeader()->hide();
+ extraMeta->verticalHeader()->hide();
layout->addWidget( extraMeta, 1, 0 );
}
@@ -409,49 +410,46 @@ ExtraMetaPanel::ExtraMetaPanel( QWidget *parent ) : QWidget( parent )
**/
void ExtraMetaPanel::update( input_item_t *p_item )
{
+ extraMeta->setRowCount(0);
+
if( !p_item )
- {
- clear();
return;
- }
-
- QList<QTreeWidgetItem *> items;
- extraMeta->clear();
-
- vlc_mutex_lock( &p_item->lock );
+ vlc_mutex_locker meta_lock( &p_item->lock );
vlc_meta_t *p_meta = p_item->p_meta;
+
if( !p_meta )
- {
- vlc_mutex_unlock( &p_item->lock );
return;
- }
- const char *psz_disc_number = vlc_meta_Get( p_meta, vlc_meta_DiscNumber);
- if( psz_disc_number )
- {
- QStringList tempItem;
- tempItem.append( VLC_META_DISCNUMBER );
- tempItem.append( qfu( psz_disc_number ) );
- items.append( new QTreeWidgetItem ( extraMeta, tempItem ) );
- }
+ struct AddRowHelper {
+ AddRowHelper( QTableWidget* target ) : target( target ) { }
+
+ void operator()( char const* psz_key, char const* psz_value )
+ {
+ int idx = target->rowCount();
+
+ target->insertRow( idx );
+
+ target->setItem( idx, 0, new QTableWidgetItem( qfu( psz_key ) ) );
+ target->setItem( idx, 1, new QTableWidgetItem( qfu( psz_value ) ) );
+ }
+
+ QTableWidget* target;
+
+ } add_row ( extraMeta );
+
+ if( char const* psz_disc = vlc_meta_Get( p_meta, vlc_meta_DiscNumber ) )
+ add_row( VLC_META_DISCNUMBER, psz_disc );
- char ** ppsz_allkey = vlc_meta_CopyExtraNames( p_meta);
+ char ** ppsz_keys = vlc_meta_CopyExtraNames( p_meta );
- for( int i = 0; ppsz_allkey[i] ; i++ )
+ for( int i = 0; ppsz_keys[i]; ++i )
{
- const char * psz_value = vlc_meta_GetExtra( p_meta, ppsz_allkey[i] );
- QStringList tempItem;
- tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
- tempItem.append( qfu( psz_value ) );
- items.append( new QTreeWidgetItem ( extraMeta, tempItem ) );
- free( ppsz_allkey[i] );
+ add_row( ppsz_keys[i], vlc_meta_GetExtra( p_meta, ppsz_keys[i] ) );
+ free( ppsz_keys[i] );
}
- vlc_mutex_unlock( &p_item->lock );
- free( ppsz_allkey );
- extraMeta->addTopLevelItems( items );
- extraMeta->resizeColumnToContents( 0 );
+ extraMeta->verticalHeader()->resizeSections( QHeaderView::ResizeToContents );
}
/**
diff --git a/modules/gui/qt/components/info_panels.hpp b/modules/gui/qt/components/info_panels.hpp
index d0af544de4..f6b5e1b8b0 100644
--- a/modules/gui/qt/components/info_panels.hpp
+++ b/modules/gui/qt/components/info_panels.hpp
@@ -37,6 +37,7 @@
class QTreeWidget;
class QTreeWidgetItem;
+class QTableWidget;
class QSpinBox;
class QLineEdit;
class CoverArtLabel;
@@ -103,7 +104,7 @@ class ExtraMetaPanel: public QWidget
public:
ExtraMetaPanel( QWidget * );
private:
- QTreeWidget *extraMeta;
+ QTableWidget *extraMeta;
public slots:
void update( input_item_t * );
void clear();
--
2.11.1
More information about the vlc-devel
mailing list