summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qproperty.h
Commit message (Collapse)AuthorAgeFilesLines
* Fix and compactify QNotifiedPropertyUlf Hermann2020-06-031-0/+32
| | | | | | | | | | | | The static observer can live in a union with the inline observers. We only need to take care of calling the ctors and dtors manually then. In order for any observers to be called in the presence of a static observer, the static observer has to be called after the other observers. Change-Id: I2f56fa64f3fe6fcd7f06cc403929362da7d86f65 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Implement support for QProperty<T> with a static observerSimon Hausmann2020-05-281-2/+144
| | | | | | | | | | | | | | | | | | | | | | | A common pattern in Qt Quick will be QProperty members that are connected to a callback that needs to perform something when the value changes, for example emitting a compatibility signal or marking scene graph node data dirty. To make such a pattern more efficient, a new QNotifiedProperty type is introduced that offers the same API as QProperty<T>, with two changes: (1) The template instantiation not only takes the property type as parameter but also a callback pointer-to-member. (2) Since that member itself cannot be called without an instance and to avoid storing an instance pointer permanently, the API for setBinding and setValue are adjusted to also take the instance pointer. For the former it gets stored in the binding, for the latter it is used to invoke the callback after setting the new value. Change-Id: I85cc1d1d1c0472164c4ae87808cfdc0d0b1475e1 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add a QPropertyAliasUlf Hermann2020-05-271-7/+152
| | | | | | | | | | | | A property alias is the equivalent of the "alias" keyword in QML. It provides the same API as QProperty, but redirects any access to the QProperty it was initialized with. When the original property is destroyed the binding becomes invalid and ignores any further acccess. Task-number: QTBUG-84370 Change-Id: I0aef8d50e73a2aa9e7703d51194d4c5480573578 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QProperty: Support multiple observersUlf Hermann2020-05-271-2/+2
| | | | | | | | | Previously, only the first observer would get notified. Also, make sure that the notifiers are always retained when switching between bindings and values. Change-Id: I9c25c0f2e288dac3a335b68e618f7ddeb44be25a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix crash when using QProperty<T>::setBinding(Functor ...)Simon Hausmann2020-04-301-3/+4
| | | | | | | | We must move the functor properly into the binding object, otherwise we end up with stale pointers as pointed out by ASAN. Change-Id: Icd84f4c113dd48e1e3e2d744abac0902cdf9339e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Minor cleanup for QProperty constructorSimon Hausmann2020-04-301-10/+3
| | | | | | | Declare it inline Change-Id: If8fe72a1f8e8e8af387d9bc3a2f731d61eda02cd Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Simplify signature of untyped property bindingsSimon Hausmann2020-04-171-8/+4
| | | | | | | | | Instead of requiring the implementation to do the compare dance, let's do this in the library. This reduces the amount of duplicated code slightly and makes it easier to generate binding code from qml files. Change-Id: Ia3b16cf9769e74d076b669efe4119ab84af3cdf0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Make it possible to take bindings from properties without private headersSimon Hausmann2020-04-171-1/+1
| | | | | | | | | | | Passing the QExplicitlySharedDataPointer by reference may lead compilers to wanting to have visibility to the destructor of the contained type (QPropertyBindingPrivate), which is not public. Fortunately QExplicitlySharedDataPointer is safe to use with raw pointers and those can be safely forward declared. Change-Id: I131ab6363eaee10b6dce196fb2c769e09a5c9557 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QProperty: Add support for member function change handlersSimon Hausmann2020-04-061-5/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | When a class has multiple QProperty members to implement functionality, it is common to have functions in the class that react to changes. For example to emit a compatibility signal, in case of Qt Quick to mark the scene graph as dirty, etc. etc. To faciliate this use-case, this patch adds an internal QPropertyMemberChangeHandler template that allows connecting a QProperty field to a member function callback. At the moment that callback is still 3 * sizeof(pointer). This could in theory be reduced to 2 by eliminating the back-pointer (prev) as the observer lives as long as the property. That however belongs into maybe a future patch. In order to get a pointer back to the surrounding object that holds the QProperty as well as provides the callback function, the property system was changed to pass through the address of the QProperty member at run-time, and at compile time the delta from the QProperty member to the beginning of the surrounding class is calculated. Through subtraction we obtain the pointer to the owning object. Change-Id: Ia2976357053f474ff44d0d6f60527c3b8e1f613a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Make QPropertyBindingPrivate accessible to QtQmlSimon Hausmann2020-03-271-7/+7
| | | | | | | | | | | | | | | | | | QtQml needs the private just for one detail which nobody else should need it for: Tracking additional dependencies and marking the binding as dirty. Exporting the private requires hiding some variables and providing accessors, to compile with MSVC - including the removal of QVarLengthArray usage. Upside: The binding structure shrinks by 8 bytes and the encapsulation makes it a little easier to change things without breaking declarative, ... in the unlikely event ;-) Also remove setDirty() from the public API as it's not needed by QtQml and using it is dangerous, because it means that there's a risk of somebody keeping a reference (count) to the untyped binding from within the binding closure, which introduces a memory leak. Change-Id: I43bd56f4bdf218efb54fa23e2d627ad3acfafeb5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use QTaggedPointer in QPropertyObserverSimon Hausmann2020-03-191-2/+12
| | | | | | | | | | This replaces the private tagged pointer and the use of enums for the tag makes the observer handling code more readable. The pointer-to-tagged-pointer class remains in qpropertyprivate.h due to its exoticness. Change-Id: Icc88799136c6839426d994b42368526463265e66 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add support for explicitly marking a property as dirtySimon Hausmann2020-03-191-0/+2
| | | | | | | | When a binding is backed by old-style property captures, then having this API is needed for Qml. Change-Id: Icf51efe057eaf845969ed2cda52d082dedde677e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Enable generic property bindings to QProperty<T>Simon Hausmann2020-03-191-6/+23
| | | | | | | | | | A generic binding allows implementing the binding function in a way that enables the QML engine to run binding scripts and convert the V4::Value into a QVariant and then assign the value to the property with the help of QMetaType::construct. Change-Id: Id4807be92eee7e3501908e6c5e4c861cfcb7772a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Property binding system: Fix developer build with MSVC 2019 (16.4.1)Friedemann Kleint2020-03-171-2/+2
| | | | | | | | | | | | | | | | | | | - Fix wrong forward declaration - De-inline constructor of QUntypedPropertyBinding(), fixing: qtbase\include/src/corelib/tools/qshareddata.h(184): error C2027: use of undefined type 'QPropertyBindingPrivate' qtbase\include/src/corelib/kernel/qpropertyprivate.h(60): note: see declaration of 'QPropertyBindingPrivate' qtbase\include/src/corelib/tools/qshareddata.h(184): note: while compiling class template member function 'QExplicitlySharedDataPointer<QPropertyBindingPrivate>::~QExplicitlySharedDataPointer(void)' qtbase\src\corelib\kernel\qproperty.h(143): note: see reference to function template instantiation 'QExplicitlySharedDataPointer<QPropertyBindingPrivate>::~QExplicitlySharedDataPointer(void)' being compiled qtbase\src\corelib\kernel\qproperty.h(142): note: see reference to class template instantiation 'QExplicitlySharedDataPointer<QPropertyBindingPrivate>' being compiled qtbase\include\/src/corelib/tools/qshareddata.h(184): warning C4150: deletion of pointer to incomplete type 'QPropertyBindingPrivate'; no destructor called qtbase\include\/src/corelib/kernel/qpropertyprivate.h(60): note: see declaration of 'QPropertyBindingPrivate' Amends 9f9049b486a47aef0c7e2e3852b20aa4ffdce748. Change-Id: Idd613e2487d5ab7f8ead74747acd976d5d210c28 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Initial import of the Qt C++ property binding systemSimon Hausmann2020-03-161-0/+451
This implements the core value based property binding system with automatic dependency tracking. More features are to be added later, and the documentation will need further improvements as well. Change-Id: I77ec9163ba4dace6c4451f5933962ebe1b3b4b14 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>