Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable type change in CFA does not rerun the analysis #5774

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/jaspTestModule
55 changes: 40 additions & 15 deletions QMLComponents/controls/factorsformbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ void FactorsFormBase::setUpModel()

void FactorsFormBase::bindTo(const Json::Value& value)
{
Json::Value newValue = value;
ListModelFactorsForm::FactorVec factors;

for (const Json::Value& factor : value)
for (Json::Value& factor : newValue)
{
int termId = 0;
Terms initTerms;
for (const Json::Value& termJson : factor[fq(_optionKey)])
const Json::Value& termsJson = factor[fq(_optionKey)];
Json::Value valuePart = _isValueWithTypes(termsJson) ? termsJson["value"] : termsJson;
Json::Value typesPart = _isValueWithTypes(termsJson) ? termsJson["types"] : Json::arrayValue;
for (Json::Value& termJson : valuePart)
{
std::vector<std::string> components;

Expand All @@ -71,16 +76,31 @@ void FactorsFormBase::bindTo(const Json::Value& value)
if (components.size() > 0)
{
columnTypeVec types;
for (const std::string& component : components)
types.push_back(model()->getVariableRealType(tq(component)));
Term term(components, types);
initTerms.add(term);
if (typesPart.size() > termId) // If the type is given, use it
{
if (typesPart[termId].isArray())
for (const Json::Value& jsonType : typesPart[termId])
types.push_back(columnTypeFromString(jsonType.asString(), columnType::unknown));
else
types.push_back(columnTypeFromString(typesPart[termId].asString(), columnType::unknown));
}
else
for (const std::string& component : components)
types.push_back(model()->getVariableRealType(tq(component)));
initTerms.add(Term(components, types));
}
termId++;
}

factors.push_back(ListModelFactorsForm::Factor(tq(factor["name"].asString()), tq(factor["title"].asString()), initTerms));

Json::Value newTerms = Json::objectValue;
newTerms["value"] = valuePart;
newTerms["types"] = initTerms.types();
factor[fq(_optionKey)] = newTerms;
}

BoundControlBase::bindTo(value);
BoundControlBase::bindTo(newValue);

_factorsModel->initFactors(factors);
}
Expand All @@ -94,7 +114,7 @@ Json::Value FactorsFormBase::createJson() const
Json::Value row(Json::objectValue);
row["name"] = fq(baseName() + QString::number(i + startIndex()));
row["title"] = fq(baseTitle() + " " + QString::number(i + startIndex()));
row[fq(_optionKey)] = Json::Value(Json::arrayValue);
row[fq(_optionKey)] = Json::Value(Json::objectValue);

result.append(row);
}
Expand All @@ -109,7 +129,7 @@ bool FactorsFormBase::isJsonValid(const Json::Value &value) const
{
for (const Json::Value& factor : value)
{
valid = factor.isObject() && factor["name"].isString() && factor["title"].isString() && factor[fq(_optionKey)].isArray();
valid = factor.isObject() && factor["name"].isString() && factor["title"].isString() && factor.isMember(fq(_optionKey));
if (!valid) break;
}
}
Expand All @@ -131,12 +151,11 @@ void FactorsFormBase::termsChangedHandler()

for (const auto &factor : factors)
{
Json::Value factorJson(Json::objectValue);
factorJson["name"] = fq(factor.name);
factorJson["title"] = fq(factor.title);
Json::Value termsJson(Json::arrayValue);
const Terms& terms = factor.listView ? factor.listView->model()->terms() : factor.initTerms;
Json::Value valuePart(Json::arrayValue),
typesPart = terms.types();

for (const Term &term : factor.listView ? factor.listView->model()->terms() : factor.initTerms)
for (const Term &term : terms)
{
Json::Value termJson(allowInteraction() ? Json::arrayValue : Json::stringValue);
if (allowInteraction())
Expand All @@ -146,8 +165,14 @@ void FactorsFormBase::termsChangedHandler()
}
else
termJson = term.asString();
termsJson.append(termJson);
valuePart.append(termJson);
}
Json::Value factorJson(Json::objectValue),
termsJson(Json::objectValue);
factorJson["name"] = fq(factor.name);
factorJson["title"] = fq(factor.title);
termsJson["value"] = valuePart;
termsJson["types"] = terms.types();
factorJson[fq(_optionKey)] = termsJson;
boundValue.append(factorJson);
}
Expand Down
Loading