Skip to content

Commit 3746368

Browse files
committed
More
1 parent d957509 commit 3746368

17 files changed

+48
-54
lines changed

Engine/jaspBase

QMLComponents/analysisform.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ QString AnalysisForm::msgsListToString(const QStringList & list) const
310310
if(list.length() == 0)
311311
return "";
312312

313+
if (list.size() == 1)
314+
return list[0];
315+
313316
QString text;
314317
for (const QString & msg : list)
315318
if(msg.size())

QMLComponents/boundcontrols/boundcontrollayers.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool BoundControlLayers::isJsonValid(const Json::Value &optionValue) const
7373
{
7474
const Json::Value& nameOption = value["name"];
7575
const Json::Value& variablesOption = value["variables"];
76-
valid = nameOption.type() == Json::stringValue && variablesOption.type() == Json::arrayValue;
76+
valid = nameOption.type() == Json::stringValue && (variablesOption.type() == Json::arrayValue || variablesOption.type() == Json::stringValue);
7777

7878
if (!valid)
7979
break;

QMLComponents/boundcontrols/boundcontrolterms.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,11 @@ Terms BoundControlTerms::_getTermsFromOptions(const Json::Value& option) const
284284
if (valueOption.isArray())
285285
{
286286
int i = 0;
287-
for (const Json::Value& jsonValue : valueOption)
287+
for (Json::Value jsonValue : valueOption)
288288
{
289+
if (jsonValue.isObject() && jsonValue.isMember(_optionKey))
290+
jsonValue = jsonValue[_optionKey];
291+
289292
const Json::Value& jsonType = typesOption.size() > i ? typesOption[i] : Json::nullValue;
290293
if (jsonValue.isArray())
291294
{

QMLComponents/controls/factorsformbase.cpp

+12-38
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ FactorsFormBase::FactorsFormBase(QQuickItem *parent)
3030
_useControlMouseArea = false;
3131
_containsVariables = true;
3232
_mayUseFormula = false;
33+
_useTermsInRSyntax = false;
3334
}
3435

3536
void FactorsFormBase::setUpModel()
@@ -48,61 +49,38 @@ void FactorsFormBase::setUpModel()
4849
void FactorsFormBase::bindTo(const Json::Value& value)
4950
{
5051
ListModelFactorsForm::FactorVec factors;
51-
Json::Value updatedValue = value; // If the value has no types, then we need to update it.
5252

53-
for (Json::Value& factor : updatedValue)
53+
for (const Json::Value& factor : value)
5454
{
55-
Json::Value types(Json::arrayValue);
56-
if (factor.isMember("types"))
57-
{
58-
if (factor["types"].isArray())
59-
types = factor["types"];
60-
else if (factor["types"].isString())
61-
types.append(factor["types"].asString());
62-
}
63-
int i = 0;
64-
6555
Terms initTerms;
66-
for (const Json::Value& termsJson : factor[fq(_optionKey)])
56+
for (const Json::Value& termJson : factor[fq(_optionKey)])
6757
{
6858
std::vector<std::string> components;
6959

70-
if (termsJson.isArray())
60+
if (termJson.isArray())
7161
{
7262
// For interaction, each term is an array of strings
73-
for (const Json::Value& elt : termsJson)
63+
for (const Json::Value& elt : termJson)
7464
if (elt.isString())
7565
components.push_back(elt.asString());
7666
}
77-
else if (termsJson.isString())
67+
else if (termJson.isString())
7868
// If not, each term is just a string
79-
components.push_back(termsJson.asString());
69+
components.push_back(termJson.asString());
8070

8171
if (components.size() > 0)
8272
{
83-
Term term(components);
84-
columnType type = columnType::unknown;
85-
if (types.size() <= i)
86-
{
87-
if (components.size() == 1)
88-
type = model()->getVariableRealType(tq(components[0]));
89-
types.append(columnTypeToString(type));
90-
}
91-
else
92-
{
93-
type = columnTypeFromString(types[i].asString());
94-
term.setType(type);
95-
}
73+
columnTypeVec types;
74+
for (const std::string& component : components)
75+
types.push_back(model()->getVariableRealType(tq(component)));
76+
Term term(components, types);
9677
initTerms.add(term);
9778
}
98-
99-
i++;
10079
}
101-
factor["types"] = types;
10280
factors.push_back(ListModelFactorsForm::Factor(tq(factor["name"].asString()), tq(factor["title"].asString()), initTerms));
10381
}
10482

105-
BoundControlBase::bindTo(updatedValue);
83+
BoundControlBase::bindTo(value);
10684

10785
_factorsModel->initFactors(factors);
10886
}
@@ -117,7 +95,6 @@ Json::Value FactorsFormBase::createJson() const
11795
row["name"] = fq(baseName() + QString::number(i + startIndex()));
11896
row["title"] = fq(baseTitle() + " " + QString::number(i + startIndex()));
11997
row[fq(_optionKey)] = Json::Value(Json::arrayValue);
120-
row["types"] = Json::Value(Json::arrayValue);
12198

12299
result.append(row);
123100
}
@@ -158,7 +135,6 @@ void FactorsFormBase::termsChangedHandler()
158135
factorJson["name"] = fq(factor.name);
159136
factorJson["title"] = fq(factor.title);
160137
Json::Value termsJson(Json::arrayValue);
161-
Json::Value typesJson(Json::arrayValue);
162138

163139
for (const Term &term : factor.listView ? factor.listView->model()->terms() : factor.initTerms)
164140
{
@@ -171,10 +147,8 @@ void FactorsFormBase::termsChangedHandler()
171147
else
172148
termJson = term.asString();
173149
termsJson.append(termJson);
174-
typesJson.append(columnTypeToString(term.type()));
175150
}
176151
factorJson[fq(_optionKey)] = termsJson;
177-
factorJson["types"] = typesJson;
178152
boundValue.append(factorJson);
179153
}
180154

QMLComponents/controls/jasplistcontrol.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ class JASPListControl : public JASPControl
122122
const QStringList & allowedColumns() const { return _allowedColumns; }
123123
QStringList allowedColumnsIcons() const;
124124
bool mayUseFormula() const { return _mayUseFormula; }
125+
bool useTermsInRSyntax() const { return _useTermsInRSyntax; }
125126
void setMayUseFormula(bool use) { _mayUseFormula = use; }
127+
void setUseTermsInRSyntax(bool use) { _useTermsInRSyntax = use; }
126128

127129
signals:
128130
void modelChanged();
@@ -204,7 +206,8 @@ protected slots:
204206
_addAvailableVariablesToAssigned = false,
205207
_allowAnalysisOwnComputedColumns = true,
206208
_allowTypeChange = false,
207-
_mayUseFormula = true;
209+
_mayUseFormula = true,
210+
_useTermsInRSyntax = true;
208211

209212
int _maxRows = -1,
210213
_minNumericLevels = -1,

QMLComponents/controls/variableslistbase.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void VariablesListBase::setUpModel()
126126
auto * layersModel = new ListModelLayersAssigned(this);
127127
_boundControl = new BoundControlLayers(layersModel);
128128
_draggableModel = layersModel;
129+
_useTermsInRSyntax = false;
129130
break;
130131
}
131132

