Cleanups: Rename some classes

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>
bb10
Lars Knoll 2020-08-21 12:56:11 +02:00
parent 0c89721716
commit e638e8a28d
5 changed files with 83 additions and 83 deletions

View File

@ -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<QPropertyObserver*>(ptr->d_ptr & ~QPropertyBase::FlagMask);
auto firstObserver = reinterpret_cast<QPropertyObserver*>(ptr->d_ptr & ~QPropertyBindingData::FlagMask);
observer->prev = reinterpret_cast<QPropertyObserver**>(&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 <typename T> QtPrivate::QPropertyBase &QProperty<T>::propertyBase() const
\fn template <typename T> QtPrivate::QPropertyBindingData &QProperty<T>::bindingData() const
\internal
*/
@ -1025,7 +1025,7 @@ QString QPropertyBindingError::description() const
*/
/*!
\fn template <typename T> QtPrivate::QPropertyBase &QNotifiedProperty<T, Callback>::propertyBase() const
\fn template <typename T> QtPrivate::QPropertyBindingData &QNotifiedProperty<T, Callback>::bindingData() const
\internal
*/

View File

@ -133,7 +133,7 @@ public:
explicit QUntypedPropertyBinding(QPropertyBindingPrivate *priv);
private:
friend class QtPrivate::QPropertyBase;
friend class QtPrivate::QPropertyBindingData;
friend class QPropertyBindingPrivate;
template <typename> friend class QPropertyBinding;
QPropertyBindingPrivatePtr d;
@ -167,9 +167,9 @@ public:
: QUntypedPropertyBinding(QMetaType::fromType<PropertyType>(), BindingAdaptor<Functor>{std::forward<Functor>(f)}, location)
{}
template<typename Property, typename = std::void_t<decltype(&Property::propertyBase)>>
template<typename Property, typename = std::void_t<decltype(&Property::bindingData)>>
QPropertyBinding(const Property &property)
: QUntypedPropertyBinding(property.propertyBase().binding())
: QUntypedPropertyBinding(property.bindingData().binding())
{}
// Internal
@ -187,13 +187,13 @@ namespace Qt {
}
}
struct QPropertyBasePointer;
struct QPropertyBindingDataPointer;
template <typename T>
class QProperty
{
T val = T();
QtPrivate::QPropertyBase d;
QtPrivate::QPropertyBindingData d;
bool is_equal(const T &v)
{
if constexpr (QTypeTraits::has_operator_equal_v<T>) {
@ -346,7 +346,7 @@ public:
template<typename Functor>
QPropertyChangeHandler<Functor> 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 <typename T, auto Callback, auto ValueGuard=nullptr>
class QNotifiedProperty
{
T val = T();
QtPrivate::QPropertyBase d;
QtPrivate::QPropertyBindingData d;
bool is_equal(const T &v)
{
if constexpr (QTypeTraits::has_operator_equal_v<T>) {
@ -532,7 +532,7 @@ public:
template<typename Functor>
QPropertyChangeHandler<Functor> 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<typename Property, typename = std::enable_if_t<std::is_same_v<decltype(std::declval<Property>().propertyBase()), QtPrivate::QPropertyBase &>>>
template<typename Property, typename = std::enable_if_t<std::is_same_v<decltype(std::declval<Property>().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<QPropertyObserver, ObserverTag> 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<typename Property, typename = std::void_t<decltype(&Property::propertyBase)>>
template<typename Property, typename = std::void_t<decltype(&Property::bindingData)>>
QPropertyChangeHandler(const Property &property, Functor handler)
: QPropertyObserver([](QPropertyObserver *self, void *) {
auto This = static_cast<QPropertyChangeHandler<Functor>*>(self);

View File

@ -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<QPropertyBindingPrivate*>(ptr->d_ptr & ~QtPrivate::QPropertyBase::FlagMask);
if (ptr->d_ptr & QtPrivate::QPropertyBindingData::BindingBit)
return reinterpret_cast<QPropertyBindingPrivate*>(ptr->d_ptr & ~QtPrivate::QPropertyBindingData::FlagMask);
return nullptr;
}
void setObservers(QPropertyObserver *observer)
{
observer->prev = reinterpret_cast<QPropertyObserver**>(&(ptr->d_ptr));
ptr->d_ptr = (reinterpret_cast<quintptr>(observer) & ~QtPrivate::QPropertyBase::FlagMask);
ptr->d_ptr = (reinterpret_cast<quintptr>(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 <typename T>
static QPropertyBasePointer get(QProperty<T> &property)
static QPropertyBindingDataPointer get(QProperty<T> &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<QPropertyObserver, 4>;
@ -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<quintptr>(observer) | (ptr->d_ptr & QtPrivate::QPropertyBase::FlagMask);
ptr->d_ptr = reinterpret_cast<quintptr>(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<QPropertyObserver*>(ptr->d_ptr & ~QtPrivate::QPropertyBase::FlagMask)};
return {reinterpret_cast<QPropertyObserver*>(ptr->d_ptr & ~QtPrivate::QPropertyBindingData::FlagMask)};
}
QT_END_NAMESPACE

View File

@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE
class QUntypedPropertyBinding;
class QPropertyBindingPrivate;
using QPropertyBindingPrivatePtr = QExplicitlySharedDataPointer<QPropertyBindingPrivate>;
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; }

View File

@ -108,30 +108,30 @@ void tst_QProperty::multipleDependencies()
QProperty<int> 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<int> 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<int> other = Qt::makePropertyBinding(second);
QCOMPARE(other.value(), 2);
QProperty<int> 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<int> intermediate = Qt::makePropertyBinding(first);
QCOMPARE(intermediate.value(), 1);
QCOMPARE(QPropertyBasePointer::get(first).observerCount(), 1);
QCOMPARE(QPropertyBindingDataPointer::get(first).observerCount(), 1);
QProperty<int> targetProp(std::move(first));
QCOMPARE(QPropertyBasePointer::get(targetProp).observerCount(), 0);
QCOMPARE(QPropertyBindingDataPointer::get(targetProp).observerCount(), 0);
}
void tst_QProperty::changeHandler()