diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index bd623bed18..17dd10e108 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE using namespace QtPrivate; -void QPropertyBasePointer::addObserver(QPropertyObserver *observer) +void QPropertyBindingDataPointer::addObserver(QPropertyObserver *observer) { if (auto *binding = bindingPtr()) { observer->prev = &binding->firstObserver.ptr; @@ -55,7 +55,7 @@ void QPropertyBasePointer::addObserver(QPropertyObserver *observer) observer->next->prev = &observer->next; binding->firstObserver.ptr = observer; } else { - auto firstObserver = reinterpret_cast(ptr->d_ptr & ~QPropertyBase::FlagMask); + auto firstObserver = reinterpret_cast(ptr->d_ptr & ~QPropertyBindingData::FlagMask); observer->prev = reinterpret_cast(&ptr->d_ptr); observer->next = firstObserver; if (observer->next) @@ -183,21 +183,21 @@ QMetaType QUntypedPropertyBinding::valueMetaType() const return d->valueMetaType(); } -QPropertyBase::QPropertyBase(QPropertyBase &&other, void *propertyDataPtr) +QPropertyBindingData::QPropertyBindingData(QPropertyBindingData &&other, void *propertyDataPtr) { std::swap(d_ptr, other.d_ptr); - QPropertyBasePointer d{this}; + QPropertyBindingDataPointer d{this}; d.setFirstObserver(nullptr); if (auto binding = d.bindingPtr()) binding->setProperty(propertyDataPtr); } -void QPropertyBase::moveAssign(QPropertyBase &&other, void *propertyDataPtr) +void QPropertyBindingData::moveAssign(QPropertyBindingData &&other, void *propertyDataPtr) { if (&other == this) return; - QPropertyBasePointer d{this}; + QPropertyBindingDataPointer d{this}; auto observer = d.firstObserver(); d.setFirstObserver(nullptr); @@ -216,9 +216,9 @@ void QPropertyBase::moveAssign(QPropertyBase &&other, void *propertyDataPtr) // The caller will have to notify observers. } -QPropertyBase::~QPropertyBase() +QPropertyBindingData::~QPropertyBindingData() { - QPropertyBasePointer d{this}; + QPropertyBindingDataPointer d{this}; for (auto observer = d.firstObserver(); observer;) { auto next = observer.nextObserver(); observer.unlink(); @@ -228,7 +228,7 @@ QPropertyBase::~QPropertyBase() binding->unlinkAndDeref(); } -QUntypedPropertyBinding QPropertyBase::setBinding(const QUntypedPropertyBinding &binding, +QUntypedPropertyBinding QPropertyBindingData::setBinding(const QUntypedPropertyBinding &binding, void *propertyDataPtr, void *staticObserver, QPropertyObserverCallback staticObserverCallback, @@ -237,7 +237,7 @@ QUntypedPropertyBinding QPropertyBase::setBinding(const QUntypedPropertyBinding QPropertyBindingPrivatePtr oldBinding; QPropertyBindingPrivatePtr newBinding = binding.d; - QPropertyBasePointer d{this}; + QPropertyBindingDataPointer d{this}; QPropertyObserverPointer observer; if (auto *existingBinding = d.bindingPtr()) { @@ -263,15 +263,15 @@ QUntypedPropertyBinding QPropertyBase::setBinding(const QUntypedPropertyBinding } else if (observer) { d.setObservers(observer.ptr); } else { - d_ptr &= ~QPropertyBase::BindingBit; + d_ptr &= ~QPropertyBindingData::BindingBit; } return QUntypedPropertyBinding(oldBinding.data()); } -QPropertyBindingPrivate *QPropertyBase::binding() const +QPropertyBindingPrivate *QPropertyBindingData::binding() const { - QPropertyBasePointer d{this}; + QPropertyBindingDataPointer d{this}; if (auto binding = d.bindingPtr()) return binding; return nullptr; @@ -300,18 +300,18 @@ QPropertyBindingPrivate *QPropertyBindingPrivate::currentlyEvaluatingBinding() return currentBindingEvaluationState ? currentBindingEvaluationState->binding : nullptr; } -void QPropertyBase::evaluateIfDirty() const +void QPropertyBindingData::evaluateIfDirty() const { - QPropertyBasePointer d{this}; + QPropertyBindingDataPointer d{this}; QPropertyBindingPrivate *binding = d.bindingPtr(); if (!binding) return; binding->evaluateIfDirtyAndReturnTrueIfValueChanged(); } -void QPropertyBase::removeBinding() +void QPropertyBindingData::removeBinding() { - QPropertyBasePointer d{this}; + QPropertyBindingDataPointer d{this}; if (auto *existingBinding = d.bindingPtr()) { auto observer = existingBinding->takeObservers(); @@ -322,27 +322,27 @@ void QPropertyBase::removeBinding() } } -void QPropertyBase::registerWithCurrentlyEvaluatingBinding() const +void QPropertyBindingData::registerWithCurrentlyEvaluatingBinding() const { auto currentState = currentBindingEvaluationState; if (!currentState) return; - QPropertyBasePointer d{this}; + QPropertyBindingDataPointer d{this}; QPropertyObserverPointer dependencyObserver = currentState->binding->allocateDependencyObserver(); dependencyObserver.setBindingToMarkDirty(currentState->binding); dependencyObserver.observeProperty(d); } -void QPropertyBase::notifyObservers(void *propertyDataPtr) const +void QPropertyBindingData::notifyObservers(void *propertyDataPtr) const { - QPropertyBasePointer d{this}; + QPropertyBindingDataPointer d{this}; if (QPropertyObserverPointer observer = d.firstObserver()) observer.notify(d.bindingPtr(), propertyDataPtr); } -int QPropertyBasePointer::observerCount() const +int QPropertyBindingDataPointer::observerCount() const { int count = 0; for (auto observer = firstObserver(); observer; observer = observer.nextObserver()) @@ -362,10 +362,10 @@ QPropertyObserver::QPropertyObserver(void *aliasedPropertyPtr) d.setAliasedProperty(aliasedPropertyPtr); } -void QPropertyObserver::setSource(const QPropertyBase &property) +void QPropertyObserver::setSource(const QPropertyBindingData &property) { QPropertyObserverPointer d{this}; - QPropertyBasePointer propPrivate{&property}; + QPropertyBindingDataPointer propPrivate{&property}; d.observeProperty(propPrivate); } @@ -471,7 +471,7 @@ void QPropertyObserverPointer::notify(QPropertyBindingPrivate *triggeringBinding } } -void QPropertyObserverPointer::observeProperty(QPropertyBasePointer property) +void QPropertyObserverPointer::observeProperty(QPropertyBindingDataPointer property) { if (ptr->prev) unlink(); @@ -795,7 +795,7 @@ QString QPropertyBindingError::description() const */ /*! - \fn template QtPrivate::QPropertyBase &QProperty::propertyBase() const + \fn template QtPrivate::QPropertyBindingData &QProperty::bindingData() const \internal */ @@ -1025,7 +1025,7 @@ QString QPropertyBindingError::description() const */ /*! - \fn template QtPrivate::QPropertyBase &QNotifiedProperty::propertyBase() const + \fn template QtPrivate::QPropertyBindingData &QNotifiedProperty::bindingData() const \internal */ diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h index e120e834b2..ef738ccc5a 100644 --- a/src/corelib/kernel/qproperty.h +++ b/src/corelib/kernel/qproperty.h @@ -133,7 +133,7 @@ public: explicit QUntypedPropertyBinding(QPropertyBindingPrivate *priv); private: - friend class QtPrivate::QPropertyBase; + friend class QtPrivate::QPropertyBindingData; friend class QPropertyBindingPrivate; template friend class QPropertyBinding; QPropertyBindingPrivatePtr d; @@ -167,9 +167,9 @@ public: : QUntypedPropertyBinding(QMetaType::fromType(), BindingAdaptor{std::forward(f)}, location) {} - template> + template> QPropertyBinding(const Property &property) - : QUntypedPropertyBinding(property.propertyBase().binding()) + : QUntypedPropertyBinding(property.bindingData().binding()) {} // Internal @@ -187,13 +187,13 @@ namespace Qt { } } -struct QPropertyBasePointer; +struct QPropertyBindingDataPointer; template class QProperty { T val = T(); - QtPrivate::QPropertyBase d; + QtPrivate::QPropertyBindingData d; bool is_equal(const T &v) { if constexpr (QTypeTraits::has_operator_equal_v) { @@ -346,7 +346,7 @@ public: template QPropertyChangeHandler subscribe(Functor f); - const QtPrivate::QPropertyBase &propertyBase() const { return d; } + const QtPrivate::QPropertyBindingData &bindingData() const { return d; } private: void notify() { @@ -370,7 +370,7 @@ template class QNotifiedProperty { T val = T(); - QtPrivate::QPropertyBase d; + QtPrivate::QPropertyBindingData d; bool is_equal(const T &v) { if constexpr (QTypeTraits::has_operator_equal_v) { @@ -532,7 +532,7 @@ public: template QPropertyChangeHandler subscribe(Functor f); - const QtPrivate::QPropertyBase &propertyBase() const { return d; } + const QtPrivate::QPropertyBindingData &bindingData() const { return d; } private: void notify(Class *owner, T *oldValue=nullptr) { @@ -566,9 +566,9 @@ public: QPropertyObserver &operator=(QPropertyObserver &&other); ~QPropertyObserver(); - template().propertyBase()), QtPrivate::QPropertyBase &>>> + template().bindingData()), QtPrivate::QPropertyBindingData &>>> void setSource(const Property &property) - { setSource(property.propertyBase()); } + { setSource(property.bindingData()); } protected: QPropertyObserver(void (*callback)(QPropertyObserver*, void *)); @@ -581,7 +581,7 @@ protected: } private: - void setSource(const QtPrivate::QPropertyBase &property); + void setSource(const QtPrivate::QPropertyBindingData &property); QTaggedPointer next; // prev is a pointer to the "next" element within the previous node, or to the "firstObserverPtr" if it is the @@ -598,7 +598,7 @@ private: QPropertyObserver &operator=(const QPropertyObserver &) = delete; friend struct QPropertyObserverPointer; - friend struct QPropertyBasePointer; + friend struct QPropertyBindingDataPointer; friend class QPropertyBindingPrivate; }; @@ -616,7 +616,7 @@ public: { } - template> + template> QPropertyChangeHandler(const Property &property, Functor handler) : QPropertyObserver([](QPropertyObserver *self, void *) { auto This = static_cast*>(self); diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h index 4cb55f8b47..6e8f4b4516 100644 --- a/src/corelib/kernel/qproperty_p.h +++ b/src/corelib/kernel/qproperty_p.h @@ -65,21 +65,21 @@ QT_BEGIN_NAMESPACE // we need to allow the compiler to inline where it makes sense. // This is a helper "namespace" -struct Q_AUTOTEST_EXPORT QPropertyBasePointer +struct Q_AUTOTEST_EXPORT QPropertyBindingDataPointer { - const QtPrivate::QPropertyBase *ptr = nullptr; + const QtPrivate::QPropertyBindingData *ptr = nullptr; QPropertyBindingPrivate *bindingPtr() const { - if (ptr->d_ptr & QtPrivate::QPropertyBase::BindingBit) - return reinterpret_cast(ptr->d_ptr & ~QtPrivate::QPropertyBase::FlagMask); + if (ptr->d_ptr & QtPrivate::QPropertyBindingData::BindingBit) + return reinterpret_cast(ptr->d_ptr & ~QtPrivate::QPropertyBindingData::FlagMask); return nullptr; } void setObservers(QPropertyObserver *observer) { observer->prev = reinterpret_cast(&(ptr->d_ptr)); - ptr->d_ptr = (reinterpret_cast(observer) & ~QtPrivate::QPropertyBase::FlagMask); + ptr->d_ptr = (reinterpret_cast(observer) & ~QtPrivate::QPropertyBindingData::FlagMask); } void addObserver(QPropertyObserver *observer); void setFirstObserver(QPropertyObserver *observer); @@ -88,9 +88,9 @@ struct Q_AUTOTEST_EXPORT QPropertyBasePointer int observerCount() const; template - static QPropertyBasePointer get(QProperty &property) + static QPropertyBindingDataPointer get(QProperty &property) { - return QPropertyBasePointer{&property.propertyBase()}; + return QPropertyBindingDataPointer{&property.bindingData()}; } }; @@ -106,7 +106,7 @@ struct QPropertyObserverPointer void setAliasedProperty(void *propertyPtr); void notify(QPropertyBindingPrivate *triggeringBinding, void *propertyDataPtr); - void observeProperty(QPropertyBasePointer property); + void observeProperty(QPropertyBindingDataPointer property); explicit operator bool() const { return ptr != nullptr; } @@ -132,7 +132,7 @@ struct BindingEvaluationState class Q_CORE_EXPORT QPropertyBindingPrivate : public QSharedData { private: - friend struct QPropertyBasePointer; + friend struct QPropertyBindingDataPointer; using ObserverArray = std::array; @@ -255,20 +255,20 @@ public: static QPropertyBindingPrivate *currentlyEvaluatingBinding(); }; -inline void QPropertyBasePointer::setFirstObserver(QPropertyObserver *observer) +inline void QPropertyBindingDataPointer::setFirstObserver(QPropertyObserver *observer) { if (auto *binding = bindingPtr()) { binding->firstObserver.ptr = observer; return; } - ptr->d_ptr = reinterpret_cast(observer) | (ptr->d_ptr & QtPrivate::QPropertyBase::FlagMask); + ptr->d_ptr = reinterpret_cast(observer) | (ptr->d_ptr & QtPrivate::QPropertyBindingData::FlagMask); } -inline QPropertyObserverPointer QPropertyBasePointer::firstObserver() const +inline QPropertyObserverPointer QPropertyBindingDataPointer::firstObserver() const { if (auto *binding = bindingPtr()) return binding->firstObserver; - return {reinterpret_cast(ptr->d_ptr & ~QtPrivate::QPropertyBase::FlagMask)}; + return {reinterpret_cast(ptr->d_ptr & ~QtPrivate::QPropertyBindingData::FlagMask)}; } QT_END_NAMESPACE diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h index acdf405648..bab4162472 100644 --- a/src/corelib/kernel/qpropertyprivate.h +++ b/src/corelib/kernel/qpropertyprivate.h @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE class QUntypedPropertyBinding; class QPropertyBindingPrivate; using QPropertyBindingPrivatePtr = QExplicitlySharedDataPointer; -struct QPropertyBasePointer; +struct QPropertyBindingDataPointer; namespace QtPrivate { @@ -74,21 +74,21 @@ using QPropertyGuardFunction = bool(*)(QMetaType, void *dataPtr, QPropertyBindingFunction, void *owner); using QPropertyObserverCallback = void (*)(void *, void *); -class Q_CORE_EXPORT QPropertyBase +class Q_CORE_EXPORT QPropertyBindingData { // Mutable because the address of the observer of the currently evaluating binding is stored here, for // notification later when the value changes. mutable quintptr d_ptr = 0; - friend struct QT_PREPEND_NAMESPACE(QPropertyBasePointer); + friend struct QT_PREPEND_NAMESPACE(QPropertyBindingDataPointer); public: - QPropertyBase() = default; - Q_DISABLE_COPY(QPropertyBase) - QPropertyBase(QPropertyBase &&other) = delete; - QPropertyBase(QPropertyBase &&other, void *propertyDataPtr); - QPropertyBase &operator=(QPropertyBase &&other) = delete; - ~QPropertyBase(); + QPropertyBindingData() = default; + Q_DISABLE_COPY(QPropertyBindingData) + QPropertyBindingData(QPropertyBindingData &&other) = delete; + QPropertyBindingData(QPropertyBindingData &&other, void *propertyDataPtr); + QPropertyBindingData &operator=(QPropertyBindingData &&other) = delete; + ~QPropertyBindingData(); - void moveAssign(QPropertyBase &&other, void *propertyDataPtr); + void moveAssign(QPropertyBindingData &&other, void *propertyDataPtr); bool hasBinding() const { return d_ptr & BindingBit; } diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index ebb8980d61..97c5a755db 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -108,30 +108,30 @@ void tst_QProperty::multipleDependencies() QProperty sum; sum = Qt::makePropertyBinding([&]() { return firstDependency + secondDependency; }); - QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 0); - QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 0); + QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 0); + QCOMPARE(QPropertyBindingDataPointer::get(secondDependency).observerCount(), 0); QCOMPARE(sum.value(), int(3)); - QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); - QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(secondDependency).observerCount(), 1); firstDependency = 10; QCOMPARE(sum.value(), int(12)); - QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); - QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(secondDependency).observerCount(), 1); secondDependency = 20; QCOMPARE(sum.value(), int(30)); - QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); - QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(secondDependency).observerCount(), 1); firstDependency = 1; secondDependency = 1; QCOMPARE(sum.value(), int(2)); - QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); - QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(secondDependency).observerCount(), 1); } void tst_QProperty::bindingWithDeletedDependency() @@ -190,13 +190,13 @@ void tst_QProperty::bindingAfterUse() propThatUsesFirstProp = Qt::makePropertyBinding(propWithBindingLater); QCOMPARE(propThatUsesFirstProp.value(), int(1)); - QCOMPARE(QPropertyBasePointer::get(propWithBindingLater).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(propWithBindingLater).observerCount(), 1); QProperty injectedValue(42); propWithBindingLater = Qt::makePropertyBinding(injectedValue); QCOMPARE(propThatUsesFirstProp.value(), int(42)); - QCOMPARE(QPropertyBasePointer::get(propWithBindingLater).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(propWithBindingLater).observerCount(), 1); } void tst_QProperty::switchBinding() @@ -227,12 +227,12 @@ void tst_QProperty::avoidDependencyAllocationAfterFirstEval() QCOMPARE(propWithBinding.value(), int(11)); - QVERIFY(QPropertyBasePointer::get(propWithBinding).bindingPtr()); - QCOMPARE(QPropertyBasePointer::get(propWithBinding).bindingPtr()->dependencyObserverCount, 2u); + QVERIFY(QPropertyBindingDataPointer::get(propWithBinding).bindingPtr()); + QCOMPARE(QPropertyBindingDataPointer::get(propWithBinding).bindingPtr()->dependencyObserverCount, 2u); firstDependency = 100; QCOMPARE(propWithBinding.value(), int(110)); - QCOMPARE(QPropertyBasePointer::get(propWithBinding).bindingPtr()->dependencyObserverCount, 2u); + QCOMPARE(QPropertyBindingDataPointer::get(propWithBinding).bindingPtr()->dependencyObserverCount, 2u); } void tst_QProperty::propertyArrays() @@ -348,18 +348,18 @@ void tst_QProperty::moveNotifies() QCOMPARE(finalProp1.value(), 1); QCOMPARE(finalProp2.value(), 1); - QCOMPARE(QPropertyBasePointer::get(propertyInTheMiddle).observerCount(), 2); + QCOMPARE(QPropertyBindingDataPointer::get(propertyInTheMiddle).observerCount(), 2); QProperty other = Qt::makePropertyBinding(second); QCOMPARE(other.value(), 2); QProperty otherDep = Qt::makePropertyBinding(other); QCOMPARE(otherDep.value(), 2); - QCOMPARE(QPropertyBasePointer::get(other).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(other).observerCount(), 1); propertyInTheMiddle = std::move(other); - QCOMPARE(QPropertyBasePointer::get(other).observerCount(), 0); + QCOMPARE(QPropertyBindingDataPointer::get(other).observerCount(), 0); QCOMPARE(finalProp1.value(), 2); QCOMPARE(finalProp2.value(), 2); @@ -371,11 +371,11 @@ void tst_QProperty::moveCtor() QProperty intermediate = Qt::makePropertyBinding(first); QCOMPARE(intermediate.value(), 1); - QCOMPARE(QPropertyBasePointer::get(first).observerCount(), 1); + QCOMPARE(QPropertyBindingDataPointer::get(first).observerCount(), 1); QProperty targetProp(std::move(first)); - QCOMPARE(QPropertyBasePointer::get(targetProp).observerCount(), 0); + QCOMPARE(QPropertyBindingDataPointer::get(targetProp).observerCount(), 0); } void tst_QProperty::changeHandler()