Skip to content

Commit

Permalink
Last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
boutinb committed Nov 8, 2024
1 parent decd3c0 commit 28267a6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
3 changes: 3 additions & 0 deletions QMLComponents/boundcontrols/boundcontrolterms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,11 @@ Json::Value BoundControlTerms::makeOption(const Terms& terms, const ListModel::R
else if (isSingleRow)
optionValue = terms.size() > 0 ? terms[0].asString() : "";
else
{
optionValue = Json::arrayValue;
for (const Term& term : terms)
optionValue.append(term.asString());
}

result["value"] = optionValue;
result["types"] = terms.types();
Expand Down
2 changes: 1 addition & 1 deletion QMLComponents/components/JASP/Controls/VariablesList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ VariablesListBase
property bool containsDragItem: variablesList.itemContainingDrag === itemRectangle
property bool isVirtual: (typeof model.type !== "undefined") && model.type.includes("virtual")
property bool isVariable: (typeof model.type !== "undefined") && model.type.includes("variable")
property string preview: !isVariable ? "" : model.preview
property string preview: !isVariable || (typeof model.preview === "undefined") ? "" : model.preview
property bool isLayer: (typeof model.type !== "undefined") && model.type.includes("layer")
property bool draggable: variablesList.draggable && model.selectable
property string columnType: isVariable && (typeof model.columnType !== "undefined") ? model.columnType : ""
Expand Down
12 changes: 9 additions & 3 deletions QMLComponents/models/listmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "controls/rowcontrols.h"
#include "controls/sourceitem.h"
#include "log.h"
#include "jsonutilities.h"

ListModel::ListModel(JASPListControl* listView)
: QAbstractTableModel(listView)
Expand Down Expand Up @@ -796,8 +797,13 @@ void ListModel::_replaceTerm(int index, const Term &term)

Json::Value ListModel::getVariableTypes(bool onlyChanged) const
{
if (onlyChanged && _listView->hasMandatoryType())
return Json::nullValue;
return getVariableTypes(_terms, onlyChanged);
}

Json::Value ListModel::getVariableTypes(const Terms& terms, bool onlyChanged) const
{
if (onlyChanged && _listView->hasMandatoryType()) // Don't need to ask for the changed types: this avoids to add the type in formula when it is not necessary
return JsonUtilities::vecToJsonArray(stringvec(terms.size(), columnTypeToString(columnType::unknown)));

return _terms.types(onlyChanged, this);
return terms.types(onlyChanged, this);
}
1 change: 1 addition & 0 deletions QMLComponents/models/listmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class ListModel : public QAbstractTableModel, public VariableInfoConsumer
void setVariableType(int index, columnType type);
columnType getVariableType( const QString& name) const;
Json::Value getVariableTypes(bool onlyChanged = false) const;
Json::Value getVariableTypes(const Terms& terms, bool onlyChanged = false) const;
columnType getVariableRealType(const QString& name) const;
QString getVariablePreview( const QString& name) const;
QStringList getUsedTypes() const;
Expand Down
6 changes: 3 additions & 3 deletions QMLComponents/rsyntax/formulasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ QString FormulaSource::_generateRandomEffectsTerms(const Terms& terms) const
result += (hasIntercept ? "1" : "0");

if (filteredTerms.size() > 0)
result += " + " + generateInteractionTerms(filteredTerms, filteredTerms.types(true, componentListModel));
result += " + " + generateInteractionTerms(filteredTerms, componentListModel->getVariableTypes(filteredTerms, true));

result += (hasCorrelation ? " | " : " || ");
result += key;
Expand Down Expand Up @@ -309,14 +309,14 @@ QString FormulaSource::generateInteractionTerms(const Terms& tterms, const Json:
}


QString FormulaSource::_generateSimpleTerms(const Terms &terms, const Json::Value& changedTypes) const
QString FormulaSource::_generateSimpleTerms(const Terms &terms, const Json::Value& types) const
{
QString result;
int i = 0;

for (const Term& term : terms)
{
Json::Value changedType = changedTypes.size() > i ? changedTypes[i] : Json::nullValue;
Json::Value changedType = types.size() > i ? types[i] : Json::nullValue;
if (i > 0) result += " + ";
result += FormulaParser::transformToFormulaTerm(term, changedType, FormulaParser::interactionSeparator);
i++;
Expand Down
2 changes: 1 addition & 1 deletion QMLComponents/rsyntax/formulasource.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class FormulaSource : public QObject
void _addError(const QString& error) const;
std::string _controlToOptionName(const QString& name) const;
QString _generateRandomEffectsTerms(const Terms& terms) const;
QString _generateSimpleTerms(const Terms& terms, const Json::Value& changedTypes) const;
QString _generateSimpleTerms(const Terms& terms, const Json::Value& types) const;
std::pair<Terms, Json::Value> _onlyTrueTerms(const QString& controlName) const;
bool _areTermsInOptions(ListModelAssignedInterface* model, const Json::Value& options, Terms& terms) const;
void _addTermsToOptions(ListModelAssignedInterface* model, Json::Value& options, const Terms& terms) const;
Expand Down

0 comments on commit 28267a6

Please sign in to comment.