[vlc-commits] Qt: ExtensionsModel: use data abstraction in delegate

Francois Cartegnie git at videolan.org
Sun Jun 23 14:05:00 CEST 2013


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Jun 22 15:20:52 2013 +0200| [8d19eace8daccfce7d79d8f3a0cf9275fc1d88e3] | committer: Francois Cartegnie

Qt: ExtensionsModel: use data abstraction in delegate

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8d19eace8daccfce7d79d8f3a0cf9275fc1d88e3
---

 modules/gui/qt4/dialogs/plugins.cpp |   18 +++++++++++-------
 modules/gui/qt4/dialogs/plugins.hpp |    1 +
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/modules/gui/qt4/dialogs/plugins.cpp b/modules/gui/qt4/dialogs/plugins.cpp
index 20a6763..701341f 100644
--- a/modules/gui/qt4/dialogs/plugins.cpp
+++ b/modules/gui/qt4/dialogs/plugins.cpp
@@ -387,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();
     }
@@ -419,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
@@ -453,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
@@ -466,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 );
@@ -474,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;
diff --git a/modules/gui/qt4/dialogs/plugins.hpp b/modules/gui/qt4/dialogs/plugins.hpp
index 1bba5e1..d1737b1 100644
--- a/modules/gui/qt4/dialogs/plugins.hpp
+++ b/modules/gui/qt4/dialogs/plugins.hpp
@@ -135,6 +135,7 @@ public:
     ExtensionListModel( QListView *view, intf_thread_t *p_intf );
     virtual ~ExtensionListModel();
 
+    static const Qt::ItemDataRole DescriptionRole = Qt::UserRole;
     virtual QVariant data( const QModelIndex& index, int role ) const;
     virtual QModelIndex index( int row, int column = 0,
                                const QModelIndex& = QModelIndex() ) const;



More information about the vlc-commits mailing list