Fix nested container field validation to respect required status
Previously, several field types in fromJsonObject() had broken
validation logic that either ignored the required status or used
early return instead of break, causing the field's invalid/cleared
state to not be visible to other fields in the same object.
The fixes cover four related cases:
1. Nested map fields (Map<K, Map<K2, V>>):
When an inner value cannot be converted to QVariantMap, the field
is now cleared and m_fieldIsValid = !required (true if optional).
Previously it was unconditionally set to false.
2. Nested array fields (Array<Array<T>>) and arrays of maps
(Array<Map<K, V>>):
A type-check (isArray / isObject) is now performed before
processing each element. On failure the field is cleared and
validation flags are set consistently. Previously the isArray
inner-container branch was the only one handled, and isMap inner
items were not type-checked at all.
3. Free-form object fields:
initializeModel() now initialises m_fieldIsValid = !required
instead of false, matching the behavior of other optional fields.
4. Early-exit logic:
All return statements inside per-element loops were changed to
break. Using return caused the enclosing fromJsonObject() to exit
immediately, skipping the validation of all subsequent fields in
the same model.
The net result is consistent behavior across all container field
types: optional fields with invalid data are dropped but remain
valid; required fields with invalid data are dropped and become
invalid. Other independently-valid fields in the same object are
no longer affected.
- Add test coverage via new Animal/Tier/e/Fauna/etc schemas with
nested map and nested array properties.
Task-number: QTBUG-145568
Pick-to: 6.11
Change-Id: I9b3cc5ba40f07a11ab53ee565df88a6032915082
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>