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

Handle also paired variablesList #5721

Merged
merged 3 commits into from
Oct 29, 2024
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 Common/jaspColumnEncoder
2 changes: 1 addition & 1 deletion Modules/jaspTestModule
42 changes: 39 additions & 3 deletions QMLComponents/boundcontrols/boundcontrolmultiterms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<std::string> > values;

for (const Json::Value& rowJson : value)
for (const Json::Value& rowJson : adjustedValue)
{
std::vector<std::string> rowValues;
if (rowJson.isArray())
Expand All @@ -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()
Expand All @@ -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);
boutinb marked this conversation as resolved.
Show resolved Hide resolved
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);

}
9 changes: 5 additions & 4 deletions QMLComponents/boundcontrols/boundcontrolmultiterms.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading