@@ -47,19 +47,17 @@ void RowControls::init(int row, const Term& key, bool isNew)
47
47
context->setContextProperty (" rowIndex" , row);
48
48
context->setContextProperty (" rowValue" , key.asQString ());
49
49
50
- _rowObject = qobject_cast<QQuickItem*>(_rowComponent->create (context));
50
+ _rowObject = qobject_cast<QQuickItem*>(_rowComponent->create (context)); // The _rowJASPControlMap will be filled during this step
51
51
_rowObject->setParent (_parentModel);
52
52
_context = context;
53
53
54
- if (_rowObject) _setupControls ();
54
+ if (_rowObject) _initializeControls ();
55
55
else Log::log () << " Could not create control in ListView " << listView->name () << std::endl;
56
56
}
57
57
58
- void RowControls::_setupControls (bool reuseBoundValue )
58
+ void RowControls::_initializeControls (bool useInitialValue )
59
59
{
60
- // The controls (when created or reused) may need to be bound with some values:
61
- // either with the initial values (in _rowValues) or new values (by calling createJson)
62
- // And if a control depends on a source, its values must be refreshed by this source.
60
+ // The controls (when created or reused) need to be initialized
63
61
QList<JASPControl*> controls = _rowJASPControlMap.values ();
64
62
AnalysisForm* form = _parentModel->listView ()->form ();
65
63
@@ -71,38 +69,22 @@ void RowControls::_setupControls(bool reuseBoundValue)
71
69
72
70
for (JASPControl* control : controls)
73
71
{
74
- bool hasInitialValues = _initialValues.contains (control->name ());
75
- BoundControl* boundItem = control->boundControl ();
72
+ JASPListControl* listView = dynamic_cast <JASPListControl*>(control);
73
+ if (listView)
74
+ for (SourceItem* source : listView->sourceItems ())
75
+ source->connectModels (); // If the source was disconnected, reconnect it.
76
76
77
- if (boundItem)
78
- {
79
- // When a control is created before its parent, it has no bound value yet.
80
- // In this case we need to create a bound volue.
81
- bool hasNoBoundValue = boundItem->boundValue ().isNull ();
82
- if (!reuseBoundValue || hasNoBoundValue)
83
- {
84
- boundItem->setDefaultBoundValue (boundItem->createJson ());
85
- boundItem->bindTo (hasInitialValues ? (_initialValues[control->name ()]) : boundItem->createJson ());
86
- // bindTo does not emit the signal that the bound value is changed.
87
- // But (at least) if it did not have any value, it should emit this signal.
88
- if (hasNoBoundValue) emit control->boundValueChanged (control);
89
- }
90
- }
91
-
92
- if (!boundItem || !hasInitialValues || reuseBoundValue)
77
+ Json::Value optionValue = Json::nullValue;
78
+ BoundControl* boundItem = control->boundControl ();
79
+ if (boundItem && _initialValues.contains (control->name ()))
93
80
{
94
- JASPListControl* listView = dynamic_cast <JASPListControl*>(control);
95
- // If a ListView depends on a source, it has to be initialized by this source
96
- // For this just call the sourceTermsChanged handler.
97
- if (listView && listView->hasSource ())
98
- {
99
- for (SourceItem* source : listView->sourceItems ())
100
- source->connectModels (); // If the source was disconnected, reconnect it.
101
- listView->model ()->sourceTermsReset ();
102
- }
81
+ // When a control is created before its parent, it has no value yet.
82
+ // In this case use its initial value.
83
+ if (useInitialValue || boundItem->boundValue ().isNull ())
84
+ optionValue = _initialValues[control->name ()];
103
85
}
104
86
105
- control->setInitialized ();
87
+ control->setInitialized (optionValue );
106
88
}
107
89
108
90
if (form)
@@ -116,7 +98,7 @@ void RowControls::setContext(int row, const QString &key)
116
98
_context->setContextProperty (" rowValue" , key);
117
99
_context->setContextProperty (" isNew" , false );
118
100
119
- _setupControls ( true );
101
+ _initializeControls ( false );
120
102
}
121
103
122
104
bool RowControls::addJASPControl (JASPControl *control)
0 commit comments