QMLComponents/models/listmodellayersassigned.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void ListModelLayersAssigned::initLayers(const std::vector<std::vector<std::stri
3232
{
3333
beginResetModel();
3434

35+
_variables.clear();
3536
for (const std::vector<std::string>& variables : allVariables)
3637
{
3738
QList<QString> layer;

QMLComponents/rsyntax/formulaparser.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ Terms FormulaParser::parseTerm(QString termStr)
6363
parsedComponents.push_back(pair.first);
6464
types.push_back(pair.second);
6565
}
66-
Term term(parsedComponents);
67-
term.setTypes(types);
6866

69-
return term;
67+
return Term(parsedComponents, types);
7068
};
7169

7270
Terms result;

QMLComponents/rsyntax/formulasource.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,20 @@ FormulaParser::ParsedTerms FormulaSource::_fillOptionsWithFixedTerms(ListModel*
500500
continue;
501501
}
502502
bool found = false;
503-
Terms terms;
503+
Terms terms, termsToSearch;
504504
terms.add(parsedTerm);
505-
Terms termsToSearch = isInteractionModel ? Terms(parsedTerm.components()) : terms;
505+
if (isInteractionModel)
506+
{
507+
int i = 0;
508+
for (const QString component : parsedTerm.components())
509+
{
510+
columnType type = parsedTerm.types().size() > i ? parsedTerm.types()[i] : columnType::unknown;
511+
termsToSearch.add(Term(component, type));
512+
i++;
513+
}
514+
}
515+
else
516+
termsToSearch = terms;
506517

507518
if (termsToSearch.size() == 0) continue;
508519

QMLComponents/rsyntax/rsyntax.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ QString RSyntax::generateSyntax(bool showAllOptions, bool useHtml) const
129129
result += "," + newLine + indent + getRSyntaxFromControlName(control) + " = ";
130130

131131
JASPListControl* listControl = qobject_cast<JASPListControl*>(control);
132-
if (listControl && !listControl->hasRowComponent() && listControl->containsVariables() && listControl->controlType() != JASPControl::ControlType::FactorsForm)
132+
if (listControl && !listControl->hasRowComponent() && listControl->containsVariables() && listControl->useTermsInRSyntax())
133133
result += _transformInteractionTerms(listControl->model());
134134
else
135135
result += transformJsonToR(foundValue);

0 commit comments

Comments
 (0)