mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-15 02:24:50 +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 )
|
||||
return QVariant();
|
||||
|
||||
switch ( role )
|
||||
{
|
||||
case Qt::TextAlignmentRole:
|
||||
{
|
||||
return QVariant( columnAlignment( index.column() ) );
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayableProxyModel::TypeRole:
|
||||
if ( role == PlayableProxyModel::TypeRole )
|
||||
{
|
||||
if ( entry->result() )
|
||||
{
|
||||
@@ -294,6 +286,21 @@ PlayableModel::data( const QModelIndex& index, int role ) const
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -301,7 +308,7 @@ PlayableModel::data( const QModelIndex& index, int role ) const
|
||||
{
|
||||
if ( !entry->query().isNull() )
|
||||
{
|
||||
return queryData( entry->query(), index.column(), role );
|
||||
return queryData( entry->query(), column, role );
|
||||
}
|
||||
else if ( !entry->artist().isNull() )
|
||||
{
|
||||
|
@@ -55,6 +55,25 @@ public:
|
||||
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 );
|
||||
virtual ~PlayableModel();
|
||||
|
||||
|
Reference in New Issue
Block a user