1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-13 01:24:11 +02:00

* Added custom UserRoles to access model's data.

This commit is contained in:
Christian Muehlhaeuser
2013-06-12 06:05:52 +02:00
parent 2bd3061516
commit 3ab8a432d9
2 changed files with 48 additions and 22 deletions

View File

@@ -268,6 +268,34 @@ PlayableModel::data( const QModelIndex& index, int role ) const
if ( !entry ) if ( !entry )
return QVariant(); return QVariant();
if ( role == PlayableProxyModel::TypeRole )
{
if ( entry->result() )
{
return Tomahawk::TypeResult;
}
else if ( entry->query() )
{
return Tomahawk::TypeQuery;
}
else if ( entry->artist() )
{
return Tomahawk::TypeArtist;
}
else if ( entry->album() )
{
return Tomahawk::TypeAlbum;
}
}
int column = index.column();
if ( role < CoverIDRole && role >= Qt::UserRole )
{
// map role to column
column = role - Qt::UserRole;
role = Qt::DisplayRole;
}
switch ( role ) switch ( role )
{ {
case Qt::TextAlignmentRole: case Qt::TextAlignmentRole:
@@ -276,32 +304,11 @@ PlayableModel::data( const QModelIndex& index, int role ) const
break; break;
} }
case PlayableProxyModel::TypeRole:
{
if ( entry->result() )
{
return Tomahawk::TypeResult;
}
else if ( entry->query() )
{
return Tomahawk::TypeQuery;
}
else if ( entry->artist() )
{
return Tomahawk::TypeArtist;
}
else if ( entry->album() )
{
return Tomahawk::TypeAlbum;
}
break;
}
default: default:
{ {
if ( !entry->query().isNull() ) if ( !entry->query().isNull() )
{ {
return queryData( entry->query(), index.column(), role ); return queryData( entry->query(), column, role );
} }
else if ( !entry->artist().isNull() ) else if ( !entry->artist().isNull() )
{ {

View File

@@ -55,6 +55,25 @@ public:
Name = 12 Name = 12
}; };
enum PlayableRoles
{
ArtistRole = Qt::UserRole,
TrackRole,
ComposerRole,
AlbumRole,
AlbumPosRole,
DurationRole,
BitrateRole,
AgeRole,
YearRole,
FilesizeRole,
OriginRole,
ScoreRole,
NameRole,
CoverIDRole,
IsPlayingRole
};
explicit PlayableModel( QObject* parent = 0, bool loading = true ); explicit PlayableModel( QObject* parent = 0, bool loading = true );
virtual ~PlayableModel(); virtual ~PlayableModel();