1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-24 09:49:42 +01:00

* Use new model/view API.

This commit is contained in:
Christian Muehlhaeuser 2012-07-02 23:10:36 +02:00
parent bd629e6178
commit 01fb91ac59
15 changed files with 40 additions and 40 deletions

View File

@ -35,7 +35,7 @@ RelatedArtistsContext::RelatedArtistsContext()
m_relatedView->setGuid( "RelatedArtistsContext" );
m_relatedView->setUpdatesContextView( false );
m_relatedModel = new TreeModel( m_relatedView );
m_relatedModel->setStyle( TreeModel::Large );
m_relatedView->proxyModel()->setStyle( PlayableProxyModel::Large );
m_relatedView->setTreeModel( m_relatedModel );
m_relatedView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
m_relatedView->setSortingEnabled( false );

View File

@ -33,7 +33,7 @@ TopTracksContext::TopTracksContext()
m_topHitsView->setGuid( "TopTracksContext" );
m_topHitsView->setUpdatesContextView( false );
m_topHitsModel = new PlaylistModel( m_topHitsView );
m_topHitsModel->setStyle( PlayableModel::Short );
m_topHitsView->proxyModel()->setStyle( PlayableProxyModel::Short );
m_topHitsView->setPlaylistModel( m_topHitsModel );
m_topHitsView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );

View File

@ -34,7 +34,7 @@ CustomPlaylistView::CustomPlaylistView( CustomPlaylistView::PlaylistType type, c
, m_model( new PlaylistModel( this ) )
{
// Generate the tracks, add them to the playlist
m_model->setStyle( PlayableModel::Large );
proxyModel()->setStyle( PlayableProxyModel::Large );
setPlaylistModel( m_model );
generateTracks();

View File

@ -67,8 +67,8 @@ PlaylistItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModel
if ( index.isValid() )
{
int style = index.data( PlayableModel::StyleRole ).toInt();
if ( style == PlayableModel::Short || style == PlayableModel::ShortWithAvatars )
int style = index.data( PlayableProxyModel::StyleRole ).toInt();
if ( style == PlayableProxyModel::Short || style == PlayableProxyModel::ShortWithAvatars )
{
int rowHeight = option.fontMetrics.height() + 8;
size.setHeight( rowHeight * 2 );
@ -101,17 +101,17 @@ PlaylistItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const
void
PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
int style = index.data( PlayableModel::StyleRole ).toInt();
int style = index.data( PlayableProxyModel::StyleRole ).toInt();
switch ( style )
{
case PlayableModel::Detailed:
case PlayableProxyModel::Detailed:
paintDetailed( painter, option, index );
break;
case PlayableModel::Short:
case PlayableProxyModel::Short:
paintShort( painter, option, index );
break;
case PlayableModel::ShortWithAvatars:
case PlayableProxyModel::ShortWithAvatars:
paintShort( painter, option, index, true );
break;
}

View File

@ -62,15 +62,15 @@ PlaylistView::setPlaylistModel( PlaylistModel* model )
setColumnHidden( PlayableModel::Age, true ); // Hide age column per default
setColumnHidden( PlayableModel::Composer, true ); // Hide composer column per default
if ( guid().isEmpty() )
if ( guid().isEmpty() && proxyModel()->columnCount() > 1 )
{
if ( !m_model->playlist().isNull() )
{
setGuid( QString( "playlistview/%1/%2" ).arg( m_model->columnCount() ).arg( m_model->playlist()->guid() ) );
setGuid( QString( "playlistview/%1/%2" ).arg( proxyModel()->columnCount() ).arg( m_model->playlist()->guid() ) );
}
else
{
setGuid( QString( "playlistview/%1" ).arg( m_model->columnCount() ) );
setGuid( QString( "playlistview/%1" ).arg( proxyModel()->columnCount() ) );
}
}

View File

@ -47,7 +47,7 @@ QueueView::QueueView( AnimatedSplitter* parent )
ui->queue->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored );
PlaylistModel* queueModel = new PlaylistModel( this );
queueModel->setStyle( PlaylistModel::Short );
ui->queue->proxyModel()->setStyle( PlayableProxyModel::Short );
queueModel->finishLoading();
ui->queue->setPlaylistModel( queueModel );
queueModel->setReadOnly( false );

View File

@ -153,13 +153,13 @@ TrackView::setPlayableModel( PlayableModel* model )
connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) );
setAcceptDrops( true );
m_header->setDefaultColumnWeights( model->columnWeights() );
m_header->setDefaultColumnWeights( m_proxyModel->columnWeights() );
switch( model->style() )
switch( m_proxyModel->style() )
{
case PlayableModel::Short:
case PlayableModel::ShortWithAvatars:
case PlayableModel::Large:
case PlayableProxyModel::Short:
case PlayableProxyModel::ShortWithAvatars:
case PlayableProxyModel::Large:
setHeaderHidden( true );
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
break;
@ -184,7 +184,7 @@ TrackView::setEmptyTip( const QString& tip )
void
TrackView::onViewChanged()
{
if ( m_model->style() != PlayableModel::Short && m_model->style() != PlayableModel::Large ) // eventual FIXME?
if ( m_proxyModel->style() != PlayableProxyModel::Short && m_proxyModel->style() != PlayableProxyModel::Large ) // eventual FIXME?
return;
if ( m_timer.isActive() )
@ -217,7 +217,7 @@ TrackView::onScrollTimeout()
for ( int i = left.row(); i <= max; i++ )
{
m_model->updateDetailedInfo( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) );
m_proxyModel->updateDetailedInfo( m_proxyModel->index( i, 0 ) );
}
}
@ -621,7 +621,7 @@ TrackView::updateHoverIndex( const QPoint& pos )
repaint();
}
if ( !m_model || m_model->style() != PlayableModel::Detailed )
if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Detailed )
return;
if ( idx.column() == PlayableModel::Artist || idx.column() == PlayableModel::Album || idx.column() == PlayableModel::Track )
@ -673,7 +673,7 @@ TrackView::mousePressEvent( QMouseEvent* event )
{
QTreeView::mousePressEvent( event );
if ( !m_model || m_model->style() != PlayableModel::Detailed )
if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Detailed )
return;
QModelIndex idx = indexAt( event->pos() );

