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

Rejig the parameters and add QASSERTs. Chris, I decided to take your advice about the asserts -- it will help in the future to make sure people don't mistakenly use the wrong function in new code either.

This commit is contained in:
Jeff Mitchell
2011-04-12 15:21:05 -04:00
parent 4a6bc942fa
commit e2a3c48e6e
14 changed files with 74 additions and 42 deletions

View File

@@ -41,15 +41,18 @@ AlbumProxyModel::AlbumProxyModel( QObject* parent )
setSourceModel( 0 ); setSourceModel( 0 );
} }
void void
AlbumProxyModel::setSourceModel( QAbstractItemModel* sourceModel ) AlbumProxyModel::setSourceModel( QAbstractItemModel* sourceModel )
{ {
AlbumModel* amodel = static_cast< AlbumModel* >( sourceModel ); Q_UNUSED( sourceModel );
if( !amodel ) qDebug() << "Explicitly use setSourceAlbumModel instead";
return; Q_ASSERT( false );
else }
m_model = amodel;
void
AlbumProxyModel::setSourceAlbumModel( AlbumModel* sourceModel )
{
m_model = sourceModel;
connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ), connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ),
SIGNAL( sourceTrackCountChanged( unsigned int ) ) ); SIGNAL( sourceTrackCountChanged( unsigned int ) ) );

View File

@@ -34,6 +34,7 @@ public:
explicit AlbumProxyModel( QObject* parent = 0 ); explicit AlbumProxyModel( QObject* parent = 0 );
virtual AlbumModel* sourceModel() const { return m_model; } virtual AlbumModel* sourceModel() const { return m_model; }
virtual void setSourceAlbumModel( AlbumModel* sourceModel );
virtual void setSourceModel( QAbstractItemModel* sourceModel ); virtual void setSourceModel( QAbstractItemModel* sourceModel );
virtual QList<Tomahawk::query_ptr> tracks() { Q_ASSERT( FALSE ); QList<Tomahawk::query_ptr> queries; return queries; } virtual QList<Tomahawk::query_ptr> tracks() { Q_ASSERT( FALSE ); QList<Tomahawk::query_ptr> queries; return queries; }

View File

@@ -74,16 +74,20 @@ AlbumView::setProxyModel( AlbumProxyModel* model )
void void
AlbumView::setModel( QAbstractItemModel* model ) AlbumView::setModel( QAbstractItemModel* model )
{ {
AlbumModel *amodel = static_cast< AlbumModel* >( model ); Q_UNUSED( model );
qDebug() << "Explicitly use setAlbumModel instead";
Q_ASSERT( false );
}
if ( !amodel )
return; void
else AlbumView::setAlbumModel( AlbumModel* model )
m_model = amodel; {
m_model = model;
if ( m_proxyModel ) if ( m_proxyModel )
{ {
m_proxyModel->setSourceModel( model ); m_proxyModel->setSourceModel( m_model );
m_proxyModel->sort( 0 ); m_proxyModel->sort( 0 );
} }
@@ -147,6 +151,7 @@ AlbumView::onFilterChanged( const QString& )
void void
AlbumView::startDrag( Qt::DropActions supportedActions ) AlbumView::startDrag( Qt::DropActions supportedActions )
{ {
Q_UNUSED( supportedActions );
} }
@@ -154,5 +159,6 @@ AlbumView::startDrag( Qt::DropActions supportedActions )
QPixmap QPixmap
AlbumView::createDragPixmap( int itemCount ) const AlbumView::createDragPixmap( int itemCount ) const
{ {
Q_UNUSED( itemCount );
return QPixmap(); return QPixmap();
} }

View File

@@ -42,6 +42,7 @@ public:
AlbumProxyModel* proxyModel() const { return m_proxyModel; } AlbumProxyModel* proxyModel() const { return m_proxyModel; }
// PlaylistItemDelegate* delegate() { return m_delegate; } // PlaylistItemDelegate* delegate() { return m_delegate; }
void setAlbumModel( AlbumModel* model );
void setModel( QAbstractItemModel* model ); void setModel( QAbstractItemModel* model );
virtual QWidget* widget() { return this; } virtual QWidget* widget() { return this; }

View File

@@ -53,14 +53,18 @@ CollectionView::~CollectionView()
void void
CollectionView::setModel( QAbstractItemModel* model ) CollectionView::setModel( QAbstractItemModel* model )
{ {
TrackModel *tmodel = static_cast< TrackModel* >( model ); qDebug() << "Explicitly use setTrackModel instead";
if ( !tmodel ) Q_ASSERT( false );
return; }
TrackView::setModel( tmodel );
void
CollectionView::setTrackModel( TrackModel* model )
{
TrackView::setModel( model );
setGuid( "collectionview" ); setGuid( "collectionview" );
connect( tmodel, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) ); connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
} }

View File

@@ -36,6 +36,7 @@ public:
explicit CollectionView( QWidget* parent = 0 ); explicit CollectionView( QWidget* parent = 0 );
~CollectionView(); ~CollectionView();
virtual void setTrackModel( TrackModel* model );
virtual void setModel( QAbstractItemModel* model ); virtual void setModel( QAbstractItemModel* model );
virtual QWidget* widget() { return this; } virtual QWidget* widget() { return this; }

View File

@@ -71,13 +71,13 @@ DynamicView::~DynamicView()
} }
void void
DynamicView::setModel( DynamicModel* model) DynamicView::setDynamicModel( DynamicModel* model)
{ {
m_model = model; m_model = model;
PlaylistView::setModel( model ); PlaylistView::setModel( m_model );
connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) ); connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
connect( model, SIGNAL( checkForOverflow() ), this, SLOT( checkForOverflow() ) ); connect( m_model, SIGNAL( checkForOverflow() ), this, SLOT( checkForOverflow() ) );
} }
void void

