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