Make the search preview work in the sort tab, and don't do duplicate searches
This commit is contained in:
parent
052ddb74a1
commit
48868ee092
@ -127,6 +127,13 @@ int QueryWizardPlugin::CreatePages(QWizard* wizard, int finish_page_id) {
|
||||
|
||||
// Set up the preview widget that's already at the bottom of the sort page
|
||||
sort_ui_->preview->set_library(library_);
|
||||
connect(sort_ui_->field, SIGNAL(toggled(bool)), SLOT(UpdateSortPreview()));
|
||||
connect(sort_ui_->field_value, SIGNAL(currentIndexChanged(int)), SLOT(UpdateSortPreview()));
|
||||
connect(sort_ui_->limit_limit, SIGNAL(toggled(bool)), SLOT(UpdateSortPreview()));
|
||||
connect(sort_ui_->limit_none, SIGNAL(toggled(bool)), SLOT(UpdateSortPreview()));
|
||||
connect(sort_ui_->limit_value, SIGNAL(valueChanged(QString)), SLOT(UpdateSortPreview()));
|
||||
connect(sort_ui_->order, SIGNAL(currentIndexChanged(int)), SLOT(UpdateSortPreview()));
|
||||
connect(sort_ui_->random, SIGNAL(toggled(bool)), SLOT(UpdateSortPreview()));
|
||||
|
||||
// Configure the page text
|
||||
search_page_->setTitle(tr("Search terms"));
|
||||
|
@ -79,6 +79,14 @@ bool Search::is_valid() const {
|
||||
return !terms_.isEmpty();
|
||||
}
|
||||
|
||||
bool Search::operator ==(const Search& other) const {
|
||||
return search_type_ == other.search_type_ &&
|
||||
terms_ == other.terms_ &&
|
||||
sort_type_ == other.sort_type_ &&
|
||||
sort_field_ == other.sort_field_ &&
|
||||
limit_ == other.limit_;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
QDataStream& operator <<(QDataStream& s, const smart_playlists::Search& search) {
|
||||
|
@ -46,6 +46,8 @@ public:
|
||||
int limit = Generator::kDefaultLimit);
|
||||
|
||||
bool is_valid() const;
|
||||
bool operator ==(const Search& other) const;
|
||||
bool operator !=(const Search& other) const { return !(*this == other); }
|
||||
|
||||
SearchType search_type_;
|
||||
TermList terms_;
|
||||
|
@ -58,6 +58,11 @@ void SearchPreview::set_library(LibraryBackend* backend) {
|
||||
}
|
||||
|
||||
void SearchPreview::Update(const Search& search) {
|
||||
if (search == last_search_) {
|
||||
// This search was the same as the last one we did
|
||||
return;
|
||||
}
|
||||
|
||||
if (generator_) {
|
||||
// It's busy generating something already
|
||||
pending_search_ = search;
|
||||
@ -84,9 +89,11 @@ void SearchPreview::RunSearch(const Search& search) {
|
||||
void SearchPreview::SearchFinished() {
|
||||
FutureWatcher* watcher = static_cast<FutureWatcher*>(sender());
|
||||
watcher->deleteLater();
|
||||
|
||||
last_search_ = generator_->search();
|
||||
generator_.reset();
|
||||
|
||||
if (pending_search_.is_valid()) {
|
||||
if (pending_search_.is_valid() && pending_search_ != last_search_) {
|
||||
// There was another search done while we were running - throw away these
|
||||
// results and do that one now instead
|
||||
RunSearch(pending_search_);
|
||||
|
@ -56,6 +56,7 @@ private:
|
||||
Playlist* model_;
|
||||
|
||||
Search pending_search_;
|
||||
Search last_search_;
|
||||
boost::scoped_ptr<QueryGenerator> generator_;
|
||||
};
|
||||
|
||||
|
@ -71,6 +71,12 @@ bool SearchTerm::is_valid() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SearchTerm::operator ==(const SearchTerm& other) const {
|
||||
return field_ == other.field_ &&
|
||||
operator_ == other.operator_ &&
|
||||
value_ == other.value_;
|
||||
}
|
||||
|
||||
SearchTerm::Type SearchTerm::TypeOf(Field field) {
|
||||
switch (field) {
|
||||
case Field_Length:
|
||||
|
@ -85,6 +85,8 @@ public:
|
||||
|
||||
QString ToSql() const;
|
||||
bool is_valid() const;
|
||||
bool operator ==(const SearchTerm& other) const;
|
||||
bool operator !=(const SearchTerm& other) const { return !(*this == other); }
|
||||
|
||||
static Type TypeOf(Field field);
|
||||
static QList<Operator> OperatorsForType(Type type);
|
||||
|
Loading…
x
Reference in New Issue
Block a user