View File

@ -41,7 +41,6 @@ TreeModel::TreeModel( QObject* parent )
: PlayableModel( parent )
, m_mode( DatabaseMode )
{
setStyle( Collection );
setIcon( QPixmap( RESPATH "images/music-icon.png" ) );
connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( onPlaybackStarted( Tomahawk::result_ptr ) ), Qt::DirectConnection );
@ -172,7 +171,7 @@ TreeModel::fetchAlbums( const artist_ptr& artist )
connect( artist.data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ),
SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, Tomahawk::ModelMode ) ), Qt::UniqueConnection );
const QModelIndex parent = indexFromArtist( artist );
addAlbums( parent, artist->albums( m_mode, m_collection ) );
}

View File

@ -145,8 +145,8 @@ TreeView::setTreeModel( TreeModel* model )
guid(); // this will set the guid on the header
m_header->setDefaultColumnWeights( model->columnWeights() );
if ( model->style() == PlayableModel::Large )
m_header->setDefaultColumnWeights( m_proxyModel->columnWeights() );
if ( m_proxyModel->style() == PlayableProxyModel::Large )
{
setHeaderHidden( true );
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
@ -158,7 +158,7 @@ TreeView::setTreeModel( TreeModel* model )
}
emit modelChanged();
/* setColumnHidden( PlayableModel::Score, true ); // Hide score column per default
setColumnHidden( PlayableModel::Origin, true ); // Hide origin column per default
setColumnHidden( PlayableModel::Composer, true ); //Hide composer column per default
@ -439,7 +439,7 @@ TreeView::updateHoverIndex( const QPoint& pos )
repaint();
}
if ( !m_model || m_model->style() != PlayableModel::Collection )
if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Collection )
return;
PlayableItem* item = proxyModel()->itemFromIndex( proxyModel()->mapToSource( idx ) );
@ -492,7 +492,7 @@ TreeView::mousePressEvent( QMouseEvent* event )
{
QTreeView::mousePressEvent( event );
if ( !m_model || m_model->style() != PlayableModel::Collection )
if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Collection )
return;
QModelIndex idx = indexAt( event->pos() );

View File

@ -69,7 +69,7 @@ SocialPlaylistWidget::SocialPlaylistWidget ( QWidget* parent )
m_topForeignTracksModel = new PlaylistModel( ui->newTracksView );
ui->newTracksView->setPlaylistModel( m_topForeignTracksModel );
m_topForeignTracksModel->setStyle( PlayableModel::Short );
ui->newTracksView->proxyModel()->setStyle( PlayableProxyModel::Short );
ui->newTracksView->overlay()->setEnabled( false );
m_popularNewAlbumsModel = new PlayableModel( ui->newAlbumsView );

View File

@ -69,7 +69,7 @@ WelcomeWidget::WelcomeWidget( QWidget* parent )
updatePlaylists();
m_tracksModel = new RecentlyPlayedModel( ui->tracksView );
m_tracksModel->setStyle( PlayableModel::ShortWithAvatars );
ui->tracksView->proxyModel()->setStyle( PlayableProxyModel::ShortWithAvatars );
ui->tracksView->overlay()->setEnabled( false );
ui->tracksView->setPlaylistModel( m_tracksModel );
m_tracksModel->setSource( source_ptr() );

View File

@ -262,7 +262,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
TreeModel* artistsModel = new TreeModel( ui->artistsViewLeft );
artistsModel->setMode( InfoSystemMode );
artistsModel->setStyle( PlayableModel::Collection );
artistsModel->startLoading();
m_artistModels[ chartId ] = artistsModel;
@ -293,7 +292,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
connect( loader, SIGNAL( tracks( Tomahawk::ChartDataLoader*, QList< Tomahawk::query_ptr > ) ), this, SLOT( chartTracksLoaded( Tomahawk::ChartDataLoader*, QList< Tomahawk::query_ptr > ) ) );
PlaylistModel* trackModel = new PlaylistModel( ui->tracksViewLeft );
trackModel->setStyle( PlayableModel::Large );
trackModel->startLoading();
m_trackModels[ chartId ] = trackModel;
@ -463,6 +461,7 @@ WhatsHotWidget::setLeftViewAlbums( PlayableModel* model )
void
WhatsHotWidget::setLeftViewArtists( TreeModel* model )
{
ui->artistsViewLeft->proxyModel()->setStyle( PlayableProxyModel::Collection );
ui->artistsViewLeft->setTreeModel( model );
ui->artistsViewLeft->proxyModel()->sort( -1 ); // disable sorting, must be called after artistsViewLeft->setTreeModel
ui->stackLeft->setCurrentIndex( 1 );
@ -472,6 +471,7 @@ WhatsHotWidget::setLeftViewArtists( TreeModel* model )
void
WhatsHotWidget::setLeftViewTracks( PlaylistModel* model )
{
ui->tracksViewLeft->proxyModel()->setStyle( PlayableProxyModel::Large );
ui->tracksViewLeft->setPlaylistModel( model );
ui->tracksViewLeft->proxyModel()->sort( -1 );
ui->stackLeft->setCurrentIndex( 0 );

View File

@ -25,6 +25,7 @@
#include <QScrollBar>
#include "audio/AudioEngine.h"
#include "playlist/GridItemDelegate.h"
#include "playlist/PlayableModel.h"
#include "playlist/TreeModel.h"
#include "playlist/PlaylistModel.h"
@ -73,7 +74,7 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
ui->topHits->setEmptyTip( tr( "Sorry, we could not find any related artists!" ) );
m_topHitsModel = new PlaylistModel( ui->topHits );
m_topHitsModel->setStyle( PlayableModel::Short );
ui->topHits->proxyModel()->setStyle( PlayableProxyModel::Short );
ui->topHits->setPlayableModel( m_topHitsModel );
ui->topHits->setSortingEnabled( false );
ui->topHits->setEmptyTip( tr( "Sorry, we could not find any top hits for this artist!" ) );
@ -82,13 +83,13 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
ui->relatedArtists->setWrapping( false );
ui->relatedArtists->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
ui->relatedArtists->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
m_relatedModel->setItemSize( QSize( 170, 170 ) );
ui->relatedArtists->delegate()->setItemSize( QSize( 170, 170 ) );
ui->albums->setAutoFitItems( false );
ui->albums->setWrapping( false );
ui->albums->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
ui->albums->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
m_albumsModel->setItemSize( QSize( 170, 170 ) );
ui->albums->delegate()->setItemSize( QSize( 170, 170 ) );
ui->albums->proxyModel()->setHideDupeItems( true );
ui->topHits->setFrameShape( QFrame::StyledPanel );

View File

@ -50,13 +50,13 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget*
ui->splitter->setStretchFactor( 1, 1 );
m_recentTracksModel = new RecentlyAddedModel( ui->recentCollectionView );
m_recentTracksModel->setStyle( PlayableModel::Short );
ui->recentCollectionView->proxyModel()->setStyle( PlayableProxyModel::Short );
ui->recentCollectionView->setPlayableModel( m_recentTracksModel );
ui->recentCollectionView->sortByColumn( PlayableModel::Age, Qt::DescendingOrder );
m_recentTracksModel->setSource( source );
m_historyModel = new RecentlyPlayedModel( ui->historyView );
m_historyModel->setStyle( PlayableModel::Short );
ui->historyView->proxyModel()->setStyle( PlayableProxyModel::Short );
ui->historyView->setPlaylistModel( m_historyModel );
m_historyModel->setSource( source );

View File

@ -513,7 +513,7 @@ SourceItem::latestAdditionsClicked()
cv->setAttribute( Qt::WA_MacShowFocusRect, 0 );
RecentlyAddedModel* raModel = new RecentlyAddedModel( cv );
raModel->setStyle( PlayableModel::Large );
cv->proxyModel()->setStyle( PlayableProxyModel::Large );
raModel->setTitle( tr( "Latest Additions" ) );
if ( m_source->isLocal() )
@ -556,7 +556,7 @@ SourceItem::recentPlaysClicked()
pv->setAttribute( Qt::WA_MacShowFocusRect, 0 );
RecentlyPlayedModel* raModel = new RecentlyPlayedModel( pv );
raModel->setStyle( PlayableModel::Large );
pv->proxyModel()->setStyle( PlayableProxyModel::Large );
raModel->setTitle( tr( "Recently Played Tracks" ) );
if ( m_source->isLocal() )