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