1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-08 23:26:40 +02: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 ) TreeProxyModel::TreeProxyModel( QObject* parent )
: QSortFilterProxyModel( parent ) : PlayableProxyModel( parent )
, m_artistsFilterCmd( 0 ) , m_artistsFilterCmd( 0 )
, m_model( 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 void
TreeProxyModel::setSourceModel( QAbstractItemModel* sourceModel ) TreeProxyModel::setSourcePlayableModel( TreeModel* model )
{ {
Q_UNUSED( sourceModel ); if ( sourceModel() )
qDebug() << "Explicitly use setSourceTreeModel instead"; {
Q_ASSERT( false ); 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;
void if ( sourceModel() )
TreeProxyModel::setSourceTreeModel( TreeModel* sourceModel )
{ {
m_model = sourceModel;
if ( m_model )
{
if ( m_model->metaObject()->indexOfSignal( "trackCountChanged(uint)" ) > -1 )
connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ), SIGNAL( sourceTrackCountChanged( unsigned int ) ) );
connect( m_model, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onRowsInserted( QModelIndex, int, int ) ) ); connect( m_model, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onRowsInserted( QModelIndex, int, int ) ) );
connect( m_model, SIGNAL( modelReset() ), SLOT( onModelReset() ) ); connect( m_model, SIGNAL( modelReset() ), SLOT( onModelReset() ) );
} }
QSortFilterProxyModel::setSourceModel( sourceModel );
} }
@@ -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 QString
TreeProxyModel::textForItem( PlayableItem* item ) const TreeProxyModel::textForItem( PlayableItem* item ) const
{ {

View File

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