From 3ab8a432d9fc37c178ae400920792f199ea1294a Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 12 Jun 2013 06:05:52 +0200 Subject: [PATCH] * Added custom UserRoles to access model's data. --- src/libtomahawk/playlist/PlayableModel.cpp | 51 ++++++++++++---------- src/libtomahawk/playlist/PlayableModel.h | 19 ++++++++ 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index df8d9c096..211a79a41 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -268,6 +268,34 @@ PlayableModel::data( const QModelIndex& index, int role ) const if ( !entry ) 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 ) { case Qt::TextAlignmentRole: @@ -276,32 +304,11 @@ PlayableModel::data( const QModelIndex& index, int role ) const 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: { if ( !entry->query().isNull() ) { - return queryData( entry->query(), index.column(), role ); + return queryData( entry->query(), column, role ); } else if ( !entry->artist().isNull() ) { diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index 4f0d91dfd..c148a76f8 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -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();