Skip to content

Commit

Permalink
Suboption not always updated in componentsList
Browse files Browse the repository at this point in the history
In a componentsList has, the controls can be created before the parent control is completed. When creating the json option, for this sub-control, the parent object does not exist. So it must be created. Also the meta information is maybe not yet available, so to check whether the option has types, we cannot trust the meta information, but we need to check whether the json is an object with "value" and "types" as member.
  • Loading branch information
boutinb committed Jul 3, 2024
1 parent 67b7770 commit f41a7f5
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions QMLComponents/analysisbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ Json::Value& AnalysisBase::_getParentBoundValue(const QVector<JASPControl::Paren
{
found = (parentKeys.size() == 0);
Json::Value* parentBoundValue = &_boundValues;
Json::Value* metaValue = &_boundValues[".meta"];

// A parentKey has 3 properties: <name>, <key> and <value>: it assumes that the json boundValue is an abject, one of its member is <name>,
// whom value is an array of json objects. These objects have a member <key>, and one of them has for value <value>.
Expand Down Expand Up @@ -149,9 +148,7 @@ Json::Value& AnalysisBase::_getParentBoundValue(const QVector<JASPControl::Paren
if (parentBoundValue->isMember(parent.name))
{
Json::Value* parentBoundValues = &(*parentBoundValue)[parent.name];
metaValue = &(*metaValue)[parent.name];
bool hasTypes = !metaValue->isNull() && metaValue->isMember("hasTypes") ? (*metaValue)["hasTypes"].asBool() : false;
if (hasTypes && parentBoundValues->isObject() && parentBoundValues->isMember("value"))
if (parentBoundValues->isObject() && parentBoundValues->isMember("value") && parentBoundValues->isMember("types"))
parentBoundValues = &(*parentBoundValues)["value"];

if (!parentBoundValues->isNull() && parentBoundValues->isArray())
Expand Down Expand Up @@ -184,23 +181,23 @@ Json::Value& AnalysisBase::_getParentBoundValue(const QVector<JASPControl::Paren
}
}
}
}

if (!found && createAnyway)
if (!found && createAnyway && (parentBoundValues->isNull() || parentBoundValues->isArray()))
{
// A control can be created before the parent control is completed.
Json::Value row(Json::objectValue);
if (parent.value.size() == 1)
row[parent.key] = parent.value[0];
else
{
// A control can be created before the parent control is completed.
Json::Value row(Json::objectValue);
if (parent.value.size() == 1)
row[parent.key] = parent.value[0];
else
{
Json::Value newValue(Json::arrayValue);
for (size_t i = 0; i < parent.value.size(); i++)
newValue.append(parent.value[i]);
row[parent.key] = newValue;
}
parentBoundValue = &(parentBoundValues->append(row));
found = true;
Json::Value newValue(Json::arrayValue);
for (size_t i = 0; i < parent.value.size(); i++)
newValue.append(parent.value[i]);
row[parent.key] = newValue;
}
parentBoundValue = &(parentBoundValues->append(row));
found = true;
}
}
}
Expand Down

0 comments on commit f41a7f5

Please sign in to comment.