Commit 8d19eace authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: ExtensionsModel: use data abstraction in delegate

parent 804c64f3
...@@ -387,6 +387,12 @@ QVariant ExtensionListModel::data( const QModelIndex& index, int role ) const ...@@ -387,6 +387,12 @@ QVariant ExtensionListModel::data( const QModelIndex& index, int role ) const
switch( role ) 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: default:
return QVariant(); return QVariant();
} }
...@@ -419,9 +425,6 @@ void ExtensionItemDelegate::paint( QPainter *painter, ...@@ -419,9 +425,6 @@ void ExtensionItemDelegate::paint( QPainter *painter,
const QStyleOptionViewItem &option, const QStyleOptionViewItem &option,
const QModelIndex &index ) const const QModelIndex &index ) const
{ {
ExtensionCopy *ext = ( ExtensionCopy* ) index.internalPointer();
assert( ext != NULL );
int width = option.rect.width(); int width = option.rect.width();
// Pixmap: buffer where to draw // Pixmap: buffer where to draw
...@@ -453,10 +456,11 @@ void ExtensionItemDelegate::paint( QPainter *painter, ...@@ -453,10 +456,11 @@ void ExtensionItemDelegate::paint( QPainter *painter,
QFontMetrics metrics = option.fontMetrics; QFontMetrics metrics = option.fontMetrics;
// Icon // 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(), pixpaint->drawPixmap( 7, 7, 2*metrics.height(), 2*metrics.height(),
*ext->icon ); icon );
} }
// Title: bold // Title: bold
...@@ -466,7 +470,7 @@ void ExtensionItemDelegate::paint( QPainter *painter, ...@@ -466,7 +470,7 @@ void ExtensionItemDelegate::paint( QPainter *painter,
pixpaint->drawText( QRect( 17 + 2 * metrics.height(), 7, pixpaint->drawText( QRect( 17 + 2 * metrics.height(), 7,
width - 40 - 2 * metrics.height(), width - 40 - 2 * metrics.height(),
metrics.height() ), metrics.height() ),
Qt::AlignLeft, ext->title ); Qt::AlignLeft, index.data( Qt::DisplayRole ).toString() );
// Short description: normal // Short description: normal
font.setBold( false ); font.setBold( false );
...@@ -474,7 +478,7 @@ void ExtensionItemDelegate::paint( QPainter *painter, ...@@ -474,7 +478,7 @@ void ExtensionItemDelegate::paint( QPainter *painter,
pixpaint->drawText( QRect( 17 + 2 * metrics.height(), pixpaint->drawText( QRect( 17 + 2 * metrics.height(),
7 + metrics.height(), width - 40, 7 + metrics.height(), width - 40,
metrics.height() ), metrics.height() ),
Qt::AlignLeft, ext->shortdesc ); Qt::AlignLeft, index.data( ExtensionListModel::DescriptionRole ).toString() );
// Flush paint operations // Flush paint operations
delete pixpaint; delete pixpaint;
......
...@@ -135,6 +135,7 @@ public: ...@@ -135,6 +135,7 @@ public:
ExtensionListModel( QListView *view, intf_thread_t *p_intf ); ExtensionListModel( QListView *view, intf_thread_t *p_intf );
virtual ~ExtensionListModel(); virtual ~ExtensionListModel();
static const Qt::ItemDataRole DescriptionRole = Qt::UserRole;
virtual QVariant data( const QModelIndex& index, int role ) const; virtual QVariant data( const QModelIndex& index, int role ) const;
virtual QModelIndex index( int row, int column = 0, virtual QModelIndex index( int row, int column = 0,
const QModelIndex& = QModelIndex() ) const; const QModelIndex& = QModelIndex() ) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment