mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
* Move columnCount, headerData and data methods to TrackModel base-class.
This commit is contained in:
@@ -23,111 +23,21 @@ CollectionFlatModel::~CollectionFlatModel()
|
|||||||
int
|
int
|
||||||
CollectionFlatModel::columnCount( const QModelIndex& parent ) const
|
CollectionFlatModel::columnCount( const QModelIndex& parent ) const
|
||||||
{
|
{
|
||||||
return 6;
|
return TrackModel::columnCount( parent );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
QVariant
|
||||||
CollectionFlatModel::data( const QModelIndex& index, int role ) const
|
CollectionFlatModel::data( const QModelIndex& index, int role ) const
|
||||||
{
|
{
|
||||||
PlItem* entry = itemFromIndex( index );
|
return TrackModel::data( index, role );
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
QVariant
|
||||||
CollectionFlatModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
CollectionFlatModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
||||||
{
|
{
|
||||||
QStringList headers;
|
return TrackModel::headerData( section, orientation, role );
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -23,111 +23,21 @@ PlaylistModel::~PlaylistModel()
|
|||||||
int
|
int
|
||||||
PlaylistModel::columnCount( const QModelIndex& parent ) const
|
PlaylistModel::columnCount( const QModelIndex& parent ) const
|
||||||
{
|
{
|
||||||
return 6;
|
return TrackModel::columnCount( parent );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
QVariant
|
||||||
PlaylistModel::data( const QModelIndex& index, int role ) const
|
PlaylistModel::data( const QModelIndex& index, int role ) const
|
||||||
{
|
{
|
||||||
PlItem* entry = itemFromIndex( index );
|
return TrackModel::data( index, role );
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
QVariant
|
||||||
PlaylistModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
PlaylistModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
||||||
{
|
{
|
||||||
QStringList headers;
|
return TrackModel::headerData( section, orientation, role );
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -54,7 +54,7 @@ TrackModel::rowCount( const QModelIndex& parent ) const
|
|||||||
int
|
int
|
||||||
TrackModel::columnCount( const QModelIndex& parent ) const
|
TrackModel::columnCount( const QModelIndex& parent ) const
|
||||||
{
|
{
|
||||||
return 0;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -81,6 +81,89 @@ TrackModel::parent( const QModelIndex& child ) const
|
|||||||
QVariant
|
QVariant
|
||||||
TrackModel::data( const QModelIndex& index, int role ) const
|
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();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +171,13 @@ TrackModel::data( const QModelIndex& index, int role ) const
|
|||||||
QVariant
|
QVariant
|
||||||
TrackModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
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();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user