diff --git a/src/libtomahawk/playlist/treemodel.cpp b/src/libtomahawk/playlist/treemodel.cpp index 067013e0b..7e48523f5 100644 --- a/src/libtomahawk/playlist/treemodel.cpp +++ b/src/libtomahawk/playlist/treemodel.cpp @@ -589,10 +589,9 @@ TreeModel::onTracksAdded( const QList& tracks, const QVaria if ( crows.second > 0 ) emit endInsertRows(); - else - emit dataChanged( item->index, item->index.sibling( item->index.row(), columnCount( QModelIndex() ) - 1 ) ); - qDebug() << rowCount( parent ); + emit dataChanged( item->index.sibling( 0, 0 ), item->index.sibling( item->index.row(), columnCount( QModelIndex() ) - 1 ) ); + emit loadingFinished(); } diff --git a/src/libtomahawk/playlist/treeproxymodel.cpp b/src/libtomahawk/playlist/treeproxymodel.cpp index 8b8327045..0547bdc85 100644 --- a/src/libtomahawk/playlist/treeproxymodel.cpp +++ b/src/libtomahawk/playlist/treeproxymodel.cpp @@ -75,15 +75,42 @@ TreeProxyModel::setFilter( const QString& pattern ) bool TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const { + TreeModelItem* pi = sourceModel()->itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) ); + Q_ASSERT( pi ); + + if ( !pi->result().isNull() ) + { + QList< Tomahawk::result_ptr > rl = m_cache.values( sourceParent ); + foreach ( const Tomahawk::result_ptr& result, rl ) + { + if ( result->track() == pi->result()->track() ) + return ( result.data() == pi->result().data() ); + } + + for ( int i = 0; i < sourceModel()->rowCount( sourceParent ); i++ ) + { + if ( i == sourceRow ) + continue; + + TreeModelItem* ti = sourceModel()->itemFromIndex( sourceModel()->index( i, 0, sourceParent ) ); + if ( ti->result()->track() == pi->result()->track() ) + { + if ( !pi->result()->isOnline() && ti->result()->isOnline() ) + return false; + + if ( ti->result()->collection()->source()->isLocal() ) + return false; + } + } + + tDebug() << "Accepting:" << pi->result()->toString() << pi->result()->collection()->source()->id(); + m_cache.insertMulti( sourceParent, pi->result() ); + } + if ( filterRegExp().isEmpty() ) return true; - TreeModelItem* pi = sourceModel()->itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) ); - if ( !pi ) - return false; - QStringList sl = filterRegExp().pattern().split( " ", QString::SkipEmptyParts ); - bool found = true; foreach( const QString& s, sl ) { diff --git a/src/libtomahawk/playlist/treeproxymodel.h b/src/libtomahawk/playlist/treeproxymodel.h index 68deab1be..1600699ec 100644 --- a/src/libtomahawk/playlist/treeproxymodel.h +++ b/src/libtomahawk/playlist/treeproxymodel.h @@ -84,6 +84,8 @@ protected: private: QString textForItem( TreeModelItem* item ) const; + mutable QMap< QPersistentModelIndex, Tomahawk::result_ptr > m_cache; + TreeModel* m_model; RepeatMode m_repeatMode; bool m_shuffled;