mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 19:30:21 +02:00
* Move columnCount, headerData and data methods to TrackModel base-class.
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user