diff --git a/src/playlist/collectionflatmodel.cpp b/src/playlist/collectionflatmodel.cpp index 99fde136c..9d3592a7b 100644 --- a/src/playlist/collectionflatmodel.cpp +++ b/src/playlist/collectionflatmodel.cpp @@ -23,111 +23,21 @@ CollectionFlatModel::~CollectionFlatModel() int CollectionFlatModel::columnCount( const QModelIndex& parent ) const { - return 6; + return TrackModel::columnCount( parent ); } QVariant CollectionFlatModel::data( const QModelIndex& index, int role ) const { - PlItem* entry = itemFromIndex( index ); - if ( !entry ) - return QVariant(); - - if ( role == Qt::DecorationRole ) - { - if ( index.column() == 0 && entry->isPlaying() ) - return QString( RESPATH "images/now-playing-speaker.png" ); - - return QVariant(); - } - - if ( role == Qt::SizeHintRole ) - { - return QSize( 0, 18 ); - } - - if ( role != Qt::DisplayRole ) - return QVariant(); - - const query_ptr& query = entry->query(); - if ( query.isNull() ) - { - if ( !index.column() ) - { - return entry->caption.isEmpty() ? "Unknown" : entry->caption; - } - - if ( index.column() == 1 ) - { - return entry->childCount; - } - - return QVariant( "" ); - } - - if ( !query->numResults() ) - { - switch( index.column() ) - { - case 0: - return query->artist(); - break; - - case 1: - return query->track(); - break; - - case 2: - return query->album(); - break; - } - } - else - { - switch( index.column() ) - { - case 0: - return query->results().first()->artist(); - break; - - case 1: - return query->results().first()->track(); - break; - - case 2: - return query->results().first()->album(); - break; - - case 3: - return TomahawkUtils::timeToString( query->results().first()->duration() ); - break; - - case 4: - return query->results().first()->bitrate(); - break; - - case 5: - return query->results().first()->collection()->source()->friendlyName(); - break; - } - } - - return QVariant(); + return TrackModel::data( index, role ); } QVariant CollectionFlatModel::headerData( int section, Qt::Orientation orientation, int role ) const { - QStringList headers; - headers << tr( "Artist" ) << tr( "Track" ) << tr( "Album" ) << tr( "Duration" ) << tr( "Bitrate" ) << tr( "Origin" ); - if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 ) - { - return headers.at( section ); - } - - return QVariant(); + return TrackModel::headerData( section, orientation, role ); } diff --git a/src/playlist/playlistmodel.cpp b/src/playlist/playlistmodel.cpp index c6fe0f506..b220f9dd8 100644 --- a/src/playlist/playlistmodel.cpp +++ b/src/playlist/playlistmodel.cpp @@ -23,111 +23,21 @@ PlaylistModel::~PlaylistModel() int PlaylistModel::columnCount( const QModelIndex& parent ) const { - return 6; + return TrackModel::columnCount( parent ); } QVariant PlaylistModel::data( const QModelIndex& index, int role ) const { - PlItem* entry = itemFromIndex( index ); - if ( !entry ) - return QVariant(); - - if ( role == Qt::DecorationRole ) - { - if ( index.column() == 0 && entry->isPlaying() ) - return QString( RESPATH "images/now-playing-speaker.png" ); - - return QVariant(); - } - - if ( role == Qt::SizeHintRole ) - { - return QSize( 0, 18 ); - } - - if ( role != Qt::DisplayRole ) - return QVariant(); - - const query_ptr& query = entry->query(); - if ( query.isNull() ) - { - if ( !index.column() ) - { - return entry->caption.isEmpty() ? "Unknown" : entry->caption; - } - - if ( index.column() == 1 ) - { - return entry->childCount; - } - - return QVariant( "" ); - } - - if ( !query->numResults() ) - { - switch( index.column() ) - { - case 0: - return query->artist(); - break; - - case 1: - return query->track(); - break; - - case 2: - return query->album(); - break; - } - } - else - { - switch( index.column() ) - { - case 0: - return query->results().first()->artist(); - break; - - case 1: - return query->results().first()->track(); - break; - - case 2: - return query->results().first()->album(); - break; - - case 3: - return TomahawkUtils::timeToString( query->results().first()->duration() ); - break; - - case 4: - return query->results().first()->bitrate(); - break; - - case 5: - return query->results().first()->collection()->source()->friendlyName(); - break; - } - } - - return QVariant(); + return TrackModel::data( index, role ); } QVariant PlaylistModel::headerData( int section, Qt::Orientation orientation, int role ) const { - QStringList headers; - headers << tr( "Artist" ) << tr( "Track" ) << tr( "Album" ) << tr( "Duration" ) << tr( "Bitrate" ) << tr( "Origin" ); - if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 ) - { - return headers.at( section ); - } - - return QVariant(); + return TrackModel::headerData( section, orientation, role ); } diff --git a/src/playlist/trackmodel.cpp b/src/playlist/trackmodel.cpp index b1eb51e65..b90f06ec9 100644 --- a/src/playlist/trackmodel.cpp +++ b/src/playlist/trackmodel.cpp @@ -54,7 +54,7 @@ TrackModel::rowCount( const QModelIndex& parent ) const int TrackModel::columnCount( const QModelIndex& parent ) const { - return 0; + return 6; } @@ -81,6 +81,89 @@ TrackModel::parent( const QModelIndex& child ) const QVariant TrackModel::data( const QModelIndex& index, int role ) const { + PlItem* entry = itemFromIndex( index ); + if ( !entry ) + return QVariant(); + + if ( role == Qt::DecorationRole ) + { + if ( index.column() == 0 && entry->isPlaying() ) + return QString( RESPATH "images/now-playing-speaker.png" ); + + return QVariant(); + } + + if ( role == Qt::SizeHintRole ) + { + return QSize( 0, 18 ); + } + + if ( role != Qt::DisplayRole ) + return QVariant(); + + const query_ptr& query = entry->query(); + if ( query.isNull() ) + { + if ( !index.column() ) + { + return entry->caption.isEmpty() ? "Unknown" : entry->caption; + } + + if ( index.column() == 1 ) + { + return entry->childCount; + } + + return QVariant( "" ); + } + + if ( !query->numResults() ) + { + switch( index.column() ) + { + case 0: + return query->artist(); + break; + + case 1: + return query->track(); + break; + + case 2: + return query->album(); + break; + } + } + else + { + switch( index.column() ) + { + case 0: + return query->results().first()->artist(); + break; + + case 1: + return query->results().first()->track(); + break; + + case 2: + return query->results().first()->album(); + break; + + case 3: + return TomahawkUtils::timeToString( query->results().first()->duration() ); + break; + + case 4: + return query->results().first()->bitrate(); + break; + + case 5: + return query->results().first()->collection()->source()->friendlyName(); + break; + } + } + return QVariant(); } @@ -88,6 +171,13 @@ TrackModel::data( const QModelIndex& index, int role ) const QVariant TrackModel::headerData( int section, Qt::Orientation orientation, int role ) const { + QStringList headers; + headers << tr( "Artist" ) << tr( "Track" ) << tr( "Album" ) << tr( "Duration" ) << tr( "Bitrate" ) << tr( "Origin" ); + if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 ) + { + return headers.at( section ); + } + return QVariant(); }