summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qpropertyprivate.h
Commit message (Collapse)AuthorAgeFilesLines
* QProperty: Use RefCounted as intendedUlf Hermann2024-03-191-3/+7
| | | | | | | | You're not supposed to mess with the refcount directly. That's what the addRef() and deref() methods are for. Change-Id: I5cae946cef7ac72dd99b247ade95590d142c269e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix usage of std::enable_if_t to SFINAE out QProperty APIsVolker Hilsheimer2024-02-031-8/+5
| | | | | | | | | | Declare an IfUntypedPropertyData alias and use that consistently. Amends 311f8896322bcd39d33369c8311a8c89ccdad449. Pick-to: 6.7 Change-Id: If36ef8e2f9ce25e0ffe7b4b448c31ea5866acfc3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QProperty: clean up unnecessary sentinel classPo-Hao Su2023-12-091-1/+6
| | | | | | | | | | Instead of introducing the nested class InheritsQUntypedPropertyData as a sentinel class for inheritance check, we can use BinaryTypeTrait to handle the check. By doing this, we no longer need to maintain the nested class. Change-Id: Ie3aae976015d5fae6b6d072cad6ee52cd30b769d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix proxy-data handlingFabian Kosmale2023-02-071-1/+6
| | | | | | | | | | | | | | | This addresses two different issues: - Firstly, we were casting the resolved binding data pointer to QPropertyProxyBindingData, instead of the d_ptr of QPropertyBindingData. Fix this by introducing a helper function, and consistently using it to access the proxy data. - Secondly, we were not resetting the originalBindingData when the pointed to object was destoyed. Fix that, too. Pick-to: 6.5 6.4 6.2 Task-number: QTBUG-110899 Change-Id: I7691c9df5cc26e761f6b0e5f16d152f7f2183208 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Long live Q_UNREACHABLE_RETURN()!Marc Mutz2022-10-151-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a combination of Q_UNREACHABLE() with a return statement. ATM, the return statement is unconditionally included. If we notice that some compilers warn about return after __builtin_unreachable(), then we can map Q_UNREACHABLE_RETURN(...) to Q_UNREACHABLE() without having to touch all the code that uses explicit Q_UNREACHABLE() + return. The fact that Boost has BOOST_UNREACHABLE_RETURN() indicates that there are compilers that complain about a lack of return after Q_UNREACHABLE (we know that MSVC, ICC, and GHS are among them), as well as compilers that complained about a return being present (Coverity). Take this opportunity to properly adapt to Coverity, by leaving out the return statement on this compiler. Apply the macro around the code base, using a clang-tidy transformer rule: const std::string unr = "unr", val = "val", ret = "ret"; auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(", ifBound(val, cat(node(val)), cat("")), ")"); auto ignoringSwitchCases = [](auto stmt) { return anyOf(stmt, switchCase(subStmt(stmt))); }; makeRule( stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)), nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))), {changeTo(node(unr), cat(makeUnreachableReturn, ";")), // TODO: why is the ; lost w/o this? changeTo(node(ret), cat(""))}, cat("use ", makeUnreachableReturn)) ); where nextStmt() is copied from some upstream clang-tidy check's private implementation and subStmt() is a private matcher that gives access to SwitchCase's SubStmt. A.k.a. qt-use-unreachable-return. There were some false positives, suppressed them with NOLINTNEXTLINE. They're not really false positiives, it's just that Clang sees the world in one way and if conditonal compilation (#if) differs for other compilers, Clang doesn't know better. This is an artifact of matching two consecutive statements. I haven't figured out how to remove the empty line left by the deletion of the return statement, if it, indeed, was on a separate line, so post-processed the patch to remove all the lines matching ^\+ *$ from the diff: git commit -am meep git reset --hard HEAD^ git diff HEAD..HEAD@{1} | sed '/^\+ *$/d' | recountdiff - | patch -p1 [ChangeLog][QtCore][QtAssert] Added Q_UNREACHABLE_RETURN() macro. Change-Id: I9782939f16091c964f25b7826e1c0dbd13a71305 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace qExchange calls with std::exchangeFabian Kosmale2022-09-281-1/+1
| | | | | | | | | | | | | | | | | | | | | qExchange is one of the few remaining functionalities that have not been moved out of qglobal. Given that std::exchange exists in the standard, we can simply move to it everywhere... ...if it weren't for the fact that std::exchange is only constexpr in C++20, and only has its noexceptness specified in (most likely) C++23. Still, we want to move to the existing std functionality where possible, to allow the removal of qglobal includes in lieu of something more fine-grained in the future. So leave any constexpr calls[1] alone for now (and observe that none of our current usages cares about the conditional noexceptness), but replace everything else. [1] QScopedValueRollback' ctor and QExplicitlySharedDataPointerV2::take Task-number: QTBUG-99313 Change-Id: I599cb9846cf319c7ffd3457130938347a75aad25 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QProperty: Notify observers even when dependency is goneFabian Kosmale2022-08-011-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem description: -------------------- Assume we have two properties, P1 and P2. Assume further that we assign a binding to P2, so that it depends on P1. Let the binding additionally capture some (non-QProperty) boolean, and only create the dependency to P1 if the boolean is true. The state afterwards is P1:[p1vaue|firstObserver] | | v ---[p2binding] / P2:[p2value|binding] If the boolean is set to false, and P1 changes its value, we still correctly re-evaluate the binding and update P2's value. However, during binding evaluation we will notice that there is no further dependency from P2 on P1, and remove its observer. The state afterwards is P1:[p1vaue|firstObserver=nullptr] ---[p2binding] / P2:[p2value|binding] Then, during the notify phase, we traverse the observer's again, starting from P1's firstObserver. Given that it is nullptr now, we never reach P2's binding, and thus won't send a notification from it. Fix: ---- We store a list of all visited binding-observers (in a QVarLengthArray, to avoid allocations as long as possible). After the binding evaluation phase, we then use that list to send notifications from every binding that we visited. As we already have a list of all bindings, we no longer need to recurse on binding-observes during the notification process; instead, we only need to deal with static callbacks and ChangeHandlers. The pre-existing notification logic is still kept for the grouped update case, where we already have a list of all delayed properties, and should therefore not encounter the same issue. Unifying its codepath with the existing logic is left as an exercise for a later patch. Fixes: QTBUG-105204 Task-number: QTBUG-104982 Pick-to: 6.4 6.3 6.2 Change-Id: I2951f7d9597f4da0b8560a64dfb834f7ad86e757 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QProperty: Work around constexpr issues on MSVCFabian Kosmale2022-01-231-3/+9
| | | | | | | | | | | | | | | MSVC complains about illegal uses of void, even though the code should be guarded by an if constexpr statement. qproperty.h(85): error C2182: 'val': illegal use of type 'void' qproperty.h(92): error C2182: 'abstract declarator': illegal use of type 'void' Avoid the issue by using a dedicated dummy type instead of void. Fixes: QTBUG-100072 Task-number: QTQAINFRA-4242 Pick-to: 6.3 6.2 Change-Id: Idc4886c26c3794e709eb762ba836139f720f8133 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QtCore: replace qSwap with std::swap/member-swap where possibleMarc Mutz2022-01-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | qSwap() is a monster that looks for ADL overloads of swap() and also detects the noexcept of the wrapped swap() function, so it should only be used when the argument type is unknown. In the vast majority of cases, the type is known to be efficiently std::swap()able or to have a member-swap. Call either of these. For the common case of pointer types, circumvent the expensive trait checks on std::swap() by providing a hand-rolled qt_ptr_swap() template, the advantage being that it can be unconditionally noexcept, removing all type traits instantiations. Don't document it, otherwise we'd be unable to pick it to 6.2. Effects on Clang -ftime-trace of a PCH'ed libQt6Gui.so build: before: **** Template sets that took longest to instantiate: [...] 27766 ms: qSwap<$> (9073 times, avg 3 ms) [...] 2806 ms: std::swap<$> (1229 times, avg 2 ms) (30572ms) after: **** Template sets that took longest to instantiate: [...] 5047 ms: qSwap<$> (641 times, avg 7 ms) [...] 3371 ms: std::swap<$> (1376 times, avg 2 ms) [qt_ptr_swap<$> does not appear in the top 400, so < 905ms] (< 9323ms) As a drive-by, remove superfluous inline keywords and template ornaments. Task-number: QTBUG-97601 Pick-to: 6.3 6.2 Change-Id: I88f9b4e3cbece268c4a1238b6d50e5712a1bab5a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Optimize QObjectCompatProperty::notifyUlf Hermann2021-10-201-0/+6
| | | | | | | | Do the check for inBindingWrapper() last. Change-Id: I3d589c9fba524f465e35cd4cc0e65e3af376b419 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QObjectCompatProperty: Add support for custom gettersIevgenii Meshcheriakov2021-10-201-2/+2
| | | | | | | | | | Add additional template argument to QObjectCompatProperty to specify a custom getter. This may be useful for classes like QAbstractProxyModelPrivate the need to customize property getters. Task-number: QTBUG-89655 Change-Id: I34fe4bdebbbf1446aff60bd20a946454607f52d5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QProperty: Eliminate further unnecessary TLS operationsUlf Hermann2021-10-181-0/+7
| | | | | | | | | If we don't have a binding, we don't need to remove it. We can figure this out without TLS lookup. Pick-to: 6.2 Change-Id: I0cb20f2a68a119df7742631e307002e3813eac03 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* corelib: Fix typos in documentationJonas Kvinge2021-10-121-1/+1
| | | | | | Pick-to: 5.15 6.2 Change-Id: I64d63af708bc6ddaabd12450eb3089e5077f849e Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* corelib: Fix typos in source code commentsJonas Kvinge2021-10-121-1/+1
| | | | | | Pick-to: 6.2 Change-Id: Ic78afb67143112468c6f84677ac88f27a74b53aa Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Avoid TLS access for groupUpdateDataFabian Kosmale2021-08-041-0/+3
| | | | | | | | | | | By putting the groupUpdateData pointer into the same thread local as the binding status, we avoid having to fetch two thread_local variables. Moreover, we can reuse the caching mechanism which we have in place for QBindingStatus to avoid costly TLS lookups. Pick-to: 6.2 Change-Id: Iaea515763510daab83f89b8e74f35a80965d6965 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Work around MSVC compilation issueFabian Kosmale2021-04-201-1/+5
| | | | | | | | | | | | | MSVC does not seem to instantiate code in the else branch of the constexpr if statement even though the condition is true. This causes an error if the PropertyType is void, as we then would attempt to create an object of type void. Work-around the issue by explicitly checking that the type is not void. Fixes: QTBUG-92962 Change-Id: Ie5acb6fae532bcc441be34418d4724de9d65b340 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add support for grouped property changesLars Knoll2021-04-161-4/+56
| | | | | | | | | | | | | | | | Add Qt::begin/endPropertyUpdateGroup() methods. These methods will group a set of property updates together and delay bindings evaluations or change notifications until the end of the update group. In cases where many properties get updated, this can avoid duplicated recalculations and change notifications. Change-Id: Ia78ae1d46abc6b7e5da5023442e081cb5c5ae67b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Andreas Buhr <andreas.buhr@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Remove lazy binding evaluationLars Knoll2021-04-161-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Too much of the existing code in Qt requires eager evaluation without large scale modifications. Combined with the fact that supporting both eager and lazy evaluation has a high maintenance burden, keeping lazy evaluation, at least in its current state, is not worth it. This does not diminish other benefits of the new property system, which include - a C++ API to setup and modify bindings and - faster execution compared to QML's existing bindings and the ability to use them without having a QML engine. We do no longer benefit from doing less work thanks to laziness. A later commit will introduce grouping support to recapture some of this benefit. [ChangeLog][Import Behavior Change][QProperty] QProperty uses always eager evaluation now when a dependency in a binding changes. Change-Id: I34694fd5c7bcb1d31a0052d2e3da8b68d016671b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Andreas Buhr <andreas.buhr@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Remove outdated commentAndreas Buhr2021-03-291-3/+3
| | | | | | | | | | | | | In qproperty_p.h and qpropertyprivate.h there were comments stating this would be used only in certain other headers. Now qproperty_p.h contains functionality to implement bindable properties, so it is used pretty much everywhere in qt. qpropertyprivate.h is only included in qproperty.h. This patch removes the outdated comments. Change-Id: Ie7328691215f875e33e58a13160ce88bf41ca228 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QPropertyBindingPrivate: Support QQmlProperyBindingFabian Kosmale2021-02-151-0/+2
| | | | | | | | | QQmlProperyBinding needs the ability to suspend binding evaluation, and needs access to the propertyDataPtr. Change-Id: If82079ffdf28fb277c6e5083714c28478f6e1729 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* QProperty add markdirtyFabian Kosmale2020-12-181-0/+2
| | | | | | | | | | | This adds functionality for marking properties (QProperty and related classes) manually as dirty. This facilliates the integration of bindable properties with non-binable properties and makes it possible for bindable properties to change due to external events. Fixes: QTBUG-89167 Change-Id: I256cf154d914149dacb6cadaba92b13c88c9d027 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Inline the fast path for removeBinding()Lars Knoll2020-11-301-2/+8
| | | | | | | | | | | Save a function call in the common case where we don't have a binding This makes a rather large performance difference for setters that do not have a binding. Change-Id: I140f29790f6fe868721a33b9fad37205e547b8e9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit c63901c5f3195596eb81e5f5ae5483ca5a0b6d35) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Inline the fast path of a few methodsLars Knoll2020-11-301-2/+15
| | | | | | | | | | No need to do function calls for the case where we return immediately after checking a boolean. Change-Id: I3e449850a10fcf82acb843cce6da6dfd98de32ad Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit e165f416a752398079590161a18255f9a0058a3e) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Remove ExtraBit and FlagMask from QPropertyBindingDataLars Knoll2020-11-301-13/+2
| | | | | | | | | | They are not needed and removing it can simplify the code in some places and avoid a couple of masking operations. Change-Id: I0e4241a2784026aa89deed35f408b094e89a11a0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit b1be6e6e6f355bfcb0c3814516f6009c91d2de89) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Inline the QPropertyBindingPrivatePtr destructorLars Knoll2020-11-301-1/+6
| | | | | | | | | | In many cases, it only derefs and does nothing else. Inline the fast code path. Change-Id: Ib605c385c1683f7833f7189c84d6cf4eb5b0e59e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit eda4c29eb26dab32e22040bdda0b9b9109b1408b) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Optimize code in QTaggedPointerLars Knoll2020-11-301-1/+1
| | | | | | | | | | | | | | | Don't execute instructions that will never do anything. Directly add the tag to the pointer in the constructor to avoid additional masking operations, and avoid a masking op that is in practice a no-op in setTag(). Do the same optimization in QTagPreservingPointerToPointer. Change-Id: Ia364f89cbe6ccc876ec9bda0c239fc4f57c10501 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 2721728c9056b442c0281f20792f19eb6a491aa0) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Inline access to the QBindingStorageLars Knoll2020-11-301-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | And inline the fast checks inside the methods in QBindingStorage. This allows QObjectBindableProperty and friends to inline all the fast checks and almost completely eliminates the overhead for property accesses when no bindings are being used. Read and write times of QObject based properties when no bindings are being used: Read Write Old style property: 3.8ns 7.3ns QObjectBindableProperty (no notification): 4.5ns 4.3ns QObjectBindableProperty (with signal): 4.5ns 7.6ns QObjectBindableProperty (inline accessors): 3.2ns 3.4ns Numbers without this patch: Old style property: 3.8ns 7.9ns QObjectBindableProperty (no notification): 7.2ns 7.7ns QObjectBindableProperty (with signal): 7.2ns 16.0ns QObjectBindableProperty (inline accessors): 6.3ns 6.7ns Change-Id: Ifd1fa3a489c3be8b1468c0b88af547aac397f412 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 98c82fb445acf45cc4c4bc86a5adda43358127bf) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* 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>