Don't let search results that arrive later appear before other search results - should make navigating the global search results less annoying when there are remote providers like spotify.
This commit is contained in:
parent
516190bfc2
commit
4282b6b68b
@ -31,23 +31,30 @@ bool GlobalSearchSortModel::lessThan(const QModelIndex& left, const QModelIndex&
|
|||||||
const SearchProvider::Result r2 = right.data(GlobalSearchWidget::Role_PrimaryResult)
|
const SearchProvider::Result r2 = right.data(GlobalSearchWidget::Role_PrimaryResult)
|
||||||
.value<SearchProvider::Result>();
|
.value<SearchProvider::Result>();
|
||||||
|
|
||||||
int ret = 0;
|
// Order results that arrived first first, so that the results don't jump
|
||||||
|
// around while the user is trying to navigate through them.
|
||||||
|
const int order_left = left.data(GlobalSearchWidget::Role_OrderArrived).toInt();
|
||||||
|
const int order_right = right.data(GlobalSearchWidget::Role_OrderArrived).toInt();
|
||||||
|
|
||||||
|
if (order_left < order_right) return true;
|
||||||
|
if (order_left > order_right) return false;
|
||||||
|
|
||||||
#define CompareInt(field) \
|
#define CompareInt(field) \
|
||||||
if (r1.field < r2.field) return true; \
|
if (r1.field < r2.field) return true; \
|
||||||
if (r1.field > r2.field) return false
|
if (r1.field > r2.field) return false
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
#define CompareString(field) \
|
#define CompareString(field) \
|
||||||
ret = QString::localeAwareCompare(r1.metadata_.field(), r2.metadata_.field()); \
|
ret = QString::localeAwareCompare(r1.metadata_.field(), r2.metadata_.field()); \
|
||||||
if (ret < 0) return true; \
|
if (ret < 0) return true; \
|
||||||
if (ret > 0) return false
|
if (ret > 0) return false
|
||||||
|
|
||||||
|
// If they arrived at the same time then sort by quality and type.
|
||||||
// Compare match quality and types first
|
|
||||||
CompareInt(match_quality_);
|
CompareInt(match_quality_);
|
||||||
CompareInt(type_);
|
CompareInt(type_);
|
||||||
|
|
||||||
// Then compare title, artist and album
|
// Failing that, compare title, artist and album
|
||||||
switch (r1.type_) {
|
switch (r1.type_) {
|
||||||
case SearchProvider::Result::Type_Track:
|
case SearchProvider::Result::Type_Track:
|
||||||
case SearchProvider::Result::Type_Stream:
|
case SearchProvider::Result::Type_Stream:
|
||||||
|
@ -48,6 +48,7 @@ GlobalSearchWidget::GlobalSearchWidget(QWidget* parent)
|
|||||||
engine_(NULL),
|
engine_(NULL),
|
||||||
last_id_(0),
|
last_id_(0),
|
||||||
clear_model_on_next_result_(false),
|
clear_model_on_next_result_(false),
|
||||||
|
order_arrived_counter_(0),
|
||||||
model_(new QStandardItemModel(this)),
|
model_(new QStandardItemModel(this)),
|
||||||
proxy_(new GlobalSearchSortModel(this)),
|
proxy_(new GlobalSearchSortModel(this)),
|
||||||
view_(new QListView),
|
view_(new QListView),
|
||||||
@ -192,6 +193,7 @@ void GlobalSearchWidget::TextEdited(const QString& text) {
|
|||||||
void GlobalSearchWidget::Reset() {
|
void GlobalSearchWidget::Reset() {
|
||||||
model_->clear();
|
model_->clear();
|
||||||
art_requests_.clear();
|
art_requests_.clear();
|
||||||
|
order_arrived_counter_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalSearchWidget::SearchFinished(int id) {
|
void GlobalSearchWidget::SearchFinished(int id) {
|
||||||
@ -200,7 +202,7 @@ void GlobalSearchWidget::SearchFinished(int id) {
|
|||||||
|
|
||||||
if (clear_model_on_next_result_) {
|
if (clear_model_on_next_result_) {
|
||||||
Reset();
|
Reset();
|
||||||
clear_model_on_next_result_ = true;
|
clear_model_on_next_result_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RepositionPopup();
|
RepositionPopup();
|
||||||
@ -219,6 +221,7 @@ void GlobalSearchWidget::AddResults(int id, const SearchProvider::ResultList& re
|
|||||||
QStandardItem* item = new QStandardItem;
|
QStandardItem* item = new QStandardItem;
|
||||||
item->setData(QVariant::fromValue(result), Role_PrimaryResult);
|
item->setData(QVariant::fromValue(result), Role_PrimaryResult);
|
||||||
item->setData(QVariant::fromValue(SearchProvider::ResultList() << result), Role_AllResults);
|
item->setData(QVariant::fromValue(SearchProvider::ResultList() << result), Role_AllResults);
|
||||||
|
item->setData(order_arrived_counter_, Role_OrderArrived);
|
||||||
|
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
if (engine_->FindCachedPixmap(result, &pixmap)) {
|
if (engine_->FindCachedPixmap(result, &pixmap)) {
|
||||||
@ -229,12 +232,16 @@ void GlobalSearchWidget::AddResults(int id, const SearchProvider::ResultList& re
|
|||||||
|
|
||||||
if (combine_identical_results_) {
|
if (combine_identical_results_) {
|
||||||
// Maybe we can combine this result with an identical result from another
|
// Maybe we can combine this result with an identical result from another
|
||||||
// provider. Only look at the results above and below this one in the
|
// provider. We can use the sorted model to narrow the scope of the
|
||||||
// sorted model.
|
// search a bit - look at the result after the current one, then all the
|
||||||
|
// results before.
|
||||||
QModelIndex my_proxy_index = proxy_->mapFromSource(item->index());
|
QModelIndex my_proxy_index = proxy_->mapFromSource(item->index());
|
||||||
QModelIndexList candidates;
|
QModelIndexList candidates;
|
||||||
candidates << my_proxy_index.sibling(my_proxy_index.row() - 1, 0)
|
candidates << my_proxy_index.sibling(my_proxy_index.row() + 1, 0);
|
||||||
<< my_proxy_index.sibling(my_proxy_index.row() + 1, 0);
|
|
||||||
|
for (int i=my_proxy_index.row()-1 ; i>=0 ; --i) {
|
||||||
|
candidates << my_proxy_index.sibling(i, 0);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (const QModelIndex& index, candidates) {
|
foreach (const QModelIndex& index, candidates) {
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
@ -261,6 +268,8 @@ void GlobalSearchWidget::AddResults(int id, const SearchProvider::ResultList& re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
order_arrived_counter_ ++;
|
||||||
|
|
||||||
RepositionPopup();
|
RepositionPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,8 @@ public:
|
|||||||
enum Role {
|
enum Role {
|
||||||
Role_PrimaryResult = Qt::UserRole + 1,
|
Role_PrimaryResult = Qt::UserRole + 1,
|
||||||
Role_AllResults,
|
Role_AllResults,
|
||||||
Role_LazyLoadingArt
|
Role_LazyLoadingArt,
|
||||||
|
Role_OrderArrived
|
||||||
};
|
};
|
||||||
|
|
||||||
void Init(GlobalSearch* engine_);
|
void Init(GlobalSearch* engine_);
|
||||||
@ -114,6 +115,7 @@ private:
|
|||||||
GlobalSearch* engine_;
|
GlobalSearch* engine_;
|
||||||
int last_id_;
|
int last_id_;
|
||||||
bool clear_model_on_next_result_;
|
bool clear_model_on_next_result_;
|
||||||
|
int order_arrived_counter_;
|
||||||
|
|
||||||
QMap<int, QModelIndex> art_requests_;
|
QMap<int, QModelIndex> art_requests_;
|
||||||
QMap<int, QAction*> track_requests_;
|
QMap<int, QAction*> track_requests_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user