Add a skeleton model for the playlist view
[soundwave.git] / playlist_model.cpp
blob0726fe12937af55c0af0830cabe8cea0af8e9115
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())
14 return QVariant();
16 // return the title of the song for the display role
17 switch( role ){
18 case Qt::DisplayRole:
19 return items[ index.row()].name;
22 // for unhandled roles, we just return NULL data
23 return QVariant();
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())
30 return QModelIndex();
32 // row cannot be larger then size of the playlist
33 if( row >= items.size())
34 return QModelIndex();
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
43 return QModelIndex();