Make the search preview work in the sort tab, and don't do duplicate searches

This commit is contained in:
David Sansome 2010-11-20 12:20:26 +00:00
parent 052ddb74a1
commit 48868ee092
7 changed files with 34 additions and 1 deletions

View File

@ -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"));

View File

@ -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) {

View File

@ -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_;

View File

@ -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_);

View File

@ -56,6 +56,7 @@ private:
Playlist* model_;
Search pending_search_;
Search last_search_;
boost::scoped_ptr<QueryGenerator> generator_;
};

View File

@ -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:

View File

@ -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);