summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qpropertyprivate.h
Commit message (Collapse)AuthorAgeFilesLines
* QProperty: Mark metaType as unused in else branch of createFor()Ulf Hermann2020-11-071-0/+1
| | | | | | | | | The metaType is only used in the constexpr if branch where the callable is not std::is_invocable_v. Therefore, we need to mark it as unused in order to avoid compile errors in code that exercises the other branch. Change-Id: I46e855b0f4b0a088f15ff41d4929fe010531b97e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove std::function from QProperty interfaceFabian Kosmale2020-11-031-3/+135
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | std::function as a type is rather unfortunate for us, as its SSO buffer makes it rather large, and we can ensure that the function is never empty. Considering that we do need to allocate memory for QPropertyBindingPrivate anyway, we can get rid of the SSO buffer and instead coalesce the allocations (similar to how std::make_shared works). The memory looks then like [--QPropertyBindingPrivate--][Functor] and QPropertyBindingPrivate can get a pointer to the functor via reinterpret_cast<std::byte>(this)+sizeof(QPropertyBindingPrivate). To actually do anything with the functor, we do however need a "vtable" which describes how we can call, destroy and move the functor. This is done by creating a constexpr struct of function pointers, and storing a pointer to it in QPropertyBindingPrivate. As a consequence of those changes, we cannot use QESDP anymore, as we now have to carefully deallocate the buffer we used for both the QPropertyBindingPrivate and the functor. We introduce a custom refcounting pointer for that. While we're at it, we make the refcount non-atomic, as bindings do not work across threads to begin with. Moreover, we can now make the class non-virtual, as that was only needed to hack around limitations of QESDP in the context of exported symbols. Change-Id: Idc5507e4c120e28df5bd5aea717fe69f15e540dc Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Whitespace cleanup in corelib/kernelAllan Sandfeld Jensen2020-10-241-2/+2
| | | | | Change-Id: If061ef0af5ced4384e20a82afcea3712fa7e45d7 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QProperty: avoid needless std::function copyingFabian Kosmale2020-10-121-1/+1
| | | | | Change-Id: Iea6280b12e7146a9ac92f071a4c21b373e9d3ab0 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QProperty: make a few helpers constexprFabian Kosmale2020-10-121-1/+1
| | | | | Change-Id: I1f3b2223530c311a7b40fd36c8162e32adbd9569 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Disable moving of QPropertyLars Knoll2020-09-291-3/+1
| | | | | | | | | The semantics are not very intuitive, and it opens a can of worms with regards to what should happen with observers that observe that property. Change-Id: I6fb00b7693904b968224cc87d098bbd0ea776ba3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add QObjectCompatPropertyLars Knoll2020-09-021-28/+3
| | | | | | | | | | | | Add a compatibility property class that makes porting to the new property system as simple as possible. Binding evaluation for those compat properties is eager, as we do not control possible side effects of the code in the existing setters. Change-Id: Ic56347abb49e40631ec73e88c6d40d4bdb05ca29 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Pass a pointer to the property data into the method evaluating a bindingLars Knoll2020-09-021-3/+2
| | | | | | | | | Make it possible to evaluate the binding but write the result into a different memory location. This will help support compat properties, where the setter does a lot of additional work. Change-Id: Ib60220eb629e3dcb5c0d7004b693e92290dfabe5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add support for bindable properties to QObjectLars Knoll2020-09-021-0/+9
| | | | | | | | | | | | | | | | Add Q_OBJECT_BINDABLE_PROPERTY() macro that can be used to define a bindable property inside QObject. The macro and the class behind it creates storage for a property that is bindable inside a QObject or QObjectPrivate. The property only uses as much space as the data contained, ie. it has no storage overhead, as long as no bindings are being used. Bindings are being stored and looked up in the QBindingStorage associated with the owning object. Change-Id: I1dadd7bddbad6fbf10cfa791d6461574b9db82dd Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Cleanup QBindingPrivateLars Knoll2020-09-021-3/+3
| | | | | | | | | | | | Simplify the data structure. We only need one pointer for either the static callback or a bindingWrapper, so don't share it with the dependency observer array. Also ensure we reset the propertyDataPtr and clear the observers when the binding gets removed from a property. Change-Id: I4c1e7ec7823c3ef12c63d6f758b757e7bac60cae Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Introduce a common base class for all QProperty typesLars Knoll2020-09-021-9/+16
| | | | | | | | | | | | | | | | | | Add an empty QUntypedPropertyData class. This allows making a couple of places where the system is currently using a void * more type safe. Also add a QPropertyData<T> as an intermediate class between QUntypedPropertyData and QProperty. This class will get used in a future commit to simplify storing property data separately from the possible binding data. Also simplify the static observer handling a bit by always passing it a pointer to the QUntypedPropertyData instead of some other void * that could point to anything. Change-Id: I1f8144ea717815b1bc6f034d1ac883c13af5aaf8 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Cleanups: Rename some classesLars Knoll2020-09-021-11/+11
| | | | | | | | | | Rename QPropertyBase to QPropertyBindingData, as it contains the data related to bindings. The new name fits better, as the data can now also live somewhere else than the data strored in the property. Change-Id: I489efb86ad2e0bad2740c9d1aa74506fe103d343 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Get rid of QPropertyValueStorageLars Knoll2020-09-021-38/+0
| | | | | | | This simplifies and cleans up the code. Change-Id: Ic811925d644466ff298f1109efcda0537e52ce0d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove the special handling of QProperty<bool>Lars Knoll2020-09-021-22/+0
| | | | | | | | | Since we will be storing property data differently in most cases, having this special case would create too many additional complications. Change-Id: I27042b0730559bb375d8e3c07324398403a9885d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add operator-> and operator*() to QPropertyFabian Kosmale2020-09-021-1/+1
| | | | | | | | | | | | | | Enable the arrow operator for all types that could have members, so that one can e.g. write myStringProperty->size() instead of having to use the less convenient myStringProperty.value().size(). Also cleaned up the rvalue ref overloads to be disabled for basic types. For those we now also return by value, for more complex types we return a const reference. Change-Id: If6a75898dc0a097f57052488f0af0cd7166b3393 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add const to some methodsLars Knoll2020-08-281-3/+3
| | | | | Change-Id: I60e93e0c9b57468ef4188bdb60a32fb9ac9046e1 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
* Pass QMetaType by valueLars Knoll2020-08-241-4/+4
| | | | | | | | Now that QMetaType is not refcounted anymore, we can and should pass it by value. Change-Id: I848db65070713762f548ca949097c27783aacad4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix a valgrind warning about accessing uninitialized memoryLars Knoll2020-08-171-1/+1
| | | | | | | | Amends change bbfecdee1e2952c401e9c5ac6e16adc2428fb2dc. Change-Id: Iba4ad5101b46f07ce0b3e3397d723e1a681bcbc5 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Don't test for equality if types can't be comparedVolker Hilsheimer2020-07-151-4/+8
| | | | | | | | | For types that don't have an operator==(), always trigger the binding and the changed notification. Task-number: QTBUG-85578 Change-Id: I41374f6d13c88106f4de83864e82172f3a248150 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Move all the QProperty related code into one compilation unitLars Knoll2020-07-101-0/+2
| | | | | | | | | | | | | And mark some methods as inline. Performance is critical for our new property system. Compiling it in one unit makes it possible for the compiler to do a much better job at inlining and generating optimized code. Improves performance of binding evaluations by another 20%. Change-Id: I5a2aa93c74d2b68418b0a9d2e34d8199bb71e3ad Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Significantly improve performance of binding evaluationLars Knoll2020-07-101-2/+42
| | | | | | | | | | | | | | Avoid any QVariant or type dependent code in the cpp files. Instead, let the binding wrapper determine if the value has changed and return true/false accordingly. This required also some reworking of the guard mechanism for notified properties, where the guard function wrapper now calls first the binding evaluation function and then passes the result to the guard. Change-Id: I350d07a508ccc0c5db7054a0efa4f270b6a78ec3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QNotifiedProperty: Add guard callbackFabian Kosmale2020-06-251-1/+2
| | | | | | | | | | | | | | | A guard callback is a predicate which takes the new value set by setValue or computed as the result of a binding expression. If it returns false, the value is discarded and the old value is kept. Note that due to lazyness, when setting a binding, we still notify everyone as the binding is only evaluated on demand, and the guard can thus only run when someone actually queries the value. Note further that a guard is allowed to modify the value that is passed to it (e.g. to clamp it to a certain range). Task-number: QTBUG-85032 Change-Id: I3551e4357fe5780fb75da80bf8be208ec152dc2a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QNotifiedProperty: pass old value to callback if requestedFabian Kosmale2020-06-251-1/+1
| | | | | | | | | Check at compile time whether the static callback takes an argument (which has to be of the same time as the type of the property). If so, retrieve the old value and pass it to the callback. Change-Id: Ib1c4c9e05b826b6be492b03f66fa72ad015963ee Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Implement support for QProperty<T> with a static observerSimon Hausmann2020-05-281-1/+3
| | | | | | | | | | | | | | | | | | | | | | | 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>
* 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-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | | | | 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-52/+18
| | | | | | | | | | 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>
* Initial import of the Qt C++ property binding systemSimon Hausmann2020-03-161-0/+249
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>