Skip to content

Commit

Permalink
Handle also paired variablesList (#5721)
Browse files Browse the repository at this point in the history
* Handle also paired variablesList

The Bain Paired T-Tests is in preloadData mode, and should work.

* Update jaspTestModule

* Update QMLComponents/boundcontrols/boundcontrolmultiterms.cpp

Co-authored-by: Joris Goosen <Joris@JorisGoosen.nl>

---------

Co-authored-by: Joris Goosen <Joris@JorisGoosen.nl>
  • Loading branch information
boutinb and JorisGoosen authored Oct 29, 2024
1 parent ddee9ba commit 70509f4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
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);
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

0 comments on commit 70509f4

Please sign in to comment.