From 524c187af3bcd532f345eed61be7bd99732d0505 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Tue, 11 May 2021 10:52:34 +0200 Subject: [PATCH] QProperty: Cleanup QPropertyAlias leftovers This removes traces of QPropertyAlias which is internal API which is a) not really working even before this change (no compatibility with QBindableInterface due to QPropertyAlias not being derived from QUntypedPropertyData) b) not used anywhere For BIC reasons, we need to keep some methods still around until Qt 7, though. Change-Id: I5bb4735a4c88cba275dc2cc6e29a46ca09622059 Reviewed-by: Qt CI Bot Reviewed-by: Ulf Hermann --- src/corelib/kernel/qproperty.cpp | 20 +---- src/corelib/kernel/qproperty.h | 4 +- src/corelib/kernel/qproperty_p.h | 1 - .../kernel/qproperty/tst_qproperty.cpp | 84 ------------------- 4 files changed, 4 insertions(+), 105 deletions(-) diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index a1b2f83c5b..d8176a845a 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -571,10 +571,9 @@ QPropertyObserver::QPropertyObserver(ChangeHandler changeHandler) d.setChangeHandler(changeHandler); } -QPropertyObserver::QPropertyObserver(QUntypedPropertyData *aliasedPropertyPtr) +QPropertyObserver::QPropertyObserver(QUntypedPropertyData *) { - QPropertyObserverPointer d{this}; - d.setAliasedProperty(aliasedPropertyPtr); + // ### Qt 7: Remove, currently left for binary compatibility } /*! \internal @@ -625,8 +624,6 @@ QPropertyObserver &QPropertyObserver::operator=(QPropertyObserver &&other) noexc void QPropertyObserverPointer::unlink() { - if (ptr->next.tag() == QPropertyObserver::ObserverNotifiesAlias) - ptr->aliasedPropertyData = nullptr; if (ptr->next) ptr->next->prev = ptr->prev; if (ptr->prev) @@ -642,13 +639,6 @@ void QPropertyObserverPointer::setChangeHandler(QPropertyObserver::ChangeHandler ptr->next.setTag(QPropertyObserver::ObserverNotifiesChangeHandler); } -void QPropertyObserverPointer::setAliasedProperty(QUntypedPropertyData *property) -{ - Q_ASSERT(ptr->next.tag() != QPropertyObserver::ObserverIsPlaceholder); - ptr->aliasedPropertyData = property; - ptr->next.setTag(QPropertyObserver::ObserverNotifiesAlias); -} - void QPropertyObserverPointer::setBindingToNotify(QPropertyBindingPrivate *binding) { Q_ASSERT(ptr->next.tag() != QPropertyObserver::ObserverIsPlaceholder); @@ -708,9 +698,6 @@ void QPropertyObserverPointer::notify(QUntypedPropertyData *propertyDataPtr) */ while (observer) { QPropertyObserver *next = observer->next.data(); - - char preventBug[1] = {'\0'}; // QTBUG-87245 - Q_UNUSED(preventBug); switch (QPropertyObserver::ObserverTag(observer->next.tag())) { case QPropertyObserver::ObserverNotifiesChangeHandler: { @@ -734,11 +721,10 @@ void QPropertyObserverPointer::notify(QUntypedPropertyData *propertyDataPtr) next = protector.next(); break; } - case QPropertyObserver::ObserverNotifiesAlias: - break; case QPropertyObserver::ObserverIsPlaceholder: // recursion is already properly handled somewhere else break; + default: Q_UNREACHABLE(); } observer = next; } diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h index f5513be73f..a2c2875a12 100644 --- a/src/corelib/kernel/qproperty.h +++ b/src/corelib/kernel/qproperty.h @@ -215,7 +215,6 @@ public: enum ObserverTag { ObserverNotifiesBinding, // observer was installed to notify bindings that obsverved property changed ObserverNotifiesChangeHandler, // observer is a change handler, which runs on every change - ObserverNotifiesAlias, // used for QPropertyAlias ObserverIsPlaceholder // the observer before this one is currently evaluated in QPropertyObserver::notifyObservers. }; protected: @@ -237,7 +236,6 @@ private: union { QPropertyBindingPrivate *binding = nullptr; ChangeHandler changeHandler; - QUntypedPropertyData *aliasedPropertyData; }; }; @@ -260,7 +258,7 @@ protected: QUntypedPropertyData *aliasedProperty() const { - return aliasedPropertyData; + return nullptr; } private: diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h index d00094c54f..32ff31166c 100644 --- a/src/corelib/kernel/qproperty_p.h +++ b/src/corelib/kernel/qproperty_p.h @@ -105,7 +105,6 @@ struct QPropertyObserverPointer void setBindingToNotify(QPropertyBindingPrivate *binding); void setChangeHandler(QPropertyObserver::ChangeHandler changeHandler); - void setAliasedProperty(QUntypedPropertyData *propertyPtr); void notify(QUntypedPropertyData *propertyDataPtr); #ifndef QT_NO_DEBUG diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index b1f5a780a6..7a214acbc4 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -83,7 +83,6 @@ private slots: void genericPropertyBindingBool(); void setBindingFunctor(); void multipleObservers(); - void propertyAlias(); void arrowAndStarOperator(); void notifiedProperty(); void typeNoOperatorEqual(); @@ -97,7 +96,6 @@ private slots: void qobjectObservers(); void compatBindings(); void metaProperty(); - void aliasOnMetaProperty(); void modifyObserverListWhileIterating(); void compatPropertyNoDobuleNotification(); @@ -791,52 +789,6 @@ void tst_QProperty::multipleObservers() QCOMPARE(property.value(), 22); } -void tst_QProperty::propertyAlias() -{ - QScopedPointer> property(new QProperty); - property->setValue(5); - QPropertyAlias alias(property.get()); - QVERIFY(alias.isValid()); - QCOMPARE(alias.value(), 5); - - int value1 = 1; - auto changeHandler = alias.onValueChanged([&]() { value1 = alias.value(); }); - QCOMPARE(value1, 1); - - int value2 = 2; - auto subscribeHandler = alias.subscribe([&]() { value2 = alias.value(); }); - QCOMPARE(value2, 5); - - alias.setValue(6); - QVERIFY(alias.isValid()); - QCOMPARE(alias.value(), 6); - QCOMPARE(value1, 6); - QCOMPARE(value2, 6); - - alias.setBinding([]() { return 12; }); - QCOMPARE(value1, 12); - QCOMPARE(value2, 12); - QCOMPARE(alias.value(), 12); - - alias.setValue(22); - QCOMPARE(value1, 22); - QCOMPARE(value2, 22); - QCOMPARE(alias.value(), 22); - - property.reset(); - - QVERIFY(!alias.isValid()); - QCOMPARE(alias.value(), int()); - QCOMPARE(value1, 22); - QCOMPARE(value2, 22); - - // Does not crash - alias.setValue(25); - QCOMPARE(alias.value(), int()); - QCOMPARE(value1, 22); - QCOMPARE(value2, 22); -} - void tst_QProperty::arrowAndStarOperator() { QString str("Hello"); @@ -1445,42 +1397,6 @@ void tst_QProperty::metaProperty() QCOMPARE(object.fooData.value(), 1); } -void tst_QProperty::aliasOnMetaProperty() -{ - MyQObject object; - QPropertyAlias alias(object.bindableFoo()); - - QVERIFY(alias.isValid()); - QCOMPARE(alias.value(), object.foo()); - QVERIFY(!alias.hasBinding()); - - object.setFoo(42); - QCOMPARE(alias.value(), 42); - - auto f = [&object]() -> int { - return object.barData; - }; - object.bindableFoo().setBinding(f); - QVERIFY(alias.hasBinding()); - QCOMPARE(alias.value(), object.bar()); - - object.setBar(111); - QCOMPARE(alias.value(), 111); - - int changedCount = 0; - auto observer = alias.onValueChanged([&changedCount]() { ++changedCount; }); - QCOMPARE(changedCount, 0); - object.setBar(666); - QCOMPARE(changedCount, 1); - - alias.setBinding([&object]() { return object.read(); }); - QCOMPARE(changedCount, 2); - QCOMPARE(alias.value(), 0); - object.readData = 100; - QCOMPARE(changedCount, 3); - QCOMPARE(alias.value(), 100); -} - void tst_QProperty::modifyObserverListWhileIterating() { struct DestructingObserver : QPropertyObserver {