mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 02:54:33 +02:00
* Added model specific roles and updated data methods.
This commit is contained in:
committed by
Michael Zanetti
parent
c47d52b144
commit
2841593a85
@@ -44,6 +44,13 @@ PlayableModel::PlayableModel( QObject* parent, bool loading )
|
||||
, m_readOnly( true )
|
||||
, m_loading( loading )
|
||||
{
|
||||
QHash<int, QByteArray> roleNames;
|
||||
roleNames.insert( ArtistRole, "artistName" );
|
||||
roleNames.insert( TrackRole, "trackName" );
|
||||
roleNames.insert( CoverIDRole, "coverID" );
|
||||
roleNames.insert( IsPlayingRole, "isPlaying" );
|
||||
setRoleNames( roleNames );
|
||||
|
||||
connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( onPlaybackStarted( Tomahawk::result_ptr ) ), Qt::DirectConnection );
|
||||
connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( onPlaybackStopped() ), Qt::DirectConnection );
|
||||
|
||||
@@ -147,6 +154,12 @@ PlayableModel::parent( const QModelIndex& child ) const
|
||||
QVariant
|
||||
PlayableModel::artistData( const artist_ptr& artist, int role ) const
|
||||
{
|
||||
if ( role == CoverIDRole )
|
||||
{
|
||||
artist->cover( QSize( 0, 0 ) );
|
||||
return artist->coverId();
|
||||
}
|
||||
|
||||
if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole )
|
||||
return QVariant();
|
||||
|
||||
@@ -157,6 +170,12 @@ PlayableModel::artistData( const artist_ptr& artist, int role ) const
|
||||
QVariant
|
||||
PlayableModel::albumData( const album_ptr& album, int role ) const
|
||||
{
|
||||
if ( role == CoverIDRole )
|
||||
{
|
||||
album->cover( QSize( 0, 0 ) );
|
||||
return album->coverId();
|
||||
}
|
||||
|
||||
if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole )
|
||||
return QVariant();
|
||||
|
||||
@@ -167,6 +186,13 @@ PlayableModel::albumData( const album_ptr& album, int role ) const
|
||||
QVariant
|
||||
PlayableModel::queryData( const query_ptr& query, int column, int role ) const
|
||||
{
|
||||
if ( role == CoverIDRole )
|
||||
{
|
||||
query->track()->cover( QSize( 0, 0 ) );
|
||||
return query->track()->coverId();
|
||||
}
|
||||
|
||||
tDebug() << Q_FUNC_INFO << role;
|
||||
if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole )
|
||||
return QVariant();
|
||||
|
||||
@@ -287,6 +313,14 @@ PlayableModel::data( const QModelIndex& index, int role ) const
|
||||
if ( !entry )
|
||||
return QVariant();
|
||||
|
||||
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:
|
||||
@@ -295,6 +329,12 @@ PlayableModel::data( const QModelIndex& index, int role ) const
|
||||
break;
|
||||
}
|
||||
|
||||
case IsPlayingRole:
|
||||
{
|
||||
return entry->isPlaying();
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayableProxyModel::TypeRole:
|
||||
{
|
||||
if ( entry->result() )
|
||||
@@ -320,7 +360,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();
|
||||
|
||||
|
@@ -628,6 +628,15 @@ PlayableProxyModel::setFilter( const QString& pattern )
|
||||
}
|
||||
|
||||
|
||||
PlayableItem*
|
||||
PlayableProxyModel::itemFromIndex( int itemIndex ) const
|
||||
{
|
||||
// qDebug() << "returning item" << sourceModel()->itemFromIndex( itemIndex )->name();
|
||||
QModelIndex modelIndex = index( itemIndex, 0 );
|
||||
return sourceModel()->itemFromIndex( mapToSource( modelIndex ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableProxyModel::setCurrentIndex( const QModelIndex& index )
|
||||
{
|
||||
|
@@ -36,7 +36,7 @@ public:
|
||||
{ Detailed = 0, Short = 1, ShortWithAvatars = 2, Large = 3, Collection = 4 };
|
||||
|
||||
enum PlayableProxyModelRole
|
||||
{ StyleRole = Qt::UserRole + 1, TypeRole };
|
||||
{ StyleRole = Qt::UserRole + 100, TypeRole };
|
||||
|
||||
explicit PlayableProxyModel ( QObject* parent = 0 );
|
||||
virtual ~PlayableProxyModel() {}
|
||||
@@ -68,6 +68,7 @@ public:
|
||||
virtual int maxVisibleItems() const { return m_maxVisibleItems; }
|
||||
virtual void setMaxVisibleItems( int items );
|
||||
|
||||
Q_INVOKABLE virtual PlayableItem* itemFromIndex( int itemIndex ) const;
|
||||
virtual PlayableItem* itemFromIndex( const QModelIndex& index ) const { return sourceModel()->itemFromIndex( index ); }
|
||||
virtual PlayableItem* itemFromQuery( const Tomahawk::query_ptr& query ) const { return sourceModel()->itemFromQuery( query ); }
|
||||
virtual PlayableItem* itemFromResult( const Tomahawk::result_ptr& result ) const { return sourceModel()->itemFromResult( result ); }
|
||||
|
Reference in New Issue
Block a user