mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 11:04:01 +02:00
* Added custom UserRoles to access model's data.
This commit is contained in:
@@ -268,15 +268,7 @@ PlayableModel::data( const QModelIndex& index, int role ) const
|
|||||||
if ( !entry )
|
if ( !entry )
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
switch ( role )
|
if ( role == PlayableProxyModel::TypeRole )
|
||||||
{
|
|
||||||
case Qt::TextAlignmentRole:
|
|
||||||
{
|
|
||||||
return QVariant( columnAlignment( index.column() ) );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case PlayableProxyModel::TypeRole:
|
|
||||||
{
|
{
|
||||||
if ( entry->result() )
|
if ( entry->result() )
|
||||||
{
|
{
|
||||||
@@ -294,6 +286,21 @@ PlayableModel::data( const QModelIndex& index, int role ) const
|
|||||||
{
|
{
|
||||||
return Tomahawk::TypeAlbum;
|
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 )
|
||||||
|
{
|
||||||
|
case Qt::TextAlignmentRole:
|
||||||
|
{
|
||||||
|
return QVariant( columnAlignment( index.column() ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,7 +308,7 @@ PlayableModel::data( const QModelIndex& index, int role ) const
|
|||||||
{
|
{
|
||||||
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() )
|
||||||
{
|
{
|
||||||
|
@@ -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();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user