]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/plugins.cpp
Qt: ExtensionsModel: use data abstraction in delegate
[vlc] / modules / gui / qt4 / dialogs / plugins.cpp
index 4d84ec9411065493026b62b43dfbff8dc7aed72d..701341f0acb1fafcb0eb11f123c907fb29f56aaa 100644 (file)
@@ -130,11 +130,13 @@ PluginTab::PluginTab( intf_thread_t *p_intf_ )
 
 inline void PluginTab::FillTree()
 {
-    module_t **p_list = module_list_get( NULL );
-    module_t *p_module;
+    size_t count;
+    module_t **p_list = module_list_get( &count );
 
-    for( unsigned int i = 0; (p_module = p_list[i] ) != NULL; i++ )
+    for( unsigned int i = 0; i < count; i++ )
     {
+        module_t *p_module = p_list[i];
+
         QStringList qs_item;
         qs_item << qfu( module_get_name( p_module, true ) )
                 << qfu( module_get_capability( p_module ) )
@@ -181,8 +183,15 @@ void PluginTab::keyPressEvent( QKeyEvent *keyEvent )
 bool PluginTreeItem::operator< ( const QTreeWidgetItem & other ) const
 {
     int col = treeWidget()->sortColumn();
-    if( col == 2 )
+    if( col == PluginTab::SCORE )
         return text( col ).toInt() < other.text( col ).toInt();
+    else if ( col == PluginTab::CAPABILITY )
+    {
+        if ( text( PluginTab::CAPABILITY ) == other.text( PluginTab::CAPABILITY ) )
+            return text( PluginTab::NAME ) < other.text( PluginTab::NAME );
+        else
+            return text( PluginTab::CAPABILITY ) < other.text( PluginTab::CAPABILITY );
+    }
     return text( col ) < other.text( col );
 }
 
@@ -298,7 +307,7 @@ public:
         url = qfu( p_ext->psz_url );
         icon = loadPixmapFromData( p_ext->p_icondata, p_ext->i_icondata_size );
     }
-    ~ExtensionCopy() {}
+    ~ExtensionCopy() { delete icon; }
 
     QString name, title, description, shortdesc, author, version, url;
     QPixmap *icon;
@@ -378,6 +387,12 @@ QVariant ExtensionListModel::data( const QModelIndex& index, int role ) const
 
     switch( role )
     {
+    case Qt::DisplayRole:
+        return ((ExtensionCopy *)index.internalPointer())->title;
+    case Qt::DecorationRole:
+        return *((ExtensionCopy *)index.internalPointer())->icon;
+    case DescriptionRole:
+        return ((ExtensionCopy *)index.internalPointer())->shortdesc;
     default:
         return QVariant();
     }
@@ -410,9 +425,6 @@ void ExtensionItemDelegate::paint( QPainter *painter,
                                    const QStyleOptionViewItem &option,
                                    const QModelIndex &index ) const
 {
-    ExtensionCopy *ext = ( ExtensionCopy* ) index.internalPointer();
-    assert( ext != NULL );
-
     int width = option.rect.width();
 
     // Pixmap: buffer where to draw
@@ -444,10 +456,11 @@ void ExtensionItemDelegate::paint( QPainter *painter,
     QFontMetrics metrics = option.fontMetrics;
 
     // Icon
-    if( ext->icon != NULL )
+    QPixmap icon = index.data( Qt::DecorationRole ).value<QPixmap>();
+    if( !icon.isNull() )
     {
         pixpaint->drawPixmap( 7, 7, 2*metrics.height(), 2*metrics.height(),
-                              *ext->icon );
+                              icon );
     }
 
     // Title: bold
@@ -457,7 +470,7 @@ void ExtensionItemDelegate::paint( QPainter *painter,
     pixpaint->drawText( QRect( 17 + 2 * metrics.height(), 7,
                                width - 40 - 2 * metrics.height(),
                                metrics.height() ),
-                        Qt::AlignLeft, ext->title );
+                        Qt::AlignLeft, index.data( Qt::DisplayRole ).toString() );
 
     // Short description: normal
     font.setBold( false );
@@ -465,7 +478,7 @@ void ExtensionItemDelegate::paint( QPainter *painter,
     pixpaint->drawText( QRect( 17 + 2 * metrics.height(),
                                7 + metrics.height(), width - 40,
                                metrics.height() ),
-                        Qt::AlignLeft, ext->shortdesc );
+                        Qt::AlignLeft, index.data( ExtensionListModel::DescriptionRole ).toString() );
 
     // Flush paint operations
     delete pixpaint;