[vlc-commits] Qt: Extensions: fullfill usage of data abstraction model

Francois Cartegnie git at videolan.org
Sun Jun 23 15:42:25 CEST 2013


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Jun 23 15:33:32 2013 +0200| [dd29c917a38d511eeada2fe575e92febc2df0773] | committer: Francois Cartegnie

Qt: Extensions: fullfill usage of data abstraction model

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

 modules/gui/qt4/dialogs/plugins.cpp |  108 +++++++++++++++++++----------------
 modules/gui/qt4/dialogs/plugins.hpp |   27 ++++++++-
 2 files changed, 85 insertions(+), 50 deletions(-)

diff --git a/modules/gui/qt4/dialogs/plugins.cpp b/modules/gui/qt4/dialogs/plugins.cpp
index 701341f..a606d2a 100644
--- a/modules/gui/qt4/dialogs/plugins.cpp
+++ b/modules/gui/qt4/dialogs/plugins.cpp
@@ -280,38 +280,58 @@ void ExtensionTab::keyPressEvent( QKeyEvent *keyEvent )
 void ExtensionTab::moreInformation()
 {
     QModelIndex index = extList->selectionModel()->selectedIndexes().first();
-    ExtensionCopy *ext = (ExtensionCopy*) index.internalPointer();
-    if( !ext )
+
+    if( !index.isValid() )
         return;
 
-    ExtensionInfoDialog dlg( *ext, p_intf, this );
+    ExtensionInfoDialog dlg( index, p_intf, this );
     dlg.exec();
 }
 
 /* Safe copy of the extension_t struct */
-class ExtensionCopy
+ExtensionListModel::ExtensionCopy::ExtensionCopy( extension_t *p_ext )
+{
+    name = qfu( p_ext->psz_name );
+    description = qfu( p_ext->psz_description );
+    shortdesc = qfu( p_ext->psz_shortdescription );
+    if( description.isEmpty() )
+        description = shortdesc;
+    if( shortdesc.isEmpty() && !description.isEmpty() )
+        shortdesc = description;
+    title = qfu( p_ext->psz_title );
+    author = qfu( p_ext->psz_author );
+    version = qfu( p_ext->psz_version );
+    url = qfu( p_ext->psz_url );
+    icon = loadPixmapFromData( p_ext->p_icondata, p_ext->i_icondata_size );
+}
+
+ExtensionListModel::ExtensionCopy::~ExtensionCopy()
+{
+    delete icon;
+}
+
+QVariant ExtensionListModel::ExtensionCopy::data( int role ) const
 {
-public:
-    ExtensionCopy( extension_t *p_ext )
+    switch( role )
     {
-        name = qfu( p_ext->psz_name );
-        description = qfu( p_ext->psz_description );
-        shortdesc = qfu( p_ext->psz_shortdescription );
-        if( description.isEmpty() )
-            description = shortdesc;
-        if( shortdesc.isEmpty() && !description.isEmpty() )
-            shortdesc = description;
-        title = qfu( p_ext->psz_title );
-        author = qfu( p_ext->psz_author );
-        version = qfu( p_ext->psz_version );
-        url = qfu( p_ext->psz_url );
-        icon = loadPixmapFromData( p_ext->p_icondata, p_ext->i_icondata_size );
+    case Qt::DisplayRole:
+        return title;
+    case Qt::DecorationRole:
+        return *icon;
+    case DescriptionRole:
+        return shortdesc;
+    case VersionRole:
+        return version;
+    case AuthorRole:
+        return author;
+    case LinkRole:
+        return url;
+    case NameRole:
+        return name;
+    default:
+        return QVariant();
     }
-    ~ExtensionCopy() { delete icon; }
-
-    QString name, title, description, shortdesc, author, version, url;
-    QPixmap *icon;
-};
+}
 
 /* Extensions list model for the QListView */
 
@@ -385,17 +405,10 @@ QVariant ExtensionListModel::data( const QModelIndex& index, int role ) const
     if( !index.isValid() )
         return QVariant();
 
