Module qtjambi
Package io.qt.core

Class QProperty<T>

All Implemented Interfaces:
QtObjectInterface

public final class QProperty<T> extends QPropertyData<T>

Java wrapper for Qt class QProperty

The QProperty class enables automatic property bindings.

Example:

QIntProperty red = new QIntProperty(255);
QIntProperty green = new QIntProperty(0);
QIntProperty blue = new QIntProperty(0);
QIntProperty alpha = new QIntProperty(255);
QProperty<QColor> color = new QProperty<>(QColor.class);
color.setBinding(()->new QColor(red.value(), green.value(), blue.value(), alpha.value()));
color.value(); // = red
red.setValue(0);
green.setValue(255);
color.value(); // = green

For primitive-typed implementations see:

  • Constructor Details

    • QProperty

      public QProperty(T initialValue, Class<T> type, QMetaType ... instantiations)
      Constructs a property with the given type and initialValue.
      Parameters:
      initialValue -
      type - class type
      instantiations - optional instantiations for container classes like QList and QMap
    • QProperty

      public QProperty(Class<T> type, QMetaType ... instantiations)
      Constructs a property with the given type.
      Parameters:
      type - class type
      instantiations - optional instantiations for container classes like QList and QMap
    • QProperty

      public QProperty(T initialValue)
      Constructs a property with the provided initialValue. The property type is extracted from initialValue.
      Parameters:
      initialValue - initial value must not be null
    • QProperty

      public QProperty()
      Constructs a QVariant-typed property.
    • QProperty

      public QProperty(QPropertyBinding<T> binding)
      Constructs a property with the provided binding. The property type corresponds to the type of binding.
      Parameters:
      binding - must not be null
    • QProperty

      public QProperty(QtUtilities.Supplier<T> functor)

      Constructs a property bound to the provided functor.

      The property type corresponds to the return type of the functor's Supplier.get().

      Parameters:
      functor -
    • QProperty

      public QProperty(QtUtilities.Supplier<T> functor, Class<T> type, QMetaType ... instantiations)

      Constructs a property bound to the provided functor.

      The property type corresponds to the return type of the functor's Supplier.get().

      Parameters:
      functor -
      type - class type
      instantiations - optional instantiations for container classes like QList and QMap
  • Method Details

    • value

      @QtUninvokable public T value()
      Returns the value of the property. This may evaluate a binding expression that is tied to this property, before returning the value.
      Returns:
      value
    • setValue

      @QtUninvokable public void setValue(T newValue)

      Assigns newValue to this property and removes the property's associated binding, if present.

      Parameters:
      newValue -
    • setBinding

      @QtUninvokable public QPropertyBinding<T> setBinding(QPropertyBinding<T> newBinding)

      Associates the value of this property with the provided newBinding expression and returns the previously associated binding.

      The binding's value type (QUntypedPropertyBinding.valueMetaType()) has to be equals to the property's value type T, otherwise the property remains unchanged.

      The first time the property value is read, the binding is evaluated. Whenever a dependency of the binding changes, the binding will be re-evaluated the next time the value of this property is read.

      Parameters:
      newBinding -
      Returns:
      oldBinding
    • setBinding

      @QtUninvokable public boolean setBinding(QUntypedPropertyBinding newBinding)

      Associates the value of this property with the provided newBinding expression.

      The binding's value type (QUntypedPropertyBinding.valueMetaType()) has to be equals to the property's value type T, otherwise the property remains unchanged and the method returns false.

      The first time the property value is read, the binding is evaluated. Whenever a dependency of the binding changes, the binding will be re-evaluated the next time the value of this property is read.

      Returns true if the type of this property is the same as the type the binding function returns; false otherwise.

      Parameters:
      newBinding -
      Returns:
      true if types match, false otherwise.
    • setBinding

      @QtUninvokable public QPropertyBinding<T> setBinding(QtUtilities.Supplier<T> functor)

      Associates the value of this property with the provided functor and returns the previously associated binding.

      The first time the property value is read, the binding is evaluated by invoking Supplier.get() of functor. Whenever a dependency of the binding changes, the binding will be re-evaluated the next time the value of this property is read.

      Parameters:
      functor -
      Returns:
      oldBinding
    • hasBinding

      @QtUninvokable public boolean hasBinding()
      Checks if the property has a binding.
      Returns:
      true if the property has a binding, false otherwise.
    • binding

      @QtUninvokable public QPropertyBinding<T> binding()
      Returns the binding expression that is associated with this property. A default constructed QPropertyBinding<T> will be returned if no such association exists.
      Returns:
      binding
    • takeBinding

      @QtUninvokable public QPropertyBinding<T> takeBinding()

      Disassociates the binding expression from this property and returns it.

      After calling this function, the value of the property will only change if you assign a new value to it, or when a new binding is set.

      Returns:
      the removed binding
    • onValueChanged

      @QtUninvokable public QPropertyChangeHandler onValueChanged(Runnable f)

      Registers the given functor f as a callback that shall be called whenever the value of the property changes.

      The returned property change handler object keeps track of the registration. As long as the change handler is alive i.e. as long as a reference to the QPropertyChangeHandler instance exists, the callback remains installed. When the garbage collection deletes the instance, the callback is de-registered.

      Parameters:
      f -
      Returns:
      property change handler
      See Also:
    • subscribe

      Subscribes the given functor f as a callback that is called immediately and whenever the value of the property changes in the future.
      Parameters:
      f -
      Returns:
      property change handler
      See Also:
    • addNotifier

      @QtUninvokable public QPropertyNotifier addNotifier(Runnable f)

      Registers the given functor f as a callback that shall be called whenever the value of the bindable changes.

      The returned property notifier object keeps track of the registration. As long as the notifier is alive i.e. as long as a reference to the QPropertyNotifier instance exists, the callback remains installed. When the garbage collection deletes the instance, the callback is de-registered.

      Parameters:
      f -
      Returns:
      property notifier
      See Also:
    • getValueBypassingBindings

      @QtUninvokable public final T getValueBypassingBindings()

      Returns the data stored in this property.

      Note: As this will bypass any binding evaluation it might return an outdated value if a binding is set on this property. Using this method will also not register the property access with any currently executing binding.

      Specified by:
      getValueBypassingBindings in class QPropertyData<T>
      Returns:
      value bypassing bindings
    • setValueBypassingBindings

      @QtUninvokable public final boolean setValueBypassingBindings(T val)

      Sets the data value stored in this property to val.

      Note: Using this method will bypass any potential binding registered for this property.

      Specified by:
      setValueBypassingBindings in class QPropertyData<T>
      Parameters:
      val -