Skip to content

Commit

Permalink
Add types in formula (#5728)
Browse files Browse the repository at this point in the history
* Add types to formula

* Last fixes

* update submodules

* Trim variable

* Ensure types are correct in formula

* remove debuglog
  • Loading branch information
boutinb authored Nov 11, 2024
1 parent c8d2524 commit e6abf6d
Show file tree
Hide file tree
Showing 33 changed files with 459 additions and 456 deletions.
7 changes: 7 additions & 0 deletions QMLComponents/analysisform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ void AnalysisForm::runScriptRequestDone(const QString& result, const QString& co
clearFormErrors();
if (_rSyntax->parseRSyntaxOptions(options))
{
blockValueChangeSignal(true);
_analysis->clearOptions();
bindTo(Json::nullValue);
bindTo(options);
blockValueChangeSignal(false, false);
_analysis->boundValueChangedHandler();
}
}
Expand Down Expand Up @@ -310,6 +314,9 @@ QString AnalysisForm::msgsListToString(const QStringList & list) const
if(list.length() == 0)
return "";

if (list.size() == 1)
return list[0];

QString text;
for (const QString & msg : list)
if(msg.size())
Expand Down
51 changes: 6 additions & 45 deletions QMLComponents/boundcontrols/boundcontrolbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,12 @@ void BoundControlBase::_readTableValue(const Json::Value &value, const std::stri
{
for (const Json::Value& row : value)
{
std::vector<std::string> term;
const Json::Value& keyValue = row[key];
if (keyValue.isArray())
{
for (const Json::Value& component : keyValue)
term.push_back(component.asString());
}
else if (keyValue.isString())
term.push_back(keyValue.asString());
else
Log::log() << "Key (" << key << ") bind value is not an array or a string in " << getName() << ": " << value.toStyledString() << std::endl;
Json::Value keyValue = row[key];

Term term = Term::readTerm(keyValue);
if (term.size() > 0)
{
terms.add(Term(term));
terms.add(term);

QMap<QString, Json::Value> controlMap;
for (auto itr = row.begin(); itr != row.end(); ++itr)
Expand All @@ -145,7 +136,7 @@ void BoundControlBase::_readTableValue(const Json::Value &value, const std::stri
controlMap[tq(name)] = *itr;
}

allControlValues[Term(term).asQString()] = controlMap;
allControlValues[term.asQString()] = controlMap;
}
}
}
Expand All @@ -158,39 +149,9 @@ Json::Value BoundControlBase::_getTableValueOption(const Terms& terms, const Lis
{
QMap<QString, Json::Value> componentValues = componentValuesMap[term.asQString()];

Json::Value rowValues(Json::objectValue),
keyValue; // depending of keyHasVariables & hasInteraction, keyValue can be an object, an array or a string

if (keyHasVariables)
{
// If the key of the row contains variables, set 'value' and 'types'
Json::Value jsonValue, jsonTypes;

if (hasInteraction)
{
for (const std::string& comp : term.scomponents())
jsonValue.append(comp);
for (columnType type : term.types())
jsonTypes.append(columnTypeToString(type));
}
else
{
jsonValue = term.asString();
jsonTypes = columnTypeToString(term.type());
}
keyValue["value"] = jsonValue;
keyValue["types"] = jsonTypes;
}
else
{
if (hasInteraction)
for (const std::string& comp : term.scomponents())
keyValue.append(comp);
else
keyValue = term.asString();
}
Json::Value rowValues(Json::objectValue);

rowValues[key] = keyValue;
rowValues[key] = term.toJson(hasInteraction, keyHasVariables);

QMapIterator<QString, Json::Value> it2(componentValues);
while (it2.hasNext())
Expand Down
2 changes: 1 addition & 1 deletion QMLComponents/boundcontrols/boundcontrolbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BoundControlBase : public BoundControl
std::string getName() const;
void handleComputedColumn(const Json::Value& value);

Json::Value _getTableValueOption(const Terms& terms, const ListModel::RowControlsValues& componentValuesMap, const std::string& key, bool hasInteraction, bool keyHasVariables);
static Json::Value _getTableValueOption(const Terms& terms, const ListModel::RowControlsValues& componentValuesMap, const std::string& key, bool hasInteraction, bool keyHasVariables);
void _setTableValue(const Terms& terms, const ListModel::RowControlsValues& componentValuesMap, const std::string& key, bool hasInteraction, bool keyHasVariables = false);

void _readTableValue(const Json::Value& value, const std::string& key, bool hasMultipleTerms, Terms& terms, ListModel::RowControlsValues& allControlValues);
Expand Down
2 changes: 1 addition & 1 deletion QMLComponents/boundcontrols/boundcontrollayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool BoundControlLayers::isJsonValid(const Json::Value &optionValue) const
{
const Json::Value& nameOption = value["name"];
const Json::Value& variablesOption = value["variables"];
valid = nameOption.type() == Json::stringValue && variablesOption.type() == Json::arrayValue;
valid = nameOption.type() == Json::stringValue && (variablesOption.type() == Json::arrayValue || variablesOption.type() == Json::stringValue);

if (!valid)
break;
Expand Down
Loading

0 comments on commit e6abf6d

Please sign in to comment.