diff --git a/Common/jaspColumnEncoder b/Common/jaspColumnEncoder index f2239e7064..f6f6f5d80f 160000 --- a/Common/jaspColumnEncoder +++ b/Common/jaspColumnEncoder @@ -1 +1 @@ -Subproject commit f2239e7064aa1bd7a8e38617e36689e963f2db5a +Subproject commit f6f6f5d80fc0c68df9d851c4468259cb00774254 diff --git a/QMLComponents/boundcontrols/boundcontrolbase.cpp b/QMLComponents/boundcontrols/boundcontrolbase.cpp index 4ac93e91fc..de485329cd 100644 --- a/QMLComponents/boundcontrols/boundcontrolbase.cpp +++ b/QMLComponents/boundcontrols/boundcontrolbase.cpp @@ -46,35 +46,6 @@ Json::Value BoundControlBase::createMeta() const return meta; } -bool BoundControlBase::setValueType() -{ - bool hasChanges = false; - AnalysisForm* form = _control->form(); - - if (_control->encodeValue()) - { - JASPListControl* listControl = qobject_cast(_control); - if (listControl) - { - Json::Value jsonTypesOrg = form->boundValue(getName() + ".types", _control->getParentKeys()); - - columnTypeVec types = listControl->valueTypes(); - Json::Value jsonTypes(Json::arrayValue); - - for (columnType type : types) - jsonTypes.append(columnTypeToString(type)); - - if (jsonTypes != jsonTypesOrg) - { - form->setBoundValue(getName() + ".types", jsonTypes, Json::nullValue, _control->getParentKeys()); - hasChanges = true; - } - } - } - - return hasChanges; -} - void BoundControlBase::handleComputedColumn(const Json::Value& value) { if (_isColumn && value.isString()) diff --git a/QMLComponents/boundcontrols/boundcontrolbase.h b/QMLComponents/boundcontrols/boundcontrolbase.h index 71ef25ebaf..dd73f021b4 100644 --- a/QMLComponents/boundcontrols/boundcontrolbase.h +++ b/QMLComponents/boundcontrols/boundcontrolbase.h @@ -46,7 +46,6 @@ class BoundControlBase : public BoundControl protected: std::string getName() const; - bool setValueType(); void handleComputedColumn(const Json::Value& value); Json::Value _getTableValueOption(const Terms& terms, const ListModel::RowControlsValues& componentValuesMap, const std::string& key, bool hasMultipleTerms); diff --git a/QMLComponents/boundcontrols/boundcontrolterms.cpp b/QMLComponents/boundcontrols/boundcontrolterms.cpp index 20ddc8ee6f..f4fbc213c2 100644 --- a/QMLComponents/boundcontrols/boundcontrolterms.cpp +++ b/QMLComponents/boundcontrols/boundcontrolterms.cpp @@ -307,17 +307,6 @@ void BoundControlTerms::resetBoundValue() } } -Json::Value BoundControlTerms::_getTypes() const -{ - columnTypeVec types = _listView->valueTypes(); - Json::Value jsonTypes(Json::arrayValue); - - for (columnType type : types) - jsonTypes.append(columnTypeToString(type)); - - return jsonTypes; -} - void BoundControlTerms::setBoundValue(const Json::Value &value, bool emitChanges) { Json::Value newValue; @@ -329,7 +318,10 @@ void BoundControlTerms::setBoundValue(const Json::Value &value, bool emitChanges else { newValue["value"] = value; - newValue["types"] = _getTypes(); + Json::Value types = _listView->valueTypes(); + if (_isSingleRow && types.isArray() && types.size() > 0) + types = types[0]; + newValue["types"] = types; } if (_listView->hasRowComponent() || _listView->containsInteractions()) newValue["optionKey"] = _optionKey; diff --git a/QMLComponents/boundcontrols/boundcontrolterms.h b/QMLComponents/boundcontrols/boundcontrolterms.h index d446c4beb3..cc075969a9 100644 --- a/QMLComponents/boundcontrols/boundcontrolterms.h +++ b/QMLComponents/boundcontrols/boundcontrolterms.h @@ -41,7 +41,6 @@ class BoundControlTerms : public BoundControlBase Terms _getValuesFromOptions(const Json::Value& option) const; Json::Value _adjustBindingValue(const Json::Value &value) const; Json::Value _adjustBindingType(const Json::Value &value) const; - Json::Value _getTypes() const; ListModelAssignedInterface* _termsModel = nullptr; JASPListControl* _listView = nullptr; diff --git a/QMLComponents/controls/jasplistcontrol.cpp b/QMLComponents/controls/jasplistcontrol.cpp index 3035074ab0..1cd177e59c 100644 --- a/QMLComponents/controls/jasplistcontrol.cpp +++ b/QMLComponents/controls/jasplistcontrol.cpp @@ -296,12 +296,35 @@ std::vector JASPListControl::usedVariables() const else return {}; } -columnTypeVec JASPListControl::valueTypes() const +Json::Value JASPListControl::valueTypes() const { - columnTypeVec types; + Json::Value types(Json::arrayValue); + std::map variableTypeMap; + static columnType unknownType = columnType::unknown; + // An interaction term has components that can be variables: if the model contains also such variables, the interaction term should get the same types. + // So first check which terms have only 1 component: these terms might be variable names, so keep in a map their types. Use then this map to set the type for interaction terms. for (const Term& term : model()->terms()) - types.push_back(term.type()); + if (term.components().size() == 1) + variableTypeMap[term.asString()] = columnTypeToString(term.type()); + + for (const Term& term : model()->terms()) + { + if (term.components().size() == 1) + types.append(columnTypeToString(term.type())); + else + { + Json::Value compTypes(Json::arrayValue); + for (const std::string& component : term.scomponents()) + { + if (variableTypeMap.count(component) > 0) + compTypes.append(variableTypeMap[component]); + else + compTypes.append(columnTypeToString(unknownType)); + } + types.append(compTypes); + } + } return types; } diff --git a/QMLComponents/controls/jasplistcontrol.h b/QMLComponents/controls/jasplistcontrol.h index 7ca1d25dc5..89a526a44a 100644 --- a/QMLComponents/controls/jasplistcontrol.h +++ b/QMLComponents/controls/jasplistcontrol.h @@ -110,7 +110,7 @@ class JASPListControl : public JASPControl bool allowAnalysisOwnComputedColumns() const { return _allowAnalysisOwnComputedColumns; } bool isTypeAllowed(columnType type) const; columnType defaultType() const; - columnTypeVec valueTypes() const; + Json::Value valueTypes() const; const QStringList & columnsTypes() const { return _columnsTypes; } const QStringList & columnsNames() const { return _columnsNames; } QAbstractListModel * allowedTypesModel();