View File

@@ -40,7 +40,7 @@ public:
explicit DynamicView( QWidget* parent = 0 ); explicit DynamicView( QWidget* parent = 0 );
virtual ~DynamicView(); virtual ~DynamicView();
virtual void setModel( DynamicModel* model ); virtual void setDynamicModel( DynamicModel* model );
void setOnDemand( bool onDemand ); void setOnDemand( bool onDemand );
void setReadOnly( bool readOnly ); void setReadOnly( bool readOnly );

View File

@@ -47,14 +47,18 @@ PlaylistView::~PlaylistView()
void void
PlaylistView::setModel( QAbstractItemModel* model ) PlaylistView::setModel( QAbstractItemModel* model )
{ {
PlaylistModel* pmodel = static_cast< PlaylistModel* >( model ); Q_UNUSED( model );
qDebug() << "Explicitly use setPlaylistModel instead";
Q_ASSERT( false );
}
if ( !pmodel )
return;
else
m_model = pmodel;
TrackView::setModel( model ); void
PlaylistView::setPlaylistModel( PlaylistModel* model )
{
m_model = model;
TrackView::setModel( m_model );
setColumnHidden( 5, true ); // Hide age column per default setColumnHidden( 5, true ); // Hide age column per default
if ( !m_model->playlist().isNull() ) if ( !m_model->playlist().isNull() )

View File

@@ -39,6 +39,7 @@ public:
~PlaylistView(); ~PlaylistView();
PlaylistModel* playlistModel() const { return m_model; } PlaylistModel* playlistModel() const { return m_model; }
virtual void setPlaylistModel( PlaylistModel* model );
virtual void setModel( QAbstractItemModel* model ); virtual void setModel( QAbstractItemModel* model );
virtual QWidget* widget() { return this; } virtual QWidget* widget() { return this; }

View File

@@ -45,19 +45,23 @@ TrackProxyModel::TrackProxyModel( QObject* parent )
void void
TrackProxyModel::setSourceModel( QAbstractItemModel* sourceModel ) TrackProxyModel::setSourceModel( QAbstractItemModel* model )
{ {
TrackModel* tmodel = static_cast< TrackModel* >( sourceModel ); Q_UNUSED( model );
qDebug() << "Explicitly use setSourceTrackModel instead";
Q_ASSERT( false );
}
if ( !tmodel )
return; void
else TrackProxyModel::setSourceTrackModel( TrackModel* sourceModel )
m_model = tmodel; {
m_model = sourceModel;
connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ), connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ),
SIGNAL( sourceTrackCountChanged( unsigned int ) ) ); SIGNAL( sourceTrackCountChanged( unsigned int ) ) );
QSortFilterProxyModel::setSourceModel( sourceModel ); QSortFilterProxyModel::setSourceModel( m_model );
} }

View File

@@ -34,7 +34,8 @@ public:
explicit TrackProxyModel ( QObject* parent = 0 ); explicit TrackProxyModel ( QObject* parent = 0 );
virtual TrackModel* sourceModel() const { return m_model; } virtual TrackModel* sourceModel() const { return m_model; }
virtual void setSourceModel( QAbstractItemModel* sourceModel ); virtual void setSourceTrackModel( TrackModel* sourceModel );
virtual void setSourceModel( QAbstractItemModel* model );
virtual QPersistentModelIndex currentItem() const { return mapFromSource( m_model->currentItem() ); } virtual QPersistentModelIndex currentItem() const { return mapFromSource( m_model->currentItem() ); }
virtual void setCurrentItem( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); } virtual void setCurrentItem( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); }

View File

@@ -33,6 +33,7 @@
#include "queueview.h" #include "queueview.h"
#include "trackmodel.h" #include "trackmodel.h"
#include "trackproxymodel.h" #include "trackproxymodel.h"
#include <track.h>
using namespace Tomahawk; using namespace Tomahawk;
@@ -109,16 +110,20 @@ TrackView::setProxyModel( TrackProxyModel* model )
void void
TrackView::setModel( QAbstractItemModel* model ) TrackView::setModel( QAbstractItemModel* model )
{ {
TrackModel* tmodel = static_cast< TrackModel* >( model ); Q_UNUSED( model );
qDebug() << "Explicitly use setTrackModel instead";
Q_ASSERT( false );
}
if ( !tmodel )
return; void
else TrackView::setTrackModel( TrackModel* model )
m_model = tmodel; {
m_model = model;
if ( m_proxyModel ) if ( m_proxyModel )
{ {
m_proxyModel->setSourceModel( model ); m_proxyModel->setSourceModel( m_model );
} }
connect( m_model, SIGNAL( itemSizeChanged( QModelIndex ) ), SLOT( onItemResized( QModelIndex ) ) ); connect( m_model, SIGNAL( itemSizeChanged( QModelIndex ) ), SLOT( onItemResized( QModelIndex ) ) );

View File

@@ -44,6 +44,7 @@ public:
virtual QString guid() const { return m_guid; } virtual QString guid() const { return m_guid; }
virtual void setGuid( const QString& guid ); virtual void setGuid( const QString& guid );
virtual void setTrackModel( TrackModel* model );
virtual void setModel( QAbstractItemModel* model ); virtual void setModel( QAbstractItemModel* model );
void setProxyModel( TrackProxyModel* model ); void setProxyModel( TrackProxyModel* model );