-    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();
-    }
+    ExtensionCopy * extension =
+            static_cast<ExtensionCopy *>(index.internalPointer());
+
+    return extension->data( role );
 }
 
 QModelIndex ExtensionListModel::index( int row, int column,
@@ -501,7 +514,7 @@ QSize ExtensionItemDelegate::sizeHint( const QStyleOptionViewItem &option,
 
 /* "More information" dialog */
 
-ExtensionInfoDialog::ExtensionInfoDialog( const ExtensionCopy& extension,
+ExtensionInfoDialog::ExtensionInfoDialog( const QModelIndex &index,
                                           intf_thread_t *p_intf,
                                           QWidget *parent )
        : QVLCDialog( parent, p_intf )
@@ -510,28 +523,25 @@ ExtensionInfoDialog::ExtensionInfoDialog( const ExtensionCopy& extension,
     setWindowModality( Qt::WindowModal );
 
     // Window title
-    setWindowTitle( qtr( "About" ) + " " + extension.title );
+    setWindowTitle( qtr( "About" ) + " " + index.data(Qt::DisplayRole).toString() );
 
     // Layout
     QGridLayout *layout = new QGridLayout( this );
 
     // Icon
     QLabel *icon = new QLabel( this );
-    if( !extension.icon )
+    QPixmap pix = index.data(Qt::DecorationRole).value<QPixmap>();
+    if( pix.isNull() )
     {
-        QPixmap pix( ":/logo/vlc48.png" );
+        pix = QPixmap( ":/logo/vlc48.png" );
         icon->setPixmap( pix );
     }
-    else
-    {
-        icon->setPixmap( *extension.icon );
-    }
     icon->setAlignment( Qt::AlignCenter );
     icon->setFixedSize( 48, 48 );
     layout->addWidget( icon, 1, 0, 2, 1 );
 
     // Title
-    QLabel *label = new QLabel( extension.title, this );
+    QLabel *label = new QLabel( index.data(Qt::DisplayRole).toString(), this );
     QFont font = label->font();
     font.setBold( true );
     font.setPointSizeF( font.pointSizeF() * 1.3f );
@@ -541,19 +551,19 @@ ExtensionInfoDialog::ExtensionInfoDialog( const ExtensionCopy& extension,
     // Version
     label = new QLabel( "<b>" + qtr( "Version" ) + ":</b>", this );
     layout->addWidget( label, 1, 1, 1, 1, Qt::AlignBottom );
-    label = new QLabel( extension.version, this );
+    label = new QLabel( index.data(ExtensionListModel::VersionRole).toString(), this );
     layout->addWidget( label, 1, 2, 1, 2, Qt::AlignBottom );
 
     // Author
     label = new QLabel( "<b>" + qtr( "Author" ) + ":</b>", this );
     layout->addWidget( label, 2, 1, 1, 1, Qt::AlignTop );
-    label = new QLabel( extension.author, this );
+    label = new QLabel( index.data(ExtensionListModel::AuthorRole).toString(), this );
     layout->addWidget( label, 2, 2, 1, 2, Qt::AlignTop );
 
 
     // Description
     label = new QLabel( this );
-    label->setText( extension.description );
+    label->setText( index.data(ExtensionListModel::DescriptionRole).toString() );
     label->setWordWrap( true );
     label->setOpenExternalLinks( true );
     layout->addWidget( label, 4, 0, 1, -1 );
@@ -562,7 +572,8 @@ ExtensionInfoDialog::ExtensionInfoDialog( const ExtensionCopy& extension,
     label = new QLabel( "<b>" + qtr( "Website" ) + ":</b>", this );
     layout->addWidget( label, 5, 0, 1, 2 );
     label = new QLabel( QString("<a href=\"%1\">%2</a>")
-                        .arg( extension.url ).arg( extension.url )
+                        .arg( index.data(ExtensionListModel::LinkRole).toString() )
+                        .arg( index.data(ExtensionListModel::LinkRole).toString() )
                         , this );
     label->setOpenExternalLinks( true );
     layout->addWidget( label, 5, 2, 1, -1 );
@@ -570,7 +581,8 @@ ExtensionInfoDialog::ExtensionInfoDialog( const ExtensionCopy& extension,
     // Script file
     label = new QLabel( "<b>" + qtr( "File" ) + ":</b>", this );
     layout->addWidget( label, 6, 0, 1, 2 );
-    QLineEdit *line = new QLineEdit( extension.name, this );
+    QLineEdit *line =
+            new QLineEdit( index.data(ExtensionListModel::NameRole).toString(), this );
     line->setReadOnly( true );
     layout->addWidget( line, 6, 2, 1, -1 );
 
diff --git a/modules/gui/qt4/dialogs/plugins.hpp b/modules/gui/qt4/dialogs/plugins.hpp
index d1737b1..5b26800 100644
--- a/modules/gui/qt4/dialogs/plugins.hpp
+++ b/modules/gui/qt4/dialogs/plugins.hpp
@@ -132,10 +132,32 @@ class ExtensionListModel : public QAbstractListModel
     Q_OBJECT
 
 public:
+    /* Safe copy of the extension_t struct */
+    class ExtensionCopy
+    {
+
+    public:
+        ExtensionCopy( extension_t * );
+        ~ExtensionCopy();
+        QVariant data( int role ) const;
+
+    private:
+        QString name, title, description, shortdesc, author, version, url;
+        QPixmap *icon;
+    };
+
     ExtensionListModel( QListView *view, intf_thread_t *p_intf );
     virtual ~ExtensionListModel();
 
-    static const Qt::ItemDataRole DescriptionRole = Qt::UserRole;
+    enum
+    {
+        DescriptionRole = Qt::UserRole,
+        VersionRole,
+        AuthorRole,
+        LinkRole,
+        NameRole
+    };
+
     virtual QVariant data( const QModelIndex& index, int role ) const;
     virtual QModelIndex index( int row, int column = 0,
                                const QModelIndex& = QModelIndex() ) const;
@@ -145,6 +167,7 @@ private slots:
     void updateList();
 
 private:
+
     intf_thread_t *p_intf;
     QList<ExtensionCopy*> extensions;
 };
@@ -169,7 +192,7 @@ private:
 class ExtensionInfoDialog : public QVLCDialog
 {
 public:
-    ExtensionInfoDialog( const ExtensionCopy& extension,
+    ExtensionInfoDialog( const QModelIndex &index,
                          intf_thread_t *p_intf, QWidget *parent );
 };
 



More information about the vlc-commits mailing list