From 856c8947f355192b9b79d799a44fb11e7dbb10e6 Mon Sep 17 00:00:00 2001 From: boutinb Date: Wed, 20 Nov 2024 15:54:24 +0100 Subject: [PATCH 1/3] Fix some issues found in the Test Module . In Test Variable Encoding, if you drag & drop 2 variables in an Interaction VariablesList, it adds automatically the interaction term. If there is an allowed type, the terms should get automatically this type even if they have another type. This does not work for the interaction term: in the result, we can still see that it keeps the original types. . In Test Sources with special attributes analysis, in the source with levels section. If you set a nominal/ordinal variable, you see the levels of the variable in the dropdown. If you duplicate the analysis, it loses these values. --- QMLComponents/controls/comboboxbase.cpp | 19 +++++++++++++++++-- QMLComponents/controls/comboboxbase.h | 1 + QMLComponents/controls/jasplistcontrol.cpp | 2 +- .../models/listmodelinteractionassigned.cpp | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/QMLComponents/controls/comboboxbase.cpp b/QMLComponents/controls/comboboxbase.cpp index b2f7309b41..43aaa0f4f6 100644 --- a/QMLComponents/controls/comboboxbase.cpp +++ b/QMLComponents/controls/comboboxbase.cpp @@ -82,6 +82,8 @@ void ComboBoxBase::bindTo(const Json::Value& value) index = int(std::distance(values.begin(), itr)); } } + else if (!selectedValue.empty()) + _lostValue = selectedValue; _setCurrentProperties(index); @@ -133,7 +135,7 @@ Json::Value ComboBoxBase::createJson() const bool ComboBoxBase::isJsonValid(const Json::Value &optionValue) const { - return optionValue.type() == Json::stringValue || optionValue.type() == Json::arrayValue; + return optionValue.type() == Json::stringValue || optionValue.type() == Json::objectValue; } void ComboBoxBase::setUp() @@ -151,8 +153,10 @@ void ComboBoxBase::setUp() connect(this, &ComboBoxBase::currentValueChanged, [this] () { if (containsVariables()) checkLevelsConstraints(); } ); if (form()) + { connect(form(), &AnalysisForm::languageChanged, [this] () { _model->resetTermsFromSources(); } ); - + connect(form(), &AnalysisForm::analysisChanged, [this] () { _lostValue = ""; }); + } } void ComboBoxBase::setUpModel() @@ -180,6 +184,17 @@ void ComboBoxBase::termsChangedHandler() { auto itr = std::find(values.begin(), values.end(), fq(_currentValue)); + if (!_lostValue.empty()) + { + auto lostValueItr = std::find(values.begin(), values.end(), _lostValue); + if (lostValueItr != values.end()) + { + itr = lostValueItr; + _orgValue = _lostValue; + _lostValue = ""; + } + } + if (itr == values.end()) index = _getStartIndex(); else index = int(std::distance(values.begin(), itr)); } diff --git a/QMLComponents/controls/comboboxbase.h b/QMLComponents/controls/comboboxbase.h index 6a65ff28ba..02d32b54ce 100644 --- a/QMLComponents/controls/comboboxbase.h +++ b/QMLComponents/controls/comboboxbase.h @@ -92,6 +92,7 @@ protected slots: _currentColumnType, _currentColumnRealType, _currentColumnTypeIcon; + std::string _lostValue; int _currentIndex = -1; bool _fixedWidth = false; diff --git a/QMLComponents/controls/jasplistcontrol.cpp b/QMLComponents/controls/jasplistcontrol.cpp index bb8dec1326..bb2ef6c145 100644 --- a/QMLComponents/controls/jasplistcontrol.cpp +++ b/QMLComponents/controls/jasplistcontrol.cpp @@ -410,7 +410,7 @@ bool JASPListControl::checkLevelsConstraints() QStringList JASPListControl::levels() const { - return initialized() ? model()->allLevels(model()->terms()) : QStringList(); + return model() ? model()->allLevels(model()->terms()) : QStringList(); } QStringList JASPListControl::allowedColumnsIcons() const diff --git a/QMLComponents/models/listmodelinteractionassigned.cpp b/QMLComponents/models/listmodelinteractionassigned.cpp index 568c250e01..aad7bd597a 100644 --- a/QMLComponents/models/listmodelinteractionassigned.cpp +++ b/QMLComponents/models/listmodelinteractionassigned.cpp @@ -166,7 +166,7 @@ Terms ListModelInteractionAssigned::addTerms(const Terms& terms, int , const Row Terms dropped; if (availableModel()) dropped.setSortParent(availableModel()->allTerms()); - dropped.set(terms); + dropped.set(checkTermsTypes(terms)); Terms newTerms = dropped.combineTerms(JASPControl::CombinationType::CombinationCross); From d839c515f477c17bb956fda6101ac8d1a8eb3b27 Mon Sep 17 00:00:00 2001 From: boutinb Date: Thu, 21 Nov 2024 11:35:16 +0100 Subject: [PATCH 2/3] Add textFormat property to controls --- QMLComponents/components/JASP/Controls/Button.qml | 1 + QMLComponents/components/JASP/Controls/CheckBox.qml | 3 ++- QMLComponents/components/JASP/Controls/ComboBox.qml | 2 ++ QMLComponents/components/JASP/Controls/ExpanderButton.qml | 2 ++ QMLComponents/components/JASP/Controls/GroupBox.qml | 4 +++- QMLComponents/components/JASP/Controls/RadioButton.qml | 2 ++ QMLComponents/components/JASP/Controls/RadioButtonGroup.qml | 2 ++ QMLComponents/components/JASP/Controls/RectangularButton.qml | 3 +-- QMLComponents/components/JASP/Controls/TextField.qml | 3 +++ QMLComponents/components/JASP/Controls/VariablesList.qml | 3 +++ 10 files changed, 21 insertions(+), 4 deletions(-) diff --git a/QMLComponents/components/JASP/Controls/Button.qml b/QMLComponents/components/JASP/Controls/Button.qml index 49836d0aa9..f948836885 100644 --- a/QMLComponents/components/JASP/Controls/Button.qml +++ b/QMLComponents/components/JASP/Controls/Button.qml @@ -34,6 +34,7 @@ JASPControl readonly property alias control: control property alias text: control.text property alias label: control.text + property alias textFormat: control.textFormat property alias iconSource: control.iconSource readonly property alias pressed: control._pressed diff --git a/QMLComponents/components/JASP/Controls/CheckBox.qml b/QMLComponents/components/JASP/Controls/CheckBox.qml index f15ca58a9e..289cab2e6c 100644 --- a/QMLComponents/components/JASP/Controls/CheckBox.qml +++ b/QMLComponents/components/JASP/Controls/CheckBox.qml @@ -42,8 +42,8 @@ CheckBoxBase property alias font: label.font property alias fontInfo: label.fontInfo property alias label: control.text - property alias labelTextFormat: label.textFormat property alias checked: control.checked + property int textFormat: Text.AutoText property bool childrenOnSameRow: false property alias columns: childControlsArea.columns property bool enableChildrenOnChecked: true @@ -111,6 +111,7 @@ CheckBoxBase font: jaspTheme.font leftPadding: checkIndicator.width + control.spacing verticalAlignment: Text.AlignVCenter + textFormat: checkBox.textFormat } background: Rectangle diff --git a/QMLComponents/components/JASP/Controls/ComboBox.qml b/QMLComponents/components/JASP/Controls/ComboBox.qml index ba60482504..9590a14490 100644 --- a/QMLComponents/components/JASP/Controls/ComboBox.qml +++ b/QMLComponents/components/JASP/Controls/ComboBox.qml @@ -20,6 +20,7 @@ ComboBoxBase property alias value: comboBox.currentValue property alias indexDefaultValue: comboBox.currentIndex property alias fieldWidth: control.width + property int textFormat: Text.AutoText property bool showVariableTypeIcon: containsVariables property var enabledOptions: [] property bool setLabelAbove: false @@ -87,6 +88,7 @@ ComboBoxBase anchors.verticalCenter: parent.verticalCenter color: enabled ? jaspTheme.textEnabled : jaspTheme.textDisabled width: implicitWidth + textFormat: comboBox.textFormat } } diff --git a/QMLComponents/components/JASP/Controls/ExpanderButton.qml b/QMLComponents/components/JASP/Controls/ExpanderButton.qml index 3dabb58365..2587f01ea2 100644 --- a/QMLComponents/components/JASP/Controls/ExpanderButton.qml +++ b/QMLComponents/components/JASP/Controls/ExpanderButton.qml @@ -46,6 +46,7 @@ FocusScope readonly property string iconsFolder : jaspTheme.iconPath readonly property string expanderButtonIcon : "expander-arrow-up.png" property alias columns : expanderArea.columns + property int textFormat : Text.AutoText states: [ State @@ -131,6 +132,7 @@ FocusScope anchors.verticalCenter : parent.verticalCenter font : jaspTheme.font color : enabled ? jaspTheme.textEnabled : jaspTheme.textDisabled + textFormat : expanderWrapper.textFormat } } } diff --git a/QMLComponents/components/JASP/Controls/GroupBox.qml b/QMLComponents/components/JASP/Controls/GroupBox.qml index b735299fec..99a49f142c 100644 --- a/QMLComponents/components/JASP/Controls/GroupBox.qml +++ b/QMLComponents/components/JASP/Controls/GroupBox.qml @@ -39,9 +39,10 @@ GroupBoxBase property int columnSpacing: jaspTheme.columnGroupSpacing property int columns: 1 property bool indent: false - property bool alignFields: true + property bool alignFields: true property alias label: label property alias preferredWidth: contentArea.width + property int textFormat: Text.AutoText property var _allAlignableFields: [] property bool _childrenConnected: false @@ -55,6 +56,7 @@ GroupBoxBase color: enabled ? jaspTheme.textEnabled : jaspTheme.textDisabled font: jaspTheme.font visible: groupBox.title ? true : false + textFormat: groupBox.textFormat property int realHeight: visible ? implicitHeight : 0 property int realWidth: visible ? implicitWidth : 0 diff --git a/QMLComponents/components/JASP/Controls/RadioButton.qml b/QMLComponents/components/JASP/Controls/RadioButton.qml index 15179da56f..07eda15863 100644 --- a/QMLComponents/components/JASP/Controls/RadioButton.qml +++ b/QMLComponents/components/JASP/Controls/RadioButton.qml @@ -43,6 +43,7 @@ RadioButtonBase property alias label: control.text property alias checked: control.checked property alias value: radioButton.name + property int textFormat: Text.AutoText property bool childrenOnSameRow: false property alias columns: childControlsArea.columns property bool enableChildrenOnChecked: true @@ -102,6 +103,7 @@ RadioButtonBase leftPadding: radioIndicator.width + control.spacing font: jaspTheme.font color: enabled ? jaspTheme.textEnabled : jaspTheme.textDisabled + textFormat: radioButton.textFormat } background: Rectangle { color: "transparent" } diff --git a/QMLComponents/components/JASP/Controls/RadioButtonGroup.qml b/QMLComponents/components/JASP/Controls/RadioButtonGroup.qml index 988ad1df83..10b5f566c0 100644 --- a/QMLComponents/components/JASP/Controls/RadioButtonGroup.qml +++ b/QMLComponents/components/JASP/Controls/RadioButtonGroup.qml @@ -35,6 +35,7 @@ RadioButtonsGroupBase property alias columns: contentArea.columns property alias text: control.title property int leftPadding: jaspTheme.groupContentPadding + property int textFormat: Text.AutoText implicitWidth: radioButtonsOnSameRow ? contentArea.x + contentArea.implicitWidth @@ -57,6 +58,7 @@ RadioButtonsGroupBase verticalAlignment: Text.AlignVCenter font: jaspTheme.font color: enabled ? jaspTheme.textEnabled : jaspTheme.textDisabled + textFormat: control.textFormat } diff --git a/QMLComponents/components/JASP/Controls/RectangularButton.qml b/QMLComponents/components/JASP/Controls/RectangularButton.qml index df33505d13..4f6cb2a556 100644 --- a/QMLComponents/components/JASP/Controls/RectangularButton.qml +++ b/QMLComponents/components/JASP/Controls/RectangularButton.qml @@ -24,8 +24,7 @@ Rectangle { id: filterButtonRoot - - + property alias textFormat: buttonText.textFormat property string text: "" property string toolTip: "" property string textColor: "default" diff --git a/QMLComponents/components/JASP/Controls/TextField.qml b/QMLComponents/components/JASP/Controls/TextField.qml index 0f7b3e5f3f..172b8d9a8d 100644 --- a/QMLComponents/components/JASP/Controls/TextField.qml +++ b/QMLComponents/components/JASP/Controls/TextField.qml @@ -34,6 +34,7 @@ TextInputBase property alias control: control property alias text: textField.label property alias displayValue: control.text ///< In onEditingFinished this contains the "value" entered by the user + property int textFormat: Text.AutoText property var lastValidValue: defaultValue property int fieldWidth: jaspTheme.textFieldWidth property int fieldHeight: 0 @@ -151,6 +152,7 @@ TextInputBase color: enabled ? jaspTheme.textEnabled : jaspTheme.textDisabled text: textField.label width: implicitWidth + textFormat: textField.textFormat } } @@ -279,6 +281,7 @@ TextInputBase anchors.verticalCenter: parent.verticalCenter color: enabled ? jaspTheme.textEnabled : jaspTheme.textDisabled text: textField.afterLabel + textFormat: textField.textFormat } } } diff --git a/QMLComponents/components/JASP/Controls/VariablesList.qml b/QMLComponents/components/JASP/Controls/VariablesList.qml index 10dab4eab5..766a5937a2 100644 --- a/QMLComponents/components/JASP/Controls/VariablesList.qml +++ b/QMLComponents/components/JASP/Controls/VariablesList.qml @@ -43,6 +43,7 @@ VariablesListBase property alias itemRectangle : itemRectangle property alias scrollBar : scrollBar property alias itemTitle : itemTitle + property int textFormat : Text.AutoText property string rowComponentTitle : "" property string itemType : "variables" property int dropMode : JASP.DropNone @@ -146,6 +147,7 @@ VariablesListBase height : title ? jaspTheme.variablesListTitle : 0 font : jaspTheme.font color : enabled ? jaspTheme.textEnabled : jaspTheme.textDisabled + textFormat : variablesList.textFormat } Text @@ -156,6 +158,7 @@ VariablesListBase height : rowComponentTitle ? jaspTheme.variablesListTitle : 0 font : jaspTheme.font color : enabled ? jaspTheme.textEnabled : jaspTheme.textDisabled + textFormat : variablesList.textFormat } Rectangle From fa4ac2bec44cf148c28c636cd587045295156084 Mon Sep 17 00:00:00 2001 From: boutinb Date: Thu, 21 Nov 2024 14:53:32 +0100 Subject: [PATCH 3/3] Rename _lostValue by _unusedInitialValue --- QMLComponents/controls/comboboxbase.cpp | 16 ++++++++++------ QMLComponents/controls/comboboxbase.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/QMLComponents/controls/comboboxbase.cpp b/QMLComponents/controls/comboboxbase.cpp index 43aaa0f4f6..d15829c7d4 100644 --- a/QMLComponents/controls/comboboxbase.cpp +++ b/QMLComponents/controls/comboboxbase.cpp @@ -83,7 +83,11 @@ void ComboBoxBase::bindTo(const Json::Value& value) } } else if (!selectedValue.empty()) - _lostValue = selectedValue; + // The control is bound with a value, but its model is empty. + // Probably the values are set with a direct reference of a property of another control, like varList.levels, and this control is not yet initialized. + // (as the combobox has no direct reference to the varList self, it cannot add a dependency in _depends). + // So keep this value, and use it if the model is reset during the initialization of the form. + _unusedInitialValue = selectedValue; _setCurrentProperties(index); @@ -155,7 +159,7 @@ void ComboBoxBase::setUp() if (form()) { connect(form(), &AnalysisForm::languageChanged, [this] () { _model->resetTermsFromSources(); } ); - connect(form(), &AnalysisForm::analysisChanged, [this] () { _lostValue = ""; }); + connect(form(), &AnalysisForm::analysisChanged, [this] () { _unusedInitialValue = ""; }); } } @@ -184,14 +188,14 @@ void ComboBoxBase::termsChangedHandler() { auto itr = std::find(values.begin(), values.end(), fq(_currentValue)); - if (!_lostValue.empty()) + if (!_unusedInitialValue.empty()) { - auto lostValueItr = std::find(values.begin(), values.end(), _lostValue); + auto lostValueItr = std::find(values.begin(), values.end(), _unusedInitialValue); if (lostValueItr != values.end()) { itr = lostValueItr; - _orgValue = _lostValue; - _lostValue = ""; + _orgValue = _unusedInitialValue; + _unusedInitialValue = ""; } } diff --git a/QMLComponents/controls/comboboxbase.h b/QMLComponents/controls/comboboxbase.h index 02d32b54ce..f2923ce932 100644 --- a/QMLComponents/controls/comboboxbase.h +++ b/QMLComponents/controls/comboboxbase.h @@ -92,7 +92,7 @@ protected slots: _currentColumnType, _currentColumnRealType, _currentColumnTypeIcon; - std::string _lostValue; + std::string _unusedInitialValue; int _currentIndex = -1; bool _fixedWidth = false;