diff --git a/Common/jaspColumnEncoder b/Common/jaspColumnEncoder index e219fb1198..094a53c3d8 160000 --- a/Common/jaspColumnEncoder +++ b/Common/jaspColumnEncoder @@ -1 +1 @@ -Subproject commit e219fb1198c657ed88d3fdf1e79930337df31cce +Subproject commit 094a53c3d8b3375bcb486ec2ded5843e15933291 diff --git a/Modules/jaspTestModule b/Modules/jaspTestModule index 4937eb1def..c27e076b5e 160000 --- a/Modules/jaspTestModule +++ b/Modules/jaspTestModule @@ -1 +1 @@ -Subproject commit 4937eb1def08c1621c200382cedef33846fcc1f5 +Subproject commit c27e076b5eb3e3c3b4699da44564281f64302991 diff --git a/QMLComponents/boundcontrols/boundcontrolmultiterms.cpp b/QMLComponents/boundcontrols/boundcontrolmultiterms.cpp index a07493dd2e..9effb8dc3b 100644 --- a/QMLComponents/boundcontrols/boundcontrolmultiterms.cpp +++ b/QMLComponents/boundcontrols/boundcontrolmultiterms.cpp @@ -27,11 +27,13 @@ BoundControlMultiTerms::BoundControlMultiTerms(ListModelMultiTermsAssigned* list void BoundControlMultiTerms::bindTo(const Json::Value& value) { - BoundControlBase::bindTo(value); + Json::Value adjustedValue = _isValueWithTypes(value) ? value["value"] : value; + + BoundControlBase::bindTo(adjustedValue); std::vector > values; - for (const Json::Value& rowJson : value) + for (const Json::Value& rowJson : adjustedValue) { std::vector rowValues; if (rowJson.isArray()) @@ -54,7 +56,7 @@ Json::Value BoundControlMultiTerms::createJson() const bool BoundControlMultiTerms::isJsonValid(const Json::Value &optionValue) const { - return optionValue.type() == Json::arrayValue; + return optionValue.type() == Json::arrayValue || optionValue.type() == Json::objectValue; } void BoundControlMultiTerms::resetBoundValue() @@ -71,3 +73,37 @@ void BoundControlMultiTerms::resetBoundValue() setBoundValue(boundValue); } + +void BoundControlMultiTerms::setBoundValue(const Json::Value &value, bool emitChanges) +{ + Json::Value newValue; + + if (_control->encodeValue()) + { + if (_isValueWithTypes(value)) + newValue = value; + else + { + // Else we are loading from a jasp version before "preloadData" was on or var.types were added to the options + Json::Value types(Json::arrayValue); + std::string type = columnTypeToString(_listModel->listView()->defaultType()); + for (const Json::Value& row : value) + { + Json::Value rowType(Json::arrayValue); + if (row.isString()) + rowType.append(type); + else if (row.isArray()) + { + for (int i = 0; i < row.size(); i++) + rowType.append(type); + } + types.append(rowType); + } + newValue["value"] = value; + newValue["types"] = types; + } + } + + BoundControlBase::setBoundValue(newValue.isNull() ? value : newValue, emitChanges); + +} diff --git a/QMLComponents/boundcontrols/boundcontrolmultiterms.h b/QMLComponents/boundcontrols/boundcontrolmultiterms.h index f7fa41bbcc..90a1d18e36 100644 --- a/QMLComponents/boundcontrols/boundcontrolmultiterms.h +++ b/QMLComponents/boundcontrols/boundcontrolmultiterms.h @@ -28,10 +28,11 @@ class BoundControlMultiTerms : public BoundControlBase public: BoundControlMultiTerms(ListModelMultiTermsAssigned* listModel); - bool isJsonValid(const Json::Value& optionValue) const override; - Json::Value createJson() const override; - void bindTo(const Json::Value &value) override; - void resetBoundValue() override; + bool isJsonValid(const Json::Value& optionValue) const override; + Json::Value createJson() const override; + void bindTo(const Json::Value &value) override; + void resetBoundValue() override; + void setBoundValue(const Json::Value &value, bool emitChanges = true) override; private: