1 #include "playlist_model.h"
3 //=========================================================
4 PlaylistModel::PlaylistModel( QObject
*parent
)
5 : QAbstractItemModel( parent
)
9 //=========================================================
10 QVariant
PlaylistModel::data( const QModelIndex
&index
, int role
) const
12 // invalid index position, so we return nothing
13 if( !index
.isValid() || index
.column() > 0 || index
.row() >= items
.size())
16 // return the title of the song for the display role
19 return items
[ index
.row()].name
;
22 // for unhandled roles, we just return NULL data
25 //=========================================================
26 QModelIndex
PlaylistModel::index( int row
, int col
, const QModelIndex
&parent
) const
28 // return invalid index for invalid input parameters
29 if( col
!= 0 || row
< 0 || parent
.isValid())
32 // row cannot be larger then size of the playlist
33 if( row
>= items
.size())
36 // ok, this is a valid row,col so we return a valid index for it
37 return createIndex( row
, col
);
39 //=========================================================
40 QModelIndex
PlaylistModel::parent( const QModelIndex
&index
) const
42 // No parents for any index - flat list