mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 00:09:47 +01:00
* Support item-sizes & adding various item_ptr's with templating in PlayableModel.
This commit is contained in:
parent
c6ba3bcc15
commit
811cd200d0
@ -288,6 +288,11 @@ PlayableModel::data( const QModelIndex& index, int role ) const
|
||||
return m_style;
|
||||
}
|
||||
|
||||
if ( role == Qt::SizeHintRole && !m_itemSize.isEmpty() )
|
||||
{
|
||||
return m_itemSize;
|
||||
}
|
||||
|
||||
if ( !entry->query().isNull() )
|
||||
{
|
||||
return queryData( entry->query()->displayQuery(), index.column(), role );
|
||||
@ -571,59 +576,48 @@ PlayableModel::queries() const
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void
|
||||
PlayableModel::append( const Tomahawk::query_ptr& query )
|
||||
PlayableModel::insertInternal( const T& item, int row )
|
||||
{
|
||||
insert( query, rowCount( QModelIndex() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::append( const QList< Tomahawk::query_ptr >& queries )
|
||||
{
|
||||
insert( queries, rowCount( QModelIndex() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::insert( const Tomahawk::query_ptr& query, int row )
|
||||
{
|
||||
if ( query.isNull() )
|
||||
if ( item.isNull() )
|
||||
return;
|
||||
|
||||
QList< Tomahawk::query_ptr > ql;
|
||||
ql << query;
|
||||
QList< T > list;
|
||||
list << item;
|
||||
|
||||
insert( ql, row );
|
||||
insertInternal( list, row );
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
PlayableModel::insert( const QList< Tomahawk::query_ptr >& queries, int row )
|
||||
PlayableModel::insertInternal( const QList< T >& items, int row )
|
||||
{
|
||||
if ( !queries.count() )
|
||||
if ( !items.count() )
|
||||
{
|
||||
emit trackCountChanged( rowCount( QModelIndex() ) );
|
||||
emit itemCountChanged( rowCount( QModelIndex() ) );
|
||||
return;
|
||||
}
|
||||
|
||||
int c = row;
|
||||
QPair< int, int > crows;
|
||||
crows.first = c;
|
||||
crows.second = c + queries.count() - 1;
|
||||
crows.second = c + items.count() - 1;
|
||||
|
||||
emit beginInsertRows( QModelIndex(), crows.first, crows.second );
|
||||
|
||||
int i = 0;
|
||||
PlayableItem* plitem;
|
||||
foreach( const query_ptr& query, queries )
|
||||
foreach( const T& item, items )
|
||||
{
|
||||
plitem = new PlayableItem( query, m_rootItem, row + i );
|
||||
plitem = new PlayableItem( item, m_rootItem, row + i );
|
||||
plitem->index = createIndex( row + i, 0, plitem );
|
||||
i++;
|
||||
|
||||
if ( query->id() == currentItemUuid() )
|
||||
setCurrentItem( plitem->index );
|
||||
/* if ( item->id() == currentItemUuid() )
|
||||
setCurrentItem( plitem->index );*/
|
||||
|
||||
connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
|
||||
}
|
||||
@ -744,7 +738,10 @@ PlayableModel::setStyle( PlayableModel::PlayableItemStyle style )
|
||||
Qt::Alignment
|
||||
PlayableModel::columnAlignment( int column ) const
|
||||
{
|
||||
switch( column )
|
||||
if ( !m_headerStyle.contains( m_style ) )
|
||||
return Qt::AlignLeft;
|
||||
|
||||
switch( m_headerStyle[ m_style ].at( column ) )
|
||||
{
|
||||
case Age:
|
||||
case AlbumPos:
|
||||
@ -798,3 +795,87 @@ PlayableModel::itemFromIndex( const QModelIndex& index ) const
|
||||
return m_rootItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::append( const Tomahawk::artist_ptr& artist )
|
||||
{
|
||||
insert( artist, rowCount( QModelIndex() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::append( const Tomahawk::album_ptr& album )
|
||||
{
|
||||
insert( album, rowCount( QModelIndex() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::append( const Tomahawk::query_ptr& query )
|
||||
{
|
||||
insert( query, rowCount( QModelIndex() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::append( const QList< Tomahawk::artist_ptr >& artists )
|
||||
{
|
||||
insert( artists, rowCount( QModelIndex() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::append( const QList< Tomahawk::album_ptr >& albums )
|
||||
{
|
||||
insert( albums, rowCount( QModelIndex() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::append( const QList< Tomahawk::query_ptr >& queries )
|
||||
{
|
||||
insert( queries, rowCount( QModelIndex() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::insert( const Tomahawk::artist_ptr& artist, int row )
|
||||
{
|
||||
insertInternal( artist, row );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::insert( const Tomahawk::album_ptr& album, int row )
|
||||
{
|
||||
insertInternal( album, row );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::insert( const Tomahawk::query_ptr& query, int row )
|
||||
{
|
||||
insertInternal( query, row );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::insert( const QList< Tomahawk::artist_ptr >& artists, int row )
|
||||
{
|
||||
insertInternal( artists, row );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::insert( const QList< Tomahawk::album_ptr >& albums, int row )
|
||||
{
|
||||
insertInternal( albums, row );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableModel::insert( const QList< Tomahawk::query_ptr >& queries, int row )
|
||||
{
|
||||
insertInternal( queries, row );
|
||||
}
|
||||
|
@ -112,6 +112,8 @@ public:
|
||||
QList< Tomahawk::query_ptr > queries() const;
|
||||
|
||||
void updateDetailedInfo( const QModelIndex& index );
|
||||
|
||||
void setItemSize( const QSize& size ) { m_itemSize = size; }
|
||||
|
||||
signals:
|
||||
void repeatModeChanged( Tomahawk::PlaylistModes::RepeatMode mode );
|
||||
@ -129,12 +131,18 @@ public slots:
|
||||
virtual void clear();
|
||||
|
||||
virtual void append( const QList< Tomahawk::query_ptr >& queries );
|
||||
virtual void append( const QList< Tomahawk::artist_ptr >& artists );
|
||||
virtual void append( const QList< Tomahawk::album_ptr >& albums );
|
||||
virtual void append( const Tomahawk::query_ptr& query );
|
||||
virtual void append( const Tomahawk::artist_ptr& artist ) { Q_UNUSED( artist ); }
|
||||
virtual void append( const Tomahawk::album_ptr& album ) { Q_UNUSED( album ); }
|
||||
virtual void append( const Tomahawk::artist_ptr& artist );
|
||||
virtual void append( const Tomahawk::album_ptr& album );
|
||||
|
||||
virtual void insert( const QList< Tomahawk::query_ptr >& queries, int row = 0 );
|
||||
virtual void insert( const QList< Tomahawk::artist_ptr >& artists, int row = 0 );
|
||||
virtual void insert( const QList< Tomahawk::album_ptr >& albums, int row = 0 );
|
||||
virtual void insert( const Tomahawk::query_ptr& query, int row = 0 );
|
||||
virtual void insert( const Tomahawk::artist_ptr& artist, int row = 0 );
|
||||
virtual void insert( const Tomahawk::album_ptr& album, int row = 0 );
|
||||
|
||||
virtual void remove( int row, bool moreToCome = false );
|
||||
virtual void remove( const QModelIndex& index, bool moreToCome = false );
|
||||
@ -156,11 +164,17 @@ private slots:
|
||||
void onPlaybackStopped();
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
void insertInternal( const QList< T >& items, int row );
|
||||
template <typename T>
|
||||
void insertInternal( const T& item, int row );
|
||||
|
||||
Qt::Alignment columnAlignment( int column ) const;
|
||||
|
||||
PlayableItem* m_rootItem;
|
||||
QPersistentModelIndex m_currentIndex;
|
||||
Tomahawk::QID m_currentUuid;
|
||||
QSize m_itemSize;
|
||||
|
||||
bool m_readOnly;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user