Details
-
Technical task
-
Resolution: Done
-
P2: Important
-
None
-
None
-
None
Description
In our current property setters, there's a common pattern of validating and potentially modifying the new value. For instance, QQuickProperty::setOpacity uses qBound to force the opacity to be in the interval [0,1] and QtQuick::setParentItem rejects the new parent if it's already part of the current item's subtree.
This is currently not possible to do with QNotifiedProperty without setting the property's value back to the old value, which can have side-effects and is thus not a proper solution. If we want to support such properties with QNotifiedProperty, a potential solution might be adding an additional template parameter for a guard function with signature bool(Class::Callback)(T& /*newValue/).
Calling that one in newValue would allow rejecting new values (if the guard returns false), and also to modify the value (possible because the parameter is passed in by non-const reference).