Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-84909 Use bindable QProperty in Qt QML classes
  3. QTBUG-85032

Investigate adding a guard callback to QNotifiedProperty

    XMLWordPrintable

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).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            fabiankosmale Fabian Kosmale
            fabiankosmale Fabian Kosmale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes