1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-08 23:26:40 +02:00

* Implemented new PlaylistInterface in Tree- & PlayableProxyModelPlaylistInterface.

This commit is contained in:
Christian Muehlhaeuser
2012-11-28 08:02:43 +01:00
parent ef3fff210e
commit 91c1bc63cd
4 changed files with 62 additions and 19 deletions

View File

@@ -111,7 +111,7 @@ PlayableProxyModelPlaylistInterface::onModelChanged()
QList< Tomahawk::query_ptr > QList< Tomahawk::query_ptr >
PlayableProxyModelPlaylistInterface::tracks() PlayableProxyModelPlaylistInterface::tracks() const
{ {
if ( m_proxyModel.isNull() ) if ( m_proxyModel.isNull() )
return QList< query_ptr >(); return QList< query_ptr >();
@@ -148,7 +148,7 @@ PlayableProxyModelPlaylistInterface::setCurrentIndex( qint64 index )
qint64 qint64
PlayableProxyModelPlaylistInterface::siblingIndex( int itemsAway ) const PlayableProxyModelPlaylistInterface::siblingIndex( int itemsAway, qint64 rootIndex ) const
{ {
if ( m_proxyModel.isNull() ) if ( m_proxyModel.isNull() )
return -1; return -1;
@@ -209,14 +209,28 @@ PlayableProxyModelPlaylistInterface::siblingIndex( int itemsAway ) const
} }
} }
} }
else if ( proxyModel->currentIndex().isValid() ) else
{ {
// random mode is disabled if ( m_repeatMode == PlaylistModes::RepeatOne )
idx = proxyModel->currentIndex();
if ( m_repeatMode != PlaylistModes::RepeatOne )
{ {
// keep progressing through the playlist normally idx = proxyModel->currentIndex();
}
else
{
// random mode is disabled
if ( rootIndex == -1 )
{
idx = proxyModel->currentIndex();
}
else
{
PlayableItem* pitem = static_cast<PlayableItem*>( (void*)rootIndex );
if ( !pitem )
return -1;
idx = proxyModel->mapFromSource( pitem->index );
}
idx = proxyModel->index( idx.row() + itemsAway, 0 ); idx = proxyModel->index( idx.row() + itemsAway, 0 );
} }
} }

View File

@@ -39,7 +39,7 @@ public:
explicit PlayableProxyModelPlaylistInterface( PlayableProxyModel* proxyModel ); explicit PlayableProxyModelPlaylistInterface( PlayableProxyModel* proxyModel );
virtual ~PlayableProxyModelPlaylistInterface(); virtual ~PlayableProxyModelPlaylistInterface();
virtual QList<Tomahawk::query_ptr> tracks(); virtual QList<Tomahawk::query_ptr> tracks() const;
virtual int trackCount() const; virtual int trackCount() const;
@@ -50,7 +50,7 @@ public:
virtual qint64 indexOfQuery( const Tomahawk::query_ptr& query ) const; virtual qint64 indexOfQuery( const Tomahawk::query_ptr& query ) const;
virtual Tomahawk::result_ptr currentItem() const; virtual Tomahawk::result_ptr currentItem() const;
virtual qint64 siblingIndex( int itemsAway ) const; virtual qint64 siblingIndex( int itemsAway, qint64 rootIndex = -1 ) const;
virtual QString filter() const; virtual QString filter() const;

View File

@@ -83,13 +83,26 @@ TreeProxyModelPlaylistInterface::setCurrentIndex( qint64 index )
qint64 qint64
TreeProxyModelPlaylistInterface::siblingIndex( int itemsAway ) const TreeProxyModelPlaylistInterface::siblingIndex( int itemsAway, qint64 rootIndex ) const
{ {
if ( m_proxyModel.isNull() ) if ( m_proxyModel.isNull() )
return -1; return -1;
TreeProxyModel* proxyModel = m_proxyModel.data(); TreeProxyModel* proxyModel = m_proxyModel.data();
QModelIndex idx = proxyModel->currentIndex(); QModelIndex idx;
if ( rootIndex == -1 )
{
idx = proxyModel->currentIndex();
}
else
{
PlayableItem* pitem = static_cast<PlayableItem*>( (void*)rootIndex );
if ( !pitem )
return -1;
idx = proxyModel->mapFromSource( pitem->index );
}
if ( !idx.isValid() ) if ( !idx.isValid() )
return -1; return -1;
@@ -149,7 +162,7 @@ TreeProxyModelPlaylistInterface::currentItem() const
QList< Tomahawk::query_ptr > QList< Tomahawk::query_ptr >
TreeProxyModelPlaylistInterface::tracks() TreeProxyModelPlaylistInterface::tracks() const
{ {
Q_ASSERT( false ); Q_ASSERT( false );
QList< Tomahawk::query_ptr > queries; QList< Tomahawk::query_ptr > queries;
@@ -163,10 +176,26 @@ TreeProxyModelPlaylistInterface::indexOfResult( const result_ptr& result ) const
if ( m_proxyModel.isNull() ) if ( m_proxyModel.isNull() )
return -1; return -1;
QModelIndex idx = m_proxyModel.data()->indexFromResult( result ); PlayableItem* item = m_proxyModel.data()->itemFromResult( result );
if ( idx.isValid() ) if ( item )
{ {
return (qint64)( m_proxyModel.data()->mapToSource( idx ).internalPointer() ); return (qint64)( item->index.internalPointer() );
}
return -1;
}
qint64
TreeProxyModelPlaylistInterface::indexOfQuery( const query_ptr& query ) const
{
if ( m_proxyModel.isNull() )
return -1;
PlayableItem* item = m_proxyModel.data()->itemFromQuery( query );
if ( item )
{
return (qint64)( item->index.internalPointer() );
} }
return -1; return -1;

View File

@@ -39,17 +39,17 @@ public:
explicit TreeProxyModelPlaylistInterface( TreeProxyModel* proxyModel ); explicit TreeProxyModelPlaylistInterface( TreeProxyModel* proxyModel );
virtual ~TreeProxyModelPlaylistInterface(); virtual ~TreeProxyModelPlaylistInterface();
virtual QList< Tomahawk::query_ptr > tracks(); virtual QList< Tomahawk::query_ptr > tracks() const;
virtual int trackCount() const; virtual int trackCount() const;
virtual Tomahawk::result_ptr resultAt( qint64 index ) const; virtual Tomahawk::result_ptr resultAt( qint64 index ) const;
virtual Tomahawk::query_ptr queryAt( qint64 index ) const; virtual Tomahawk::query_ptr queryAt( qint64 index ) const;
virtual qint64 indexOfResult( const Tomahawk::result_ptr& result ) const; virtual qint64 indexOfResult( const Tomahawk::result_ptr& result ) const;
virtual qint64 indexOfQuery( const Tomahawk::query_ptr& query ) const { Q_UNUSED( query ); Q_ASSERT( false ); return -1; } virtual qint64 indexOfQuery( const Tomahawk::query_ptr& query ) const;
virtual void setCurrentIndex( qint64 index ); virtual void setCurrentIndex( qint64 index );
virtual Tomahawk::result_ptr currentItem() const; virtual Tomahawk::result_ptr currentItem() const;
virtual qint64 siblingIndex( int itemsAway ) const; virtual qint64 siblingIndex( int itemsAway, qint64 rootIndex = -1 ) const;
virtual QString filter() const; virtual QString filter() const;