1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

Expose name and isPlaying status in TreeModel

This commit is contained in:
Dominik Schmidt
2011-09-07 09:31:53 +02:00
parent 0d0f9be3f2
commit a0c3806da7
2 changed files with 21 additions and 3 deletions

View File

@@ -49,6 +49,11 @@ TreeModel::TreeModel( QObject* parent )
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[IsPlayingRole] = "isPlaying";
setRoleNames(roles);
}
@@ -277,17 +282,25 @@ TreeModel::data( const QModelIndex& index, int role ) const
return QSize( 128, 0 );
}
if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole )
if ( role != Qt::DisplayRole && !roleNames().contains( role ) ) // && role != Qt::ToolTipRole )
return QVariant();
if ( !entry->artist().isNull() && index.column() == Name )
if ( role == IsPlayingRole )
return entry->isPlaying();
if ( !entry->artist().isNull() && ( index.column() == Name || role == NameRole ) )
{
return entry->artist()->name();
}
else if ( !entry->album().isNull() && index.column() == Name )
else if ( !entry->album().isNull() && ( index.column() == Name || role == NameRole ) )
{
return entry->album()->name();
}
else if ( role = NameRole )
{
return entry->result()->track();
}
else
{
const result_ptr& result = entry->result();

View File

@@ -50,6 +50,11 @@ public:
AlbumPosition
};
enum Roles {
NameRole = Qt::UserRole + 1,
IsPlayingRole
};
enum ColumnStyle // Default style is AllColumns
{ AllColumns = 0, TrackOnly };