Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qproperty.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPROPERTY_H
5#define QPROPERTY_H
6
7#include <QtCore/qglobal.h>
8#include <QtCore/qshareddata.h>
9#include <QtCore/qstring.h>
10#include <QtCore/qbindingstorage.h>
11
12#include <type_traits>
13
14#include <QtCore/qpropertyprivate.h>
15
16#if __has_include(<source_location>) && __cplusplus >= 202002L && !defined(Q_QDOC)
17#include <source_location>
18#if defined(__cpp_lib_source_location)
19#define QT_SOURCE_LOCATION_NAMESPACE std
20#define QT_PROPERTY_COLLECT_BINDING_LOCATION
21#if defined(Q_CC_MSVC)
22/* MSVC runs into an issue with constexpr with source location (error C7595)
23 so use the factory function as a workaround */
24# define QT_PROPERTY_DEFAULT_BINDING_LOCATION QPropertyBindingSourceLocation::fromStdSourceLocation(std::source_location::current())
25#else
26/* some versions of gcc in turn run into
27 expression ‘std::source_location::current()’ is not a constant expression
28 so don't use the workaround there */
29# define QT_PROPERTY_DEFAULT_BINDING_LOCATION QPropertyBindingSourceLocation(std::source_location::current())
30#endif
31#endif
32#endif
33
34#if __has_include(<experimental/source_location>) && !defined(Q_QDOC)
35#include <experimental/source_location>
36#if !defined(QT_PROPERTY_COLLECT_BINDING_LOCATION)
37#if defined(__cpp_lib_experimental_source_location)
38#define QT_SOURCE_LOCATION_NAMESPACE std::experimental
39#define QT_PROPERTY_COLLECT_BINDING_LOCATION
40#define QT_PROPERTY_DEFAULT_BINDING_LOCATION QPropertyBindingSourceLocation(std::experimental::source_location::current())
41#endif // defined(__cpp_lib_experimental_source_location)
42#endif
43#endif
44
45#if !defined(QT_PROPERTY_COLLECT_BINDING_LOCATION)
46#define QT_PROPERTY_DEFAULT_BINDING_LOCATION QPropertyBindingSourceLocation()
47#endif
48
50
51namespace Qt {
52Q_CORE_EXPORT void beginPropertyUpdateGroup();
53Q_CORE_EXPORT void endPropertyUpdateGroup();
54}
55
66
67template <typename T>
69{
70protected:
71 mutable T val = T();
72private:
73 class DisableRValueRefs {};
74protected:
75 static constexpr bool UseReferences = !(std::is_arithmetic_v<T> || std::is_enum_v<T> || std::is_pointer_v<T>);
76public:
77 using value_type = T;
78 using parameter_type = std::conditional_t<UseReferences, const T &, T>;
79 using rvalue_ref = typename std::conditional_t<UseReferences, T &&, DisableRValueRefs>;
80 using arrow_operator_result = std::conditional_t<std::is_pointer_v<T>, const T &,
81 std::conditional_t<QTypeTraits::is_dereferenceable_v<T>, const T &, void>>;
82
83 QPropertyData() = default;
86 ~QPropertyData() = default;
87
90 void setValueBypassingBindings(rvalue_ref v) { val = std::move(v); }
91};
92
93// ### Qt 7: un-export
95{
96 const char *fileName = nullptr;
97 const char *functionName = nullptr;
101#ifdef __cpp_lib_source_location
102 constexpr QPropertyBindingSourceLocation(const std::source_location &cppLocation)
103 {
104 fileName = cppLocation.file_name();
105 functionName = cppLocation.function_name();
106 line = cppLocation.line();
107 column = cppLocation.column();
108 }
110 static consteval QPropertyBindingSourceLocation
111 fromStdSourceLocation(const std::source_location &cppLocation)
112 {
113 return cppLocation;
114 }
115#endif
116#ifdef __cpp_lib_experimental_source_location
117 constexpr QPropertyBindingSourceLocation(const std::experimental::source_location &cppLocation)
118 {
119 fileName = cppLocation.file_name();
120 functionName = cppLocation.function_name();
121 line = cppLocation.line();
122 column = cppLocation.column();
123 }
124#endif
125};
126
127template <typename Functor> class QPropertyChangeHandler;
129
130class Q_CORE_EXPORT QPropertyBindingError
131{
132public:
139
141 QPropertyBindingError(Type type, const QString &description = QString());
142
148
149 bool hasError() const { return d.get() != nullptr; }
150 Type type() const;
151 QString description() const;
152
153private:
154 QSharedDataPointer<QPropertyBindingErrorPrivate> d;
155};
156
157class Q_CORE_EXPORT QUntypedPropertyBinding
158{
159public:
160 // writes binding result into dataPtr
162
165
166 template<typename Functor>
168 : QUntypedPropertyBinding(metaType, &QtPrivate::bindingFunctionVTable<std::remove_reference_t<Functor>>, &f, location)
169 {}
170
176
177 bool isNull() const;
178
180
181 QMetaType valueMetaType() const;
182
184private:
187 template <typename> friend class QPropertyBinding;
189};
190
191template <typename PropertyType>
193{
194
195public:
196 QPropertyBinding() = default;
197
198 template<typename Functor>
200 : QUntypedPropertyBinding(QMetaType::fromType<PropertyType>(), &QtPrivate::bindingFunctionVTable<std::remove_reference_t<Functor>, PropertyType>, &f, location)
201 {}
202
203
204 // Internal
206 : QUntypedPropertyBinding(binding)
207 {}
208};
209
210namespace Qt {
211 template <typename Functor>
213 std::enable_if_t<std::is_invocable_v<Functor>> * = nullptr)
214 {
215 return QPropertyBinding<std::invoke_result_t<Functor>>(std::forward<Functor>(f), location);
216 }
217}
218
219struct QPropertyObserverPrivate;
222
224{
225public:
226 // Internal
228 ObserverNotifiesBinding, // observer was installed to notify bindings that obsverved property changed
229 ObserverNotifiesChangeHandler, // observer is a change handler, which runs on every change
230 ObserverIsPlaceholder, // the observer before this one is currently evaluated in QPropertyObserver::notifyObservers.
231#if QT_DEPRECATED_SINCE(6, 6)
232 ObserverIsAlias QT_DEPRECATED_VERSION_X_6_6("Use QProperty and add a binding to the target.")
233#endif
234 };
235protected:
237
238private:
241 friend class QPropertyObserver;
245
246 QTaggedPointer<QPropertyObserver, ObserverTag> next;
247 // prev is a pointer to the "next" element within the previous node, or to the "firstObserverPtr" if it is the
248 // first node.
250
251 union {
255 };
256};
257
258class Q_CORE_EXPORT QPropertyObserver : public QPropertyObserverBase
259{
260public:
261 constexpr QPropertyObserver() = default;
263 QPropertyObserver &operator=(QPropertyObserver &&other) noexcept;
265
266 template <typename Property, QtPrivate::IsUntypedPropertyData<Property> = true>
267 void setSource(const Property &property)
268 { setSource(property.bindingData()); }
269 void setSource(const QtPrivate::QPropertyBindingData &property);
270
271protected:
272 QPropertyObserver(ChangeHandler changeHandler);
273#if QT_DEPRECATED_SINCE(6, 6)
274 QT_DEPRECATED_VERSION_X_6_6("This constructor was only meant for internal use. Use QProperty and add a binding to the target.")
275 QPropertyObserver(QUntypedPropertyData *aliasedPropertyPtr);
276#endif
277
279 {
280 return aliasData;
281 }
282
283private:
284
285 QPropertyObserver(const QPropertyObserver &) = delete;
286 QPropertyObserver &operator=(const QPropertyObserver &) = delete;
287
288};
289
290template <typename Functor>
292{
293 Functor m_handler;
294public:
298 auto This = static_cast<QPropertyChangeHandler<Functor>*>(self);
299 This->m_handler();
300 })
301 , m_handler(handler)
302 {
303 }
304
305 template <typename Property, QtPrivate::IsUntypedPropertyData<Property> = true>
307 QPropertyChangeHandler(const Property &property, Functor handler)
309 auto This = static_cast<QPropertyChangeHandler<Functor>*>(self);
310 This->m_handler();
311 })
312 , m_handler(handler)
313 {
315 }
316};
317
319{
320 std::function<void()> m_handler;
321public:
323 QPropertyNotifier() = default;
324 template<typename Functor>
328 auto This = static_cast<QPropertyNotifier *>(self);
329 This->m_handler();
330 })
331 , m_handler(handler)
332 {
333 }
334
335 template <typename Functor, typename Property,
338 QPropertyNotifier(const Property &property, Functor handler)
340 auto This = static_cast<QPropertyNotifier *>(self);
341 This->m_handler();
342 })
343 , m_handler(handler)
344 {
346 }
347};
348
349template <typename T>
350class QProperty : public QPropertyData<T>
351{
353 bool is_equal(const T &v)
354 {
355 if constexpr (QTypeTraits::has_operator_equal_v<T>) {
356 if (v == this->val)
357 return true;
358 }
359 return false;
360 }
361
362public:
367
368 QProperty() = default;
369 explicit QProperty(parameter_type initialValue) : QPropertyData<T>(initialValue) {}
370 explicit QProperty(rvalue_ref initialValue) : QPropertyData<T>(std::move(initialValue)) {}
371 explicit QProperty(const QPropertyBinding<T> &binding)
372 : QProperty()
373 { setBinding(binding); }
374#ifndef Q_QDOC
375 template <typename Functor>
377 typename std::enable_if_t<std::is_invocable_r_v<T, Functor&>> * = nullptr)
379 {}
380#else
381 template <typename Functor>
382 explicit QProperty(Functor &&f);
383#endif
384 ~QProperty() = default;
385
387 {
388 d.registerWithCurrentlyEvaluatingBinding();
389 return this->val;
390 }
391
393 {
394 if constexpr (QTypeTraits::is_dereferenceable_v<T>) {
395 return value();
396 } else if constexpr (std::is_pointer_v<T>) {
397 value();
398 return this->val;
399 } else {
400 return;
401 }
402 }
403
405 {
406 return value();
407 }
408
409 operator parameter_type() const
410 {
411 return value();
412 }
413
414 void setValue(rvalue_ref newValue)
415 {
416 d.removeBinding();
417 if (is_equal(newValue))
418 return;
419 this->val = std::move(newValue);
420 notify();
421 }
422
424 {
425 d.removeBinding();
426 if (is_equal(newValue))
427 return;
428 this->val = newValue;
429 notify();
430 }
431
432 QProperty<T> &operator=(rvalue_ref newValue)
433 {
434 setValue(std::move(newValue));
435 return *this;
436 }
437
438 QProperty<T> &operator=(parameter_type newValue)
439 {
440 setValue(newValue);
441 return *this;
442 }
443
444 QPropertyBinding<T> setBinding(const QPropertyBinding<T> &newBinding)
445 {
446 return QPropertyBinding<T>(d.setBinding(newBinding, this));
447 }
448
449 bool setBinding(const QUntypedPropertyBinding &newBinding)
450 {
451 if (!newBinding.isNull() && newBinding.valueMetaType().id() != qMetaTypeId<T>())
452 return false;
453 setBinding(static_cast<const QPropertyBinding<T> &>(newBinding));
454 return true;
455 }
456
457#ifndef Q_QDOC
458 template <typename Functor>
459 QPropertyBinding<T> setBinding(Functor &&f,
461 std::enable_if_t<std::is_invocable_v<Functor>> * = nullptr)
462 {
463 return setBinding(Qt::makePropertyBinding(std::forward<Functor>(f), location));
464 }
465#else
466 template <typename Functor>
467 QPropertyBinding<T> setBinding(Functor f);
468#endif
469
470 bool hasBinding() const { return d.hasBinding(); }
471
472 QPropertyBinding<T> binding() const
473 {
474 return QPropertyBinding<T>(QUntypedPropertyBinding(d.binding()));
475 }
476
477 QPropertyBinding<T> takeBinding()
478 {
479 return QPropertyBinding<T>(d.setBinding(QUntypedPropertyBinding(), this));
480 }
481
482 template<typename Functor>
483 QPropertyChangeHandler<Functor> onValueChanged(Functor f)
484 {
485 static_assert(std::is_invocable_v<Functor>, "Functor callback must be callable without any parameters");
486 return QPropertyChangeHandler<Functor>(*this, f);
487 }
488
489 template<typename Functor>
490 QPropertyChangeHandler<Functor> subscribe(Functor f)
491 {
492 static_assert(std::is_invocable_v<Functor>, "Functor callback must be callable without any parameters");
493 f();
494 return onValueChanged(f);
495 }
496
497 template<typename Functor>
499 {
500 static_assert(std::is_invocable_v<Functor>, "Functor callback must be callable without any parameters");
501 return QPropertyNotifier(*this, f);
502 }
503
505private:
506 void notify()
507 {
508 d.notifyObservers(this);
509 }
510
511 Q_DISABLE_COPY_MOVE(QProperty)
512};
513
514namespace Qt {
515 template <typename PropertyType>
516 QPropertyBinding<PropertyType> makePropertyBinding(const QProperty<PropertyType> &otherProperty,
519 {
520 return Qt::makePropertyBinding([&otherProperty]() -> PropertyType { return otherProperty; }, location);
521 }
522}
523
524
525namespace QtPrivate
526{
527
547
548template<typename Property, typename = void>
550{
551 using T = typename Property::value_type;
552public:
553 // interface for computed properties. Those do not have a binding()/setBinding() method, but one can
554 // install observers on them.
555 static constexpr QBindableInterface iface = {
556 [](const QUntypedPropertyData *d, void *value) -> void
557 { *static_cast<T*>(value) = static_cast<const Property *>(d)->value(); },
558 nullptr,
559 nullptr,
560 nullptr,
562 { return Qt::makePropertyBinding([d]() -> T { return static_cast<const Property *>(d)->value(); }, location); },
563 [](const QUntypedPropertyData *d, QPropertyObserver *observer) -> void
564 { observer->setSource(static_cast<const Property *>(d)->bindingData()); },
565 []() { return QMetaType::fromType<T>(); }
566 };
567};
568
569template<typename Property>
570class QBindableInterfaceForProperty<const Property, std::void_t<decltype(std::declval<Property>().binding())>>
571{
572 using T = typename Property::value_type;
573public:
574 // A bindable created from a const property results in a read-only interface, too.
575 static constexpr QBindableInterface iface = {
576
577 [](const QUntypedPropertyData *d, void *value) -> void
578 { *static_cast<T*>(value) = static_cast<const Property *>(d)->value(); },
579 /*setter=*/nullptr,
581 { return static_cast<const Property *>(d)->binding(); },
582 /*setBinding=*/nullptr,
584 { return Qt::makePropertyBinding([d]() -> T { return static_cast<const Property *>(d)->value(); }, location); },
585 [](const QUntypedPropertyData *d, QPropertyObserver *observer) -> void
586 { observer->setSource(static_cast<const Property *>(d)->bindingData()); },
587 []() { return QMetaType::fromType<T>(); }
588 };
589};
590
591template<typename Property>
592class QBindableInterfaceForProperty<Property, std::void_t<decltype(std::declval<Property>().binding())>>
593{
594 using T = typename Property::value_type;
595public:
596 static constexpr QBindableInterface iface = {
597 [](const QUntypedPropertyData *d, void *value) -> void
598 { *static_cast<T*>(value) = static_cast<const Property *>(d)->value(); },
599 [](QUntypedPropertyData *d, const void *value) -> void
600 { static_cast<Property *>(d)->setValue(*static_cast<const T*>(value)); },
602 { return static_cast<const Property *>(d)->binding(); },
604 { return static_cast<Property *>(d)->setBinding(static_cast<const QPropertyBinding<T> &>(binding)); },
606 { return Qt::makePropertyBinding([d]() -> T { return static_cast<const Property *>(d)->value(); }, location); },
607 [](const QUntypedPropertyData *d, QPropertyObserver *observer) -> void
608 { observer->setSource(static_cast<const Property *>(d)->bindingData()); },
609 []() { return QMetaType::fromType<T>(); }
610 };
611};
612
613}
614
615namespace QtPrivate {
616// used in Q(Untyped)Bindable to print warnings about various binding errors
617namespace BindableWarnings {
619Q_CORE_EXPORT void printUnsuitableBindableWarning(QAnyStringView prefix, Reason reason);
620Q_CORE_EXPORT void printMetaTypeMismatch(QMetaType actual, QMetaType expected);
621}
622
623namespace PropertyAdaptorSlotObjectHelpers {
624Q_CORE_EXPORT void getter(const QUntypedPropertyData *d, void *value);
625Q_CORE_EXPORT void setter(QUntypedPropertyData *d, const void *value);
629 QUntypedPropertyData *temp, void *value);
631 const QUntypedPropertyBinding &binding,
633Q_CORE_EXPORT void setObserver(const QUntypedPropertyData *d, QPropertyObserver *observer);
634
635template<typename T>
638{
639 struct Data : QPropertyData<T>
640 {
641 void *data() { return &this->val; }
642 } temp;
643 return bindingWrapper(type, d, binding, &temp, temp.data());
644}
645
646template<typename T>
648{
649 return setBinding(d, binding, &bindingWrapper<T>);
650}
651
652template<typename T>
655{
657 [d]() -> T {
658 T r;
659 getter(d, &r);
660 return r;
661 },
662 location);
663}
664
665template<class T>
666inline constexpr QBindableInterface iface = {
667 &getter,
668 &setter,
669 &getBinding,
670 &setBinding<T>,
671 &makeBinding<T>,
673 &QMetaType::fromType<T>,
674};
675}
676}
677
679{
680 friend struct QUntypedBindablePrivate; // allows access to internal data
681protected:
687
688 Q_CORE_EXPORT explicit QUntypedBindable(QObject* obj, const QMetaProperty &property, const QtPrivate::QBindableInterface *i);
689 Q_CORE_EXPORT explicit QUntypedBindable(QObject* obj, const char* property, const QtPrivate::QBindableInterface *i);
690
691public:
692 constexpr QUntypedBindable() = default;
693 template<typename Property>
695 : data(const_cast<std::remove_cv_t<Property> *>(p)),
696 iface(&QtPrivate::QBindableInterfaceForProperty<Property>::iface)
697 { Q_ASSERT(data && iface); }
698
699 bool isValid() const { return data != nullptr; }
700 bool isBindable() const { return iface && iface->getBinding; }
701 bool isReadOnly() const { return !(iface && iface->setBinding && iface->setObserver); }
702
707
709 {
710 if (!iface)
711 return QUntypedPropertyBinding {};
712 // We do not have a dedicated takeBinding function pointer in the interface
713 // therefore we synthesize takeBinding by retrieving the binding with binding
714 // and calling setBinding with a default constructed QUntypedPropertyBinding
715 // afterwards.
716 if (!(iface->getBinding && iface->setBinding))
717 return QUntypedPropertyBinding {};
720 return binding;
721 }
722
723 void observe(QPropertyObserver *observer) const
724 {
725 if (iface)
726 iface->setObserver(data, observer);
727#ifndef QT_NO_DEBUG
728 else
731#endif
732 }
733
734 template<typename Functor>
735 QPropertyChangeHandler<Functor> onValueChanged(Functor f) const
736 {
737 QPropertyChangeHandler<Functor> handler(f);
738 observe(&handler);
739 return handler;
740 }
741
742 template<typename Functor>
743 QPropertyChangeHandler<Functor> subscribe(Functor f) const
744 {
745 f();
746 return onValueChanged(f);
747 }
748
749 template<typename Functor>
751 {
752 QPropertyNotifier handler(f);
753 observe(&handler);
754 return handler;
755 }
756
758 {
759 if (!isBindable()) {
760#ifndef QT_NO_DEBUG
763#endif
765 }
766 return iface->getBinding(data);
767 }
769 {
770 if (isReadOnly()) {
771#ifndef QT_NO_DEBUG
774 QtPrivate::BindableWarnings::printUnsuitableBindableWarning("setBinding: Could not set binding via bindable interface.", errorType);
775#endif
776 return false;
777 }
778 if (!binding.isNull() && binding.valueMetaType() != metaType()) {
779#ifndef QT_NO_DEBUG
781#endif
782 return false;
783 }
785 return true;
786 }
787 bool hasBinding() const
788 {
789 return !binding().isNull();
790 }
791
793 {
794 if (!(iface && data))
795 return QMetaType();
796 if (iface->metaType)
797 return iface->metaType();
798 // ### Qt 7: Change the metatype function to take data as its argument
799 // special casing for QML's proxy bindable: allow multiplexing in the getter
800 // function to retrieve the metatype from data
804 return result;
805 }
806
807};
808
809template<typename T>
811{
812 template<typename U>
813 friend class QPropertyAlias;
816 {}
817public:
820 {
821 if (iface && metaType() != QMetaType::fromType<T>()) {
822 data = nullptr;
823 iface = nullptr;
824 }
825 }
826
828 : QUntypedBindable(obj, property, &QtPrivate::PropertyAdaptorSlotObjectHelpers::iface<T>) {}
829
830 explicit QBindable(QObject *obj, const char *property)
831 : QUntypedBindable(obj, property, &QtPrivate::PropertyAdaptorSlotObjectHelpers::iface<T>) {}
832
834 {
835 return static_cast<QPropertyBinding<T> &&>(QUntypedBindable::makeBinding(location));
836 }
837 QPropertyBinding<T> binding() const
838 {
839 return static_cast<QPropertyBinding<T> &&>(QUntypedBindable::binding());
840 }
841
842 QPropertyBinding<T> takeBinding()
843 {
844 return static_cast<QPropertyBinding<T> &&>(QUntypedBindable::takeBinding());
845 }
846
848 QPropertyBinding<T> setBinding(const QPropertyBinding<T> &binding)
849 {
850 Q_ASSERT(!iface || binding.isNull() || binding.valueMetaType() == metaType());
851
852 if (iface && iface->setBinding)
853 return static_cast<QPropertyBinding<T> &&>(iface->setBinding(data, binding));
854#ifndef QT_NO_DEBUG
855 if (!iface)
857 else
859#endif
860 return QPropertyBinding<T>();
861 }
862#ifndef Q_QDOC
863 template <typename Functor>
864 QPropertyBinding<T> setBinding(Functor &&f,
866 std::enable_if_t<std::is_invocable_v<Functor>> * = nullptr)
867 {
868 return setBinding(Qt::makePropertyBinding(std::forward<Functor>(f), location));
869 }
870#else
871 template <typename Functor>
872 QPropertyBinding<T> setBinding(Functor f);
873#endif
874
875 T value() const
876 {
877 if (iface) {
878 T result;
880 return result;
881 }
882 return T{};
883 }
884
885 void setValue(const T &value)
886 {
887 if (iface && iface->setter)
889 }
890};
891
892#if QT_DEPRECATED_SINCE(6, 6)
893template<typename T>
894class QT_DEPRECATED_VERSION_X_6_6("Class was only meant for internal use, use a QProperty and add a binding to the target")
896{
897 Q_DISABLE_COPY_MOVE(QPropertyAlias)
898 const QtPrivate::QBindableInterface *iface = nullptr;
899
900public:
902 QPropertyAlias(QProperty<T> *property)
904 iface(&QtPrivate::QBindableInterfaceForProperty<QProperty<T>>::iface)
905 {
906 if (iface)
907 iface->setObserver(aliasedProperty(), this);
908 }
909
910 template <typename Property, QtPrivate::IsUntypedPropertyData<Property> = true>
911 QPropertyAlias(Property *property)
913 iface(&QtPrivate::QBindableInterfaceForProperty<Property>::iface)
914 {
915 if (iface)
916 iface->setObserver(aliasedProperty(), this);
917 }
918
919 QPropertyAlias(QPropertyAlias<T> *alias)
920 : QPropertyObserver(alias->aliasedProperty()),
921 iface(alias->iface)
922 {
923 if (iface)
924 iface->setObserver(aliasedProperty(), this);
925 }
926
927 QPropertyAlias(const QBindable<T> &property)
930 {
931 if (iface)
932 iface->setObserver(aliasedProperty(), this);
933 }
934
935 T value() const
936 {
937 T t = T();
938 if (auto *p = aliasedProperty())
939 iface->getter(p, &t);
940 return t;
941 }
942
943 operator T() const { return value(); }
944
945 void setValue(const T &newValue)
946 {
947 if (auto *p = aliasedProperty())
948 iface->setter(p, &newValue);
949 }
950
951 QPropertyAlias<T> &operator=(const T &newValue)
952 {
953 setValue(newValue);
954 return *this;
955 }
956
957 QPropertyBinding<T> setBinding(const QPropertyBinding<T> &newBinding)
958 {
959 return QBindable<T>(aliasedProperty(), iface).setBinding(newBinding);
960 }
961
962 bool setBinding(const QUntypedPropertyBinding &newBinding)
963 {
964 return QBindable<T>(aliasedProperty(), iface).setBinding(newBinding);
965 }
966
967#ifndef Q_QDOC
968 template <typename Functor>
969 QPropertyBinding<T> setBinding(Functor &&f,
971 std::enable_if_t<std::is_invocable_v<Functor>> * = nullptr)
972 {
973 return setBinding(Qt::makePropertyBinding(std::forward<Functor>(f), location));
974 }
975#else
976 template <typename Functor>
977 QPropertyBinding<T> setBinding(Functor f);
978#endif
979
980 bool hasBinding() const
981 {
982 return QBindable<T>(aliasedProperty(), iface).hasBinding();
983 }
984
985 QPropertyBinding<T> binding() const
986 {
987 return QBindable<T>(aliasedProperty(), iface).binding();
988 }
989
990 QPropertyBinding<T> takeBinding()
991 {
992 return QBindable<T>(aliasedProperty(), iface).takeBinding();
993 }
994
995 template<typename Functor>
996 QPropertyChangeHandler<Functor> onValueChanged(Functor f)
997 {
998 return QBindable<T>(aliasedProperty(), iface).onValueChanged(f);
999 }
1000
1001 template<typename Functor>
1002 QPropertyChangeHandler<Functor> subscribe(Functor f)
1003 {
1004 return QBindable<T>(aliasedProperty(), iface).subscribe(f);
1005 }
1006
1007 template<typename Functor>
1008 QPropertyNotifier addNotifier(Functor f)
1009 {
1010 return QBindable<T>(aliasedProperty(), iface).addNotifier(f);
1011 }
1012
1013 bool isValid() const
1014 {
1015 return aliasedProperty() != nullptr;
1016 }
1018};
1019#endif // QT_DEPRECATED_SINCE(6, 6)
1020
1021template<typename Class, typename T, auto Offset, auto Signal = nullptr>
1023{
1024 using ThisType = QObjectBindableProperty<Class, T, Offset, Signal>;
1025 static bool constexpr HasSignal = !std::is_same_v<decltype(Signal), std::nullptr_t>;
1026 using SignalTakesValue = std::is_invocable<decltype(Signal), Class, T>;
1027 Class *owner()
1028 {
1029 char *that = reinterpret_cast<char *>(this);
1030 return reinterpret_cast<Class *>(that - QtPrivate::detail::getOffset(Offset));
1031 }
1032 const Class *owner() const
1033 {
1034 char *that = const_cast<char *>(reinterpret_cast<const char *>(this));
1035 return reinterpret_cast<Class *>(that - QtPrivate::detail::getOffset(Offset));
1036 }
1037 static void signalCallBack(QUntypedPropertyData *o)
1038 {
1039 QObjectBindableProperty *that = static_cast<QObjectBindableProperty *>(o);
1040 if constexpr (HasSignal) {
1041 if constexpr (SignalTakesValue::value)
1042 (that->owner()->*Signal)(that->valueBypassingBindings());
1043 else
1044 (that->owner()->*Signal)();
1045 }
1046 }
1047public:
1052
1054 explicit QObjectBindableProperty(const T &initialValue) : QPropertyData<T>(initialValue) {}
1055 explicit QObjectBindableProperty(T &&initialValue) : QPropertyData<T>(std::move(initialValue)) {}
1056 explicit QObjectBindableProperty(const QPropertyBinding<T> &binding)
1058 { setBinding(binding); }
1059#ifndef Q_QDOC
1060 template <typename Functor>
1062 typename std::enable_if_t<std::is_invocable_r_v<T, Functor&>> * = nullptr)
1064 {}
1065#else
1066 template <typename Functor>
1067 explicit QObjectBindableProperty(Functor &&f);
1068#endif
1069
1071 {
1072 qGetBindingStorage(owner())->registerDependency(this);
1073 return this->val;
1074 }
1075
1077 {
1078 if constexpr (QTypeTraits::is_dereferenceable_v<T>) {
1079 return value();
1080 } else if constexpr (std::is_pointer_v<T>) {
1081 value();
1082 return this->val;
1083 } else {
1084 return;
1085 }
1086 }
1087
1089 {
1090 return value();
1091 }
1092
1093 operator parameter_type() const
1094 {
1095 return value();
1096 }
1097
1099 {
1100 auto *bd = qGetBindingStorage(owner())->bindingData(this);
1101 if (bd)
1102 bd->removeBinding();
1103 if (this->val == t)
1104 return;
1105 this->val = t;
1106 notify(bd);
1107 }
1108
1109 void notify() {
1110 auto *bd = qGetBindingStorage(owner())->bindingData(this);
1111 notify(bd);
1112 }
1113
1115 {
1116 auto *bd = qGetBindingStorage(owner())->bindingData(this);
1117 if (bd)
1118 bd->removeBinding();
1119 if (this->val == t)
1120 return;
1121 this->val = std::move(t);
1122 notify(bd);
1123 }
1124
1126 {
1127 setValue(std::move(newValue));
1128 return *this;
1129 }
1130
1132 {
1133 setValue(newValue);
1134 return *this;
1135 }
1136
1137 QPropertyBinding<T> setBinding(const QPropertyBinding<T> &newBinding)
1138 {
1140 QUntypedPropertyBinding oldBinding(bd->setBinding(newBinding, this, HasSignal ? &signalCallBack : nullptr));
1141 return static_cast<QPropertyBinding<T> &>(oldBinding);
1142 }
1143
1144 bool setBinding(const QUntypedPropertyBinding &newBinding)
1145 {
1146 if (!newBinding.isNull() && newBinding.valueMetaType().id() != qMetaTypeId<T>())
1147 return false;
1148 setBinding(static_cast<const QPropertyBinding<T> &>(newBinding));
1149 return true;
1150 }
1151
1152#ifndef Q_QDOC
1153 template <typename Functor>
1154 QPropertyBinding<T> setBinding(Functor &&f,
1156 std::enable_if_t<std::is_invocable_v<Functor>> * = nullptr)
1157 {
1158 return setBinding(Qt::makePropertyBinding(std::forward<Functor>(f), location));
1159 }
1160#else
1161 template <typename Functor>
1162 QPropertyBinding<T> setBinding(Functor f);
1163#endif
1164
1165 bool hasBinding() const
1166 {
1167 auto *bd = qGetBindingStorage(owner())->bindingData(this);
1168 return bd && bd->binding() != nullptr;
1169 }
1170
1171 QPropertyBinding<T> binding() const
1172 {
1173 auto *bd = qGetBindingStorage(owner())->bindingData(this);
1174 return static_cast<QPropertyBinding<T> &&>(QUntypedPropertyBinding(bd ? bd->binding() : nullptr));
1175 }
1176
1177 QPropertyBinding<T> takeBinding()
1178 {
1179 return setBinding(QPropertyBinding<T>());
1180 }
1181
1182 template<typename Functor>
1183 QPropertyChangeHandler<Functor> onValueChanged(Functor f)
1184 {
1185 static_assert(std::is_invocable_v<Functor>, "Functor callback must be callable without any parameters");
1186 return QPropertyChangeHandler<Functor>(*this, f);
1187 }
1188
1189 template<typename Functor>
1190 QPropertyChangeHandler<Functor> subscribe(Functor f)
1191 {
1192 static_assert(std::is_invocable_v<Functor>, "Functor callback must be callable without any parameters");
1193 f();
1194 return onValueChanged(f);
1195 }
1196
1197 template<typename Functor>
1199 {
1200 static_assert(std::is_invocable_v<Functor>, "Functor callback must be callable without any parameters");
1201 return QPropertyNotifier(*this, f);
1202 }
1203
1205 {
1206 auto *storage = const_cast<QBindingStorage *>(qGetBindingStorage(owner()));
1207 return *storage->bindingData(const_cast<ThisType *>(this), true);
1208 }
1209private:
1211 {
1212 if (binding)
1213 binding->notifyObservers(this, qGetBindingStorage(owner()));
1214 if constexpr (HasSignal) {
1215 if constexpr (SignalTakesValue::value)
1216 (owner()->*Signal)(this->valueBypassingBindings());
1217 else
1218 (owner()->*Signal)();
1219 }
1220 }
1221};
1222
1223#define QT_OBJECT_BINDABLE_PROPERTY_3(Class, Type, name) \
1224 static constexpr size_t _qt_property_##name##_offset() { \
1225 QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \
1226 return offsetof(Class, name); \
1227 QT_WARNING_POP \
1228 } \
1229 QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, nullptr> name;
1230
1231#define QT_OBJECT_BINDABLE_PROPERTY_4(Class, Type, name, Signal) \
1232 static constexpr size_t _qt_property_##name##_offset() { \
1233 QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \
1234 return offsetof(Class, name); \
1235 QT_WARNING_POP \
1236 } \
1237 QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, Signal> name;
1238
1239#define Q_OBJECT_BINDABLE_PROPERTY(...) \
1240 QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \
1241 QT_OVERLOADED_MACRO(QT_OBJECT_BINDABLE_PROPERTY, __VA_ARGS__) \
1242 QT_WARNING_POP
1243
1244#define QT_OBJECT_BINDABLE_PROPERTY_WITH_ARGS_4(Class, Type, name, value) \
1245 static constexpr size_t _qt_property_##name##_offset() \
1246 { \
1247 QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \
1248 return offsetof(Class, name); \
1249 QT_WARNING_POP \
1250 } \
1251 QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, nullptr> name = \
1252 QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, nullptr>( \
1253 value);
1254
1255#define QT_OBJECT_BINDABLE_PROPERTY_WITH_ARGS_5(Class, Type, name, value, Signal) \
1256 static constexpr size_t _qt_property_##name##_offset() \
1257 { \
1258 QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \
1259 return offsetof(Class, name); \
1260 QT_WARNING_POP \
1261 } \
1262 QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, Signal> name = \
1263 QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, Signal>( \
1264 value);
1265
1266#define Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(...) \
1267 QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \
1268 QT_OVERLOADED_MACRO(QT_OBJECT_BINDABLE_PROPERTY_WITH_ARGS, __VA_ARGS__) \
1269 QT_WARNING_POP
1270
1271template<typename Class, typename T, auto Offset, auto Getter>
1273{
1274 Class *owner()
1275 {
1276 char *that = reinterpret_cast<char *>(this);
1277 return reinterpret_cast<Class *>(that - QtPrivate::detail::getOffset(Offset));
1278 }
1279 const Class *owner() const
1280 {
1281 char *that = const_cast<char *>(reinterpret_cast<const char *>(this));
1282 return reinterpret_cast<Class *>(that - QtPrivate::detail::getOffset(Offset));
1283 }
1284
1285public:
1286 using value_type = T;
1288
1290
1292 {
1293 qGetBindingStorage(owner())->registerDependency(this);
1294 return (owner()->*Getter)();
1295 }
1296
1297 std::conditional_t<QTypeTraits::is_dereferenceable_v<T>, parameter_type, void>
1299 {
1300 if constexpr (QTypeTraits::is_dereferenceable_v<T>)
1301 return value();
1302 else
1303 return;
1304 }
1305
1307 {
1308 return value();
1309 }
1310
1311 operator parameter_type() const
1312 {
1313 return value();
1314 }
1315
1316 constexpr bool hasBinding() const { return false; }
1317
1318 template<typename Functor>
1319 QPropertyChangeHandler<Functor> onValueChanged(Functor f)
1320 {
1321 static_assert(std::is_invocable_v<Functor>, "Functor callback must be callable without any parameters");
1322 return QPropertyChangeHandler<Functor>(*this, f);
1323 }
1324
1325 template<typename Functor>
1326 QPropertyChangeHandler<Functor> subscribe(Functor f)
1327 {
1328 static_assert(std::is_invocable_v<Functor>, "Functor callback must be callable without any parameters");
1329 f();
1330 return onValueChanged(f);
1331 }
1332
1333 template<typename Functor>
1335 {
1336 static_assert(std::is_invocable_v<Functor>, "Functor callback must be callable without any parameters");
1337 return QPropertyNotifier(*this, f);
1338 }
1339
1341 {
1342 auto *storage = const_cast<QBindingStorage *>(qGetBindingStorage(owner()));
1343 return *storage->bindingData(const_cast<QObjectComputedProperty *>(this), true);
1344 }
1345
1346 void notify() {
1347 // computed property can't store a binding, so there's nothing to mark
1348 auto *storage = const_cast<QBindingStorage *>(qGetBindingStorage(owner()));
1349 auto bd = storage->bindingData(const_cast<QObjectComputedProperty *>(this), false);
1350 if (bd)
1351 bd->notifyObservers(this, qGetBindingStorage(owner()));
1352 }
1353};
1354
1355#define Q_OBJECT_COMPUTED_PROPERTY(Class, Type, name, ...) \
1356 static constexpr size_t _qt_property_##name##_offset() { \
1357 QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \
1358 return offsetof(Class, name); \
1359 QT_WARNING_POP \
1360 } \
1361 QObjectComputedProperty<Class, Type, Class::_qt_property_##name##_offset, __VA_ARGS__> name;
1362
1363#undef QT_SOURCE_LOCATION_NAMESPACE
1364
1366
1367#endif // QPROPERTY_H
\inmodule QtCore
\inmodule QtCore
Definition qproperty.h:811
void setValue(const T &value)
Sets the underlying property's value to value.
Definition qproperty.h:885
QBindable(QObject *obj, const QMetaProperty &property)
See \l QBindable::QBindable(QObject *obj, const char *property)
Definition qproperty.h:827
QPropertyBinding< T > makeBinding(const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION) const
Constructs a binding evaluating to the underlying property's value, using a specified source location...
Definition qproperty.h:833
QPropertyBinding< T > takeBinding()
Removes the currently set binding of the underlying property and returns it.
Definition qproperty.h:842
QPropertyBinding< T > setBinding(const QPropertyBinding< T > &binding)
Sets the underlying property's binding to binding.
Definition qproperty.h:848
T value() const
Returns the underlying property's current value.
Definition qproperty.h:875
QPropertyBinding< T > setBinding(Functor &&f, const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION, std::enable_if_t< std::is_invocable_v< Functor > > *=nullptr)
Definition qproperty.h:864
QBindable(QObject *obj, const char *property)
Constructs a QBindable for the \l Q_PROPERTY property on obj.
Definition qproperty.h:830
QBindable(const QUntypedBindable &b)
Definition qproperty.h:819
QPropertyBinding< T > binding() const
Returns the currently set binding of the underlying property.
Definition qproperty.h:837
void registerDependency(const QUntypedPropertyData *data) const
QtPrivate::QPropertyBindingData * bindingData(const QUntypedPropertyData *data) const
\inmodule QtCore
\inmodule QtCore
Definition qmetatype.h:341
int id(int=0) const
Definition qmetatype.h:475
\inmodule QtCore
Definition qproperty.h:1023
QObjectBindableProperty()=default
void setValue(parameter_type t)
Definition qproperty.h:1098
QPropertyNotifier addNotifier(Functor f)
Subscribes the given functor f as a callback that is called whenever the value of the property change...
Definition qproperty.h:1198
typename QPropertyData< T >::rvalue_ref rvalue_ref
Definition qproperty.h:1050
typename QPropertyData< T >::value_type value_type
Definition qproperty.h:1048
void notify()
Programmatically signals a change of the property.
Definition qproperty.h:1109
QPropertyBinding< T > binding() const
Returns the binding expression that is associated with this property.
Definition qproperty.h:1171
typename QPropertyData< T >::arrow_operator_result arrow_operator_result
Definition qproperty.h:1051
arrow_operator_result operator->() const
Definition qproperty.h:1076
parameter_type value() const
Returns the value of the property.
Definition qproperty.h:1070
QObjectBindableProperty(T &&initialValue)
Move-Constructs a property with the provided initialValue.
Definition qproperty.h:1055
QPropertyChangeHandler< Functor > subscribe(Functor f)
Subscribes the given functor f as a callback that is called immediately and whenever the value of the...
Definition qproperty.h:1190
const QtPrivate::QPropertyBindingData & bindingData() const
Definition qproperty.h:1204
void setValue(rvalue_ref t)
Assigns newValue to this property and removes the property's associated binding, if present.
Definition qproperty.h:1114
parameter_type operator*() const
Definition qproperty.h:1088
QObjectBindableProperty(Functor &&f, const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION, typename std::enable_if_t< std::is_invocable_r_v< T, Functor & > > *=nullptr)
Definition qproperty.h:1061
QObjectBindableProperty(const QPropertyBinding< T > &binding)
Definition qproperty.h:1056
bool hasBinding() const
Returns true if the property is associated with a binding; false otherwise.
Definition qproperty.h:1165
QObjectBindableProperty & operator=(rvalue_ref newValue)
Definition qproperty.h:1125
QPropertyBinding< T > setBinding(Functor &&f, const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION, std::enable_if_t< std::is_invocable_v< Functor > > *=nullptr)
Definition qproperty.h:1154
QObjectBindableProperty & operator=(parameter_type newValue)
Definition qproperty.h:1131
typename QPropertyData< T >::parameter_type parameter_type
Definition qproperty.h:1049
QPropertyBinding< T > setBinding(const QPropertyBinding< T > &newBinding)
Associates the value of this property with the provided newBinding expression and returns the previou...
Definition qproperty.h:1137
bool setBinding(const QUntypedPropertyBinding &newBinding)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qproperty.h:1144
QPropertyBinding< T > takeBinding()
Disassociates the binding expression from this property and returns it.
Definition qproperty.h:1177
QObjectBindableProperty(const T &initialValue)
Constructs a property with the provided initialValue.
Definition qproperty.h:1054
QPropertyChangeHandler< Functor > onValueChanged(Functor f)
Registers the given functor f as a callback that shall be called whenever the value of the property c...
Definition qproperty.h:1183
\macro Q_OBJECT_COMPAT_PROPERTY(containingClass, type, name, callback)
Definition qproperty.h:1273
QPropertyChangeHandler< Functor > onValueChanged(Functor f)
Definition qproperty.h:1319
constexpr bool hasBinding() const
Definition qproperty.h:1316
QObjectComputedProperty()=default
std::conditional_t< QTypeTraits::is_dereferenceable_v< T >, parameter_type, void > operator->() const
Definition qproperty.h:1298
QPropertyChangeHandler< Functor > subscribe(Functor f)
Definition qproperty.h:1326
QtPrivate::QPropertyBindingData & bindingData() const
Definition qproperty.h:1340
parameter_type operator*() const
Definition qproperty.h:1306
parameter_type value() const
Definition qproperty.h:1291
QPropertyNotifier addNotifier(Functor f)
Definition qproperty.h:1334
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
\inmodule QtCore
Definition qproperty.h:131
bool hasError() const
Definition qproperty.h:149
QPropertyBinding(const QUntypedPropertyBinding &binding)
Definition qproperty.h:205
QPropertyBinding()=default
QPropertyBinding(Functor &&f, const QPropertyBindingSourceLocation &location)
Definition qproperty.h:199
\inmodule QtCore
Definition qproperty.h:292
Q_NODISCARD_CTOR QPropertyChangeHandler(Functor handler)
Definition qproperty.h:296
Q_NODISCARD_CTOR QPropertyChangeHandler(const Property &property, Functor handler)
Definition qproperty.h:307
\inmodule QtCore
Definition qproperty.h:69
QPropertyData(rvalue_ref t)
Definition qproperty.h:85
std::conditional_t< std::is_pointer_v< T >, const T &, std::conditional_t< QTypeTraits::is_dereferenceable_v< T >, const T &, void > > arrow_operator_result
Definition qproperty.h:80
typename std::conditional_t< UseReferences, T &&, DisableRValueRefs > rvalue_ref
Definition qproperty.h:79
static constexpr bool UseReferences
Definition qproperty.h:75
std::conditional_t< UseReferences, const T &, T > parameter_type
Definition qproperty.h:78
void setValueBypassingBindings(rvalue_ref v)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qproperty.h:90
parameter_type valueBypassingBindings() const
Returns the data stored in this property.
Definition qproperty.h:88
void setValueBypassingBindings(parameter_type v)
Sets the data value stored in this property to v.
Definition qproperty.h:89
QPropertyData()=default
QPropertyData(parameter_type t)
Definition qproperty.h:84
~QPropertyData()=default
\inmodule QtCore
Definition qproperty.h:319
Q_NODISCARD_CTOR QPropertyNotifier(Functor handler)
Definition qproperty.h:326
Q_NODISCARD_CTOR QPropertyNotifier(const Property &property, Functor handler)
Definition qproperty.h:338
Q_NODISCARD_CTOR QPropertyNotifier()=default
QUntypedPropertyData * aliasData
Definition qproperty.h:254
void(*)(QPropertyObserver *, QUntypedPropertyData *) ChangeHandler
Definition qproperty.h:236
ChangeHandler changeHandler
Definition qproperty.h:253
QPropertyBindingPrivate * binding
Definition qproperty.h:252
void setSource(const Property &property)
Definition qproperty.h:267
QUntypedPropertyData * aliasedProperty() const
Definition qproperty.h:278
QPropertyObserver & operator=(QPropertyObserver &&other) noexcept
constexpr QPropertyObserver()=default
\inmodule QtCore
Definition qproperty.h:351
typename QPropertyData< T >::arrow_operator_result arrow_operator_result
Definition qproperty.h:366
QPropertyBinding< T > takeBinding()
Disassociates the binding expression from this property and returns it.
Definition qproperty.h:477
QProperty(const QPropertyBinding< T > &binding)
Constructs a property that is tied to the provided binding expression.
Definition qproperty.h:371
QPropertyChangeHandler< Functor > subscribe(Functor f)
Subscribes the given functor f as a callback that is called immediately and whenever the value of the...
Definition qproperty.h:490
QPropertyChangeHandler< Functor > onValueChanged(Functor f)
Registers the given functor f as a callback that shall be called whenever the value of the property c...
Definition qproperty.h:483
QProperty< T > & operator=(rvalue_ref newValue)
Definition qproperty.h:432
QProperty(rvalue_ref initialValue)
Definition qproperty.h:370
const QtPrivate::QPropertyBindingData & bindingData() const
Definition qproperty.h:504
typename QPropertyData< T >::value_type value_type
Definition qproperty.h:363
bool hasBinding() const
Definition qproperty.h:470
bool setBinding(const QUntypedPropertyBinding &newBinding)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qproperty.h:449
QPropertyBinding< T > binding() const
Returns the binding expression that is associated with this property.
Definition qproperty.h:472
parameter_type value() const
Returns the value of the property.
Definition qproperty.h:386
QPropertyBinding< T > setBinding(const QPropertyBinding< T > &newBinding)
Associates the value of this property with the provided newBinding expression and returns the previou...
Definition qproperty.h:444
void setValue(parameter_type newValue)
Assigns newValue to this property and removes the property's associated binding, if present.
Definition qproperty.h:423
typename QPropertyData< T >::rvalue_ref rvalue_ref
Definition qproperty.h:365
QPropertyBinding< T > setBinding(Functor &&f, const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION, std::enable_if_t< std::is_invocable_v< Functor > > *=nullptr)
Definition qproperty.h:459
void setValue(rvalue_ref newValue)
Definition qproperty.h:414
QProperty()=default
Constructs a property with a default constructed instance of T.
QProperty(Functor &&f, const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION, typename std::enable_if_t< std::is_invocable_r_v< T, Functor & > > *=nullptr)
Definition qproperty.h:376
QProperty< T > & operator=(parameter_type newValue)
Assigns newValue to this property and returns a reference to this QProperty.
Definition qproperty.h:438
typename QPropertyData< T >::parameter_type parameter_type
Definition qproperty.h:364
QPropertyNotifier addNotifier(Functor f)
Subscribes the given functor f as a callback that is called whenever the value of the property change...
Definition qproperty.h:498
arrow_operator_result operator->() const
Definition qproperty.h:392
~QProperty()=default
Destroys the property.
parameter_type operator*() const
Definition qproperty.h:404
QProperty(parameter_type initialValue)
Definition qproperty.h:369
RAII class around Qt::beginPropertyUpdateGroup()/Qt::endPropertyUpdateGroup().
Definition qproperty.h:57
Q_NODISCARD_CTOR QScopedPropertyUpdateGroup()
Calls Qt::beginPropertyUpdateGroup().
Definition qproperty.h:61
~QScopedPropertyUpdateGroup() noexcept(false)
Calls Qt::endPropertyUpdateGroup().
Definition qproperty.h:63
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qproperty.h:679
QUntypedPropertyBinding binding() const
Returns the underlying property's binding if there is any, or a default constructed QUntypedPropertyB...
Definition qproperty.h:757
QUntypedPropertyBinding makeBinding(const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION) const
Creates a binding returning the underlying properties' value, using a specified source location.
Definition qproperty.h:703
bool hasBinding() const
Returns true if the underlying property has a binding.
Definition qproperty.h:787
QMetaType metaType() const
Definition qproperty.h:792
const QtPrivate::QBindableInterface * iface
Definition qproperty.h:683
QPropertyChangeHandler< Functor > subscribe(Functor f) const
Behaves like a call to f followed by onValueChanged(f),.
Definition qproperty.h:743
QUntypedPropertyBinding takeBinding()
Removes the currently set binding from the property and returns it.
Definition qproperty.h:708
bool isBindable() const
Definition qproperty.h:700
bool isValid() const
Returns true if the QUntypedBindable is valid.
Definition qproperty.h:699
bool setBinding(const QUntypedPropertyBinding &binding)
Sets the underlying property's binding to binding.
Definition qproperty.h:768
bool isReadOnly() const
Definition qproperty.h:701
QUntypedBindable(Property *p)
Constructs a QUntypedBindable from the property property.
Definition qproperty.h:694
QPropertyNotifier addNotifier(Functor f)
Installs f as a change handler.
Definition qproperty.h:750
constexpr QUntypedBindable(QUntypedPropertyData *d, const QtPrivate::QBindableInterface *i)
Definition qproperty.h:684
QPropertyChangeHandler< Functor > onValueChanged(Functor f) const
Installs f as a change handler.
Definition qproperty.h:735
constexpr QUntypedBindable()=default
Default-constructs a QUntypedBindable.
void observe(QPropertyObserver *observer) const
Definition qproperty.h:723
QMetaType valueMetaType() const
Returns the meta-type of the binding.
QUntypedPropertyBinding()
Constructs a null QUntypedPropertyBinding.
bool isNull() const
Returns true if the QUntypedPropertyBinding is null.
QUntypedPropertyBinding(QMetaType metaType, Functor &&f, const QPropertyBindingSourceLocation &location)
Definition qproperty.h:167
static constexpr QBindableInterface iface
Definition qproperty.h:555
QPropertyBindingPrivate * binding() const
QJSValue expected
Definition qjsengine.cpp:12
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
void printMetaTypeMismatch(QMetaType actual, QMetaType expected)
void printUnsuitableBindableWarning(QAnyStringView prefix, BindableWarnings::Reason reason)
void getter(const QUntypedPropertyData *d, void *value)
void setObserver(const QUntypedPropertyData *d, QPropertyObserver *observer)
QUntypedPropertyBinding setBinding(QUntypedPropertyData *d, const QUntypedPropertyBinding &binding, QPropertyBindingWrapper wrapper)
void setter(QUntypedPropertyData *d, const void *value)
bool bindingWrapper(QMetaType type, QUntypedPropertyData *d, QtPrivate::QPropertyBindingFunction binding, QUntypedPropertyData *temp, void *value)
constexpr QBindableInterface iface
Definition qproperty.h:666
QUntypedPropertyBinding makeBinding(const QUntypedPropertyData *d, const QPropertyBindingSourceLocation &location)
Definition qproperty.h:653
QUntypedPropertyBinding getBinding(const QUntypedPropertyData *d)
constexpr size_t getOffset(size_t o)
\macro QT_NO_KEYWORDS >
std::enable_if_t< std::is_base_of_v< QUntypedPropertyData, T >, bool > IsUntypedPropertyData
bool(*)(QMetaType, QUntypedPropertyData *dataPtr, QPropertyBindingFunction) QPropertyBindingWrapper
Definition qcompare.h:63
auto makePropertyBinding(Functor &&f, const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION, std::enable_if_t< std::is_invocable_v< Functor > > *=nullptr)
Definition qproperty.h:212
Q_CORE_EXPORT void beginPropertyUpdateGroup()
Q_CORE_EXPORT void endPropertyUpdateGroup()
#define Q_NODISCARD_CTOR
#define QT_POST_CXX17_API_IN_EXPORTED_CLASS
#define QT_WARNING_POP
#define QT_WARNING_DISABLE_DEPRECATED
#define QT_WARNING_PUSH
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
quint16 Offset
static const QMetaObjectPrivate * priv(const uint *data)
const QBindingStorage * qGetBindingStorage(const QObject *o)
Definition qobject.h:469
GLint location
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLboolean r
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLenum type
GLenum GLenum GLsizei void GLsizei void * column
GLhandleARB obj
[2]
GLuint GLfloat * val
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
#define QT_PROPERTY_DEFAULT_BINDING_LOCATION
Definition qproperty.h:46
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QT_DEPRECATED_VERSION_X_6_6(text)
unsigned int quint32
Definition qtypes.h:50
size_t quintptr
Definition qtypes.h:167
const char property[13]
Definition qwizard.cpp:101
settings setValue("DataPump/bgcolor", color)
QStorageInfo storage
[1]
QSharedPointer< T > other(t)
[5]
void(*)(const QUntypedPropertyData *d, void *value) Getter
Definition qproperty.h:530
QUntypedPropertyBinding(*)(QUntypedPropertyData *d, const QUntypedPropertyBinding &binding) BindingSetter
Definition qproperty.h:533
void(*)(const QUntypedPropertyData *d, QPropertyObserver *observer) SetObserver
Definition qproperty.h:535
void(*)(QUntypedPropertyData *d, const void *value) Setter
Definition qproperty.h:531
QUntypedPropertyBinding(*)(const QUntypedPropertyData *d, const QPropertyBindingSourceLocation &location) MakeBinding
Definition qproperty.h:534
QUntypedPropertyBinding(*)(const QUntypedPropertyData *d) BindingGetter
Definition qproperty.h:532
static constexpr quintptr MetaTypeAccessorFlag
Definition qproperty.h:545
Definition moc.h:23
void wrapper()