When getting children of global search results for adding to the playlist, get them through the proxy model to maintain their order.

This commit is contained in:
David Sansome 2012-06-24 21:08:33 +01:00
parent 1c338455c3
commit 3ec22e3cc6
3 changed files with 17 additions and 2 deletions

View File

@ -19,9 +19,12 @@
#include "globalsearchmodel.h"
#include "core/mimedata.h"
#include <QSortFilterProxyModel>
GlobalSearchModel::GlobalSearchModel(GlobalSearch* engine, QObject* parent)
: QStandardItemModel(parent),
engine_(engine),
proxy_(NULL),
use_pretty_covers_(true),
artist_icon_(":/icons/22x22/x-clementine-artist.png"),
album_icon_(":/icons/22x22/x-clementine-album.png")
@ -202,9 +205,14 @@ void GlobalSearchModel::GetChildResults(const QStandardItem* item,
// Does this item have children?
if (item->rowCount()) {
// Yes - visit all the children
const QModelIndex parent_proxy_index = proxy_->mapFromSource(item->index());
// Yes - visit all the children, but do so through the proxy so we get them
// in the right order.
for (int i=0 ; i<item->rowCount() ; ++i) {
GetChildResults(item->child(i), results, visited);
const QModelIndex proxy_index = parent_proxy_index.child(i, 0);
const QModelIndex index = proxy_->mapToSource(proxy_index);
GetChildResults(itemFromIndex(index), results, visited);
}
} else {
// No - it's a song, add its result

View File

@ -25,6 +25,8 @@
class GlobalSearch;
class QSortFilterProxyModel;
class GlobalSearchModel : public QStandardItemModel {
Q_OBJECT
@ -44,6 +46,7 @@ public:
QString group_[3];
};
void set_proxy(QSortFilterProxyModel* proxy) { proxy_ = proxy; }
void set_use_pretty_covers(bool pretty) { use_pretty_covers_ = pretty; }
void set_provider_order(const QStringList& provider_order) { provider_order_ = provider_order; }
void SetGroupBy(const LibraryModel::Grouping& grouping, bool regroup_now);
@ -68,6 +71,7 @@ private:
private:
GlobalSearch* engine_;
QSortFilterProxyModel* proxy_;
LibraryModel::Grouping group_by_;

View File

@ -63,6 +63,9 @@ GlobalSearchView::GlobalSearchView(Application* app, QWidget* parent)
{
ui_->setupUi(this);
front_model_->set_proxy(front_proxy_);
back_model_->set_proxy(back_proxy_);
ui_->search->installEventFilter(this);
ui_->results_stack->installEventFilter(this);