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
|
// Set up the preview widget that's already at the bottom of the sort page
|
||||||
sort_ui_->preview->set_library(library_);
|
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
|
// Configure the page text
|
||||||
search_page_->setTitle(tr("Search terms"));
|
search_page_->setTitle(tr("Search terms"));
|
||||||
|
@ -79,6 +79,14 @@ bool Search::is_valid() const {
|
|||||||
return !terms_.isEmpty();
|
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
|
} // namespace
|
||||||
|
|
||||||
QDataStream& operator <<(QDataStream& s, const smart_playlists::Search& search) {
|
QDataStream& operator <<(QDataStream& s, const smart_playlists::Search& search) {
|
||||||
|
@ -46,6 +46,8 @@ public:
|
|||||||
int limit = Generator::kDefaultLimit);
|
int limit = Generator::kDefaultLimit);
|
||||||
|
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
|
bool operator ==(const Search& other) const;
|
||||||
|
bool operator !=(const Search& other) const { return !(*this == other); }
|
||||||
|
|
||||||
SearchType search_type_;
|
SearchType search_type_;
|
||||||
TermList terms_;
|
TermList terms_;
|
||||||
|
@ -58,6 +58,11 @@ void SearchPreview::set_library(LibraryBackend* backend) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SearchPreview::Update(const Search& search) {
|
void SearchPreview::Update(const Search& search) {
|
||||||
|
if (search == last_search_) {
|
||||||
|
// This search was the same as the last one we did
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (generator_) {
|
if (generator_) {
|
||||||
// It's busy generating something already
|
// It's busy generating something already
|
||||||
pending_search_ = search;
|
pending_search_ = search;
|
||||||
@ -84,9 +89,11 @@ void SearchPreview::RunSearch(const Search& search) {
|
|||||||
void SearchPreview::SearchFinished() {
|
void SearchPreview::SearchFinished() {
|
||||||
FutureWatcher* watcher = static_cast<FutureWatcher*>(sender());
|
FutureWatcher* watcher = static_cast<FutureWatcher*>(sender());
|
||||||
watcher->deleteLater();
|
watcher->deleteLater();
|
||||||
|
|
||||||
|
last_search_ = generator_->search();
|
||||||
generator_.reset();
|
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
|
// There was another search done while we were running - throw away these
|
||||||
// results and do that one now instead
|
// results and do that one now instead
|
||||||
RunSearch(pending_search_);
|
RunSearch(pending_search_);
|
||||||
|
@ -56,6 +56,7 @@ private:
|
|||||||
Playlist* model_;
|
Playlist* model_;
|
||||||
|
|
||||||
Search pending_search_;
|
Search pending_search_;
|
||||||
|
Search last_search_;
|
||||||
boost::scoped_ptr<QueryGenerator> generator_;
|
boost::scoped_ptr<QueryGenerator> generator_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -71,6 +71,12 @@ bool SearchTerm::is_valid() const {
|
|||||||
return false;
|
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) {
|
SearchTerm::Type SearchTerm::TypeOf(Field field) {
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case Field_Length:
|
case Field_Length:
|
||||||
|
@ -85,6 +85,8 @@ public:
|
|||||||
|
|
||||||
QString ToSql() const;
|
QString ToSql() const;
|
||||||
bool is_valid() 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 Type TypeOf(Field field);
|
||||||
static QList<Operator> OperatorsForType(Type type);
|
static QList<Operator> OperatorsForType(Type type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user