mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-24 09:49:42 +01:00
* Move TreeModel filtering to TreeProxyModel.
This commit is contained in:
parent
71117d3c42
commit
9ef5894685
src/libtomahawk
@ -82,7 +82,6 @@ DatabaseCommand_AllArtists::exec( DatabaseImpl* dbi )
|
||||
al << artist;
|
||||
}
|
||||
|
||||
if ( al.count() )
|
||||
emit artists( al );
|
||||
emit artists( al );
|
||||
emit done();
|
||||
}
|
||||
|
@ -528,7 +528,6 @@ TreeModel::addAllCollections()
|
||||
|
||||
emit loadingStarted();
|
||||
DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists();
|
||||
cmd->setFilter( m_filter );
|
||||
|
||||
connect( cmd, SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
|
||||
SLOT( onArtistsAdded( QList<Tomahawk::artist_ptr> ) ) );
|
||||
@ -579,7 +578,6 @@ TreeModel::addTracks( const album_ptr& album, const QModelIndex& parent )
|
||||
emit loadingStarted();
|
||||
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection );
|
||||
cmd->setAlbum( album.data() );
|
||||
// cmd->setArtist( album->artist().data() );
|
||||
|
||||
QList< QVariant > rows;
|
||||
rows << parent.row();
|
||||
@ -602,7 +600,6 @@ TreeModel::addCollection( const collection_ptr& collection )
|
||||
|
||||
m_collection = collection;
|
||||
DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( collection );
|
||||
cmd->setFilter( m_filter );
|
||||
|
||||
connect( cmd, SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
|
||||
SLOT( onArtistsAdded( QList<Tomahawk::artist_ptr> ) ) );
|
||||
@ -644,6 +641,7 @@ TreeModel::addFilteredCollection( const collection_ptr& collection, unsigned int
|
||||
void
|
||||
TreeModel::onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists )
|
||||
{
|
||||
emit loadingFinished();
|
||||
if ( !artists.count() )
|
||||
return;
|
||||
|
||||
@ -663,7 +661,6 @@ TreeModel::onArtistsAdded( const QList<Tomahawk::artist_ptr>& artists )
|
||||
}
|
||||
|
||||
emit endInsertRows();
|
||||
emit loadingFinished();
|
||||
}
|
||||
|
||||
|
||||
@ -785,19 +782,6 @@ TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QV
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeModel::setFilter( const QString& pattern )
|
||||
{
|
||||
m_filter = pattern;
|
||||
clear();
|
||||
|
||||
if ( !m_collection.isNull() )
|
||||
addCollection( m_collection );
|
||||
else
|
||||
addAllCollections();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeModel::infoSystemFinished( QString target )
|
||||
{
|
||||
|
@ -81,6 +81,8 @@ public:
|
||||
|
||||
virtual QPersistentModelIndex currentItem() { return m_currentIndex; }
|
||||
|
||||
Tomahawk::collection_ptr collection() const { return m_collection; }
|
||||
|
||||
void addAllCollections();
|
||||
void addCollection( const Tomahawk::collection_ptr& collection );
|
||||
void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order );
|
||||
@ -99,9 +101,6 @@ public:
|
||||
virtual void setTitle( const QString& title ) { m_title = title; }
|
||||
virtual void setDescription( const QString& description ) { m_description = description; }
|
||||
|
||||
virtual QString filter() const { return m_filter; }
|
||||
virtual void setFilter( const QString& pattern );
|
||||
|
||||
TreeModelItem* itemFromIndex( const QModelIndex& index ) const
|
||||
{
|
||||
if ( index.isValid() )
|
||||
@ -154,9 +153,10 @@ private:
|
||||
QString m_description;
|
||||
ColumnStyle m_columnStyle;
|
||||
|
||||
QList<Tomahawk::artist_ptr> m_artistsFilter;
|
||||
|
||||
Tomahawk::collection_ptr m_collection;
|
||||
QHash<qlonglong, QPersistentModelIndex> m_coverHash;
|
||||
QString m_filter;
|
||||
};
|
||||
|
||||
#endif // ALBUMMODEL_H
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <QListView>
|
||||
|
||||
#include "query.h"
|
||||
#include "database/database.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
|
||||
@ -63,11 +64,27 @@ TreeProxyModel::setSourceTreeModel( TreeModel* sourceModel )
|
||||
void
|
||||
TreeProxyModel::setFilter( const QString& pattern )
|
||||
{
|
||||
PlaylistInterface::setFilter( pattern );
|
||||
setFilterRegExp( pattern );
|
||||
m_model->setFilter( pattern );
|
||||
m_filter = pattern;
|
||||
|
||||
emit filterChanged( pattern );
|
||||
DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( m_model->collection() );
|
||||
cmd->setFilter( pattern );
|
||||
|
||||
connect( cmd, SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
|
||||
SLOT( onFilterArtists( QList<Tomahawk::artist_ptr> ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeProxyModel::onFilterArtists( const QList<Tomahawk::artist_ptr>& artists )
|
||||
{
|
||||
m_artistsFilter = artists;
|
||||
|
||||
PlaylistInterface::setFilter( m_filter );
|
||||
setFilterRegExp( m_filter );
|
||||
|
||||
emit filterChanged( m_filter );
|
||||
emit trackCountChanged( trackCount() );
|
||||
}
|
||||
|
||||
@ -112,6 +129,10 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent
|
||||
m_cache.insertMulti( sourceParent, pi->result() );
|
||||
}
|
||||
|
||||
if ( !filterRegExp().isEmpty() && !pi->artist().isNull() )
|
||||
{
|
||||
return m_artistsFilter.contains( pi->artist() );
|
||||
}
|
||||
return true;
|
||||
|
||||
QStringList sl = filterRegExp().pattern().split( " ", QString::SkipEmptyParts );
|
||||
|
@ -82,11 +82,17 @@ protected:
|
||||
bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
|
||||
bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
|
||||
|
||||
private slots:
|
||||
void onFilterArtists( const QList<Tomahawk::artist_ptr>& artists );
|
||||
|
||||
private:
|
||||
QString textForItem( TreeModelItem* item ) const;
|
||||
|
||||
mutable QMap< QPersistentModelIndex, Tomahawk::result_ptr > m_cache;
|
||||
|
||||
QList<Tomahawk::artist_ptr> m_artistsFilter;
|
||||
QString m_filter;
|
||||
|
||||
TreeModel* m_model;
|
||||
RepeatMode m_repeatMode;
|
||||
bool m_shuffled;
|
||||
|
Loading…
x
Reference in New Issue
Block a user