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

* TreeProxyModel now inherits from PlayableProxyModel.

This commit is contained in:
Christian Muehlhaeuser 2012-06-01 00:32:15 +02:00
parent 0f6f58373e
commit 644f6a714a
2 changed files with 17 additions and 83 deletions

View File

@ -32,52 +32,30 @@
TreeProxyModel::TreeProxyModel( QObject* parent )
: QSortFilterProxyModel( parent )
: PlayableProxyModel( parent )
, m_artistsFilterCmd( 0 )
, m_model( 0 )
{
setFilterCaseSensitivity( Qt::CaseInsensitive );
setSortCaseSensitivity( Qt::CaseInsensitive );
setDynamicSortFilter( true );
setSourceTreeModel( 0 );
}
QPersistentModelIndex
TreeProxyModel::currentIndex() const
{
if ( !m_model )
return QPersistentModelIndex();
return mapFromSource( m_model->currentItem() );
}
void
TreeProxyModel::setSourceModel( QAbstractItemModel* sourceModel )
TreeProxyModel::setSourcePlayableModel( TreeModel* model )
{
Q_UNUSED( sourceModel );
qDebug() << "Explicitly use setSourceTreeModel instead";
Q_ASSERT( false );
}
void
TreeProxyModel::setSourceTreeModel( TreeModel* sourceModel )
{
m_model = sourceModel;
if ( m_model )
if ( sourceModel() )
{
if ( m_model->metaObject()->indexOfSignal( "trackCountChanged(uint)" ) > -1 )
connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ), SIGNAL( sourceTrackCountChanged( unsigned int ) ) );
disconnect( m_model, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( onRowsInserted( QModelIndex, int, int ) ) );
disconnect( m_model, SIGNAL( modelReset() ), this, SLOT( onModelReset() ) );
}
PlayableProxyModel::setSourcePlayableModel( model );
m_model = model;
if ( sourceModel() )
{
connect( m_model, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onRowsInserted( QModelIndex, int, int ) ) );
connect( m_model, SIGNAL( modelReset() ), SLOT( onModelReset() ) );
}
QSortFilterProxyModel::setSourceModel( sourceModel );
}
@ -114,7 +92,7 @@ TreeProxyModel::onModelReset()
void
TreeProxyModel::newFilterFromPlaylistInterface( const QString &pattern )
TreeProxyModel::newFilterFromPlaylistInterface( const QString& pattern )
{
emit filteringStarted();
@ -339,33 +317,6 @@ TreeProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) co
}
void
TreeProxyModel::removeIndex( const QModelIndex& index )
{
qDebug() << Q_FUNC_INFO;
if ( !sourceModel() )
return;
if ( index.column() > 0 )
return;
sourceModel()->removeIndex( mapToSource( index ) );
}
void
TreeProxyModel::removeIndexes( const QList<QModelIndex>& indexes )
{
if ( !sourceModel() )
return;
foreach( const QModelIndex& idx, indexes )
{
removeIndex( idx );
}
}
QString
TreeProxyModel::textForItem( PlayableItem* item ) const
{

View File

@ -20,10 +20,9 @@
#ifndef TREEPROXYMODEL_H
#define TREEPROXYMODEL_H
#include <QSortFilterProxyModel>
#include "PlaylistInterface.h"
#include "TreeModel.h"
#include "PlayableProxyModel.h"
#include "DllMacro.h"
@ -34,7 +33,7 @@ namespace Tomahawk
class TreeProxyModelPlaylistInterface;
}
class DLLEXPORT TreeProxyModel : public QSortFilterProxyModel
class DLLEXPORT TreeProxyModel : public PlayableProxyModel
{
Q_OBJECT
@ -42,28 +41,13 @@ public:
explicit TreeProxyModel( QObject* parent = 0 );
virtual ~TreeProxyModel() {}
virtual TreeModel* sourceModel() const { return m_model; }
virtual void setSourceTreeModel( TreeModel* sourceModel );
virtual void setSourceModel( QAbstractItemModel* sourceModel );
virtual void setSourcePlayableModel( TreeModel* model );
virtual QPersistentModelIndex currentIndex() const;
virtual void setCurrentIndex( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); }
virtual void newFilterFromPlaylistInterface( const QString &pattern );
virtual void removeIndex( const QModelIndex& index );
virtual void removeIndexes( const QList<QModelIndex>& indexes );
virtual int albumCount() const { return rowCount( QModelIndex() ); }
virtual PlayableItem* itemFromIndex( const QModelIndex& index ) const { return sourceModel()->itemFromIndex( index ); }
virtual void newFilterFromPlaylistInterface( const QString& pattern );
virtual Tomahawk::playlistinterface_ptr playlistInterface();
signals:
void filterChanged( const QString& filter );
void filteringStarted();
void filteringFinished();
protected:
bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
@ -87,8 +71,7 @@ private:
QList<int> m_albumsFilter;
DatabaseCommand_AllArtists* m_artistsFilterCmd;
QString m_filter;
QString m_filter;
TreeModel* m_model;
Tomahawk::playlistinterface_ptr m_playlistInterface;