CollectionModel: Fix compilation requirement query

Fixes #1140
This commit is contained in:
Jonas Kvinge 2023-02-18 16:40:12 +01:00
parent 506e670aa7
commit 79bf194ed6
3 changed files with 21 additions and 9 deletions

View File

@ -869,7 +869,13 @@ CollectionModel::QueryResult CollectionModel::RunQuery(const CollectionFilterOpt
for (const CollectionQueryOptions::Where &where_clauses : query_options.where_clauses()) {
q.AddWhere(where_clauses.column, where_clauses.value, where_clauses.op);
}
q.AddCompilationRequirement(query_options.compilation_requirement());
if (result.create_va) {
q.AddCompilationRequirement(false);
}
else if (query_options.compilation_requirement() != CollectionQueryOptions::CompilationRequirement::None) {
q.AddCompilationRequirement(query_options.compilation_requirement() == CollectionQueryOptions::CompilationRequirement::On);
}
if (q.Exec()) {
while (q.Next()) {
@ -1090,21 +1096,21 @@ void CollectionModel::AddQueryWhere(const GroupBy group_by, const bool separate_
switch (group_by) {
case GroupBy::AlbumArtist:
if (IsCompilationArtistNode(item)) {
query_options->set_compilation_requirement(true);
query_options->set_compilation_requirement(CollectionQueryOptions::CompilationRequirement::On);
}
else {
// Don't duplicate compilations outside the Various artists node
query_options->set_compilation_requirement(false);
query_options->set_compilation_requirement(CollectionQueryOptions::CompilationRequirement::Off);
query_options->AddWhere("effective_albumartist", item->metadata.effective_albumartist());
}
break;
case GroupBy::Artist:
if (IsCompilationArtistNode(item)) {
query_options->set_compilation_requirement(true);
query_options->set_compilation_requirement(CollectionQueryOptions::CompilationRequirement::On);
}
else {
// Don't duplicate compilations outside the Various artists node
query_options->set_compilation_requirement(false);
query_options->set_compilation_requirement(CollectionQueryOptions::CompilationRequirement::Off);
query_options->AddWhere("artist", item->metadata.artist());
}
break;

View File

@ -24,7 +24,7 @@
#include "collectionfilteroptions.h"
CollectionQueryOptions::CollectionQueryOptions()
: compilation_requirement_(false),
: compilation_requirement_(CollectionQueryOptions::CompilationRequirement::None),
query_have_compilations_(false) {}
void CollectionQueryOptions::AddWhere(const QString &column, const QVariant &value, const QString &op) {

View File

@ -36,12 +36,18 @@ class CollectionQueryOptions {
QString op;
};
enum class CompilationRequirement {
None,
On,
Off
};
QString column_spec() const { return column_spec_; }
bool compilation_requirement() const { return compilation_requirement_; }
CompilationRequirement compilation_requirement() const { return compilation_requirement_; }
bool query_have_compilations() const { return query_have_compilations_; }
void set_column_spec(const QString &column_spec) { column_spec_ = column_spec; }
void set_compilation_requirement(const bool compilation_requirement) { compilation_requirement_ = compilation_requirement; }
void set_compilation_requirement(const CompilationRequirement compilation_requirement) { compilation_requirement_ = compilation_requirement; }
void set_query_have_compilations(const bool query_have_compilations) { query_have_compilations_ = query_have_compilations; }
QList<Where> where_clauses() const { return where_clauses_; }
@ -49,7 +55,7 @@ class CollectionQueryOptions {
private:
QString column_spec_;
bool compilation_requirement_;
CompilationRequirement compilation_requirement_;
bool query_have_compilations_;
QList<Where> where_clauses_;
};