From f69bcf8d806dbfd1af673f2f8e3b803c7a76361c Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Wed, 8 Feb 2023 12:38:23 +0100 Subject: [PATCH] Deprecate QPropertyAlias That use case for the class never materialized, and it was actually meant for internal use. However, we put it into the public header, so we cannot remove it (and while undocumented, someone actually used it at some point, compare e4d62651c278c468f71ce097979bc1183ffd0713). Mark it as deprecated instead so that it can be finally be removed in Qt 7. Change-Id: I058c5831a44610121fbec6eaddebd8b33d4a16c9 Reviewed-by: Ulf Hermann --- src/corelib/kernel/qproperty.cpp | 2 ++ src/corelib/kernel/qproperty.h | 13 +++++++++++-- src/corelib/kernel/qproperty_p.h | 6 ++++++ .../auto/corelib/kernel/qproperty/tst_qproperty.cpp | 4 ++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index f54cd732789..4a8874caf4b 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -641,11 +641,13 @@ QPropertyObserver::QPropertyObserver(ChangeHandler changeHandler) d.setChangeHandler(changeHandler); } +#if QT_DEPRECATED_SINCE(6, 6) QPropertyObserver::QPropertyObserver(QUntypedPropertyData *data) { aliasData = data; next.setTag(ObserverIsAlias); } +#endif /*! \internal */ diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h index 297a3fe9740..5d8b908f31a 100644 --- a/src/corelib/kernel/qproperty.h +++ b/src/corelib/kernel/qproperty.h @@ -217,7 +217,9 @@ public: ObserverNotifiesBinding, // observer was installed to notify bindings that obsverved property changed ObserverNotifiesChangeHandler, // observer is a change handler, which runs on every change ObserverIsPlaceholder, // the observer before this one is currently evaluated in QPropertyObserver::notifyObservers. +#if QT_DEPRECATED_SINCE(6, 6) ObserverIsAlias +#endif }; protected: using ChangeHandler = void (*)(QPropertyObserver*, QUntypedPropertyData *); @@ -257,7 +259,9 @@ public: protected: QPropertyObserver(ChangeHandler changeHandler); - QPropertyObserver(QUntypedPropertyData *aliasedPropertyPtr); +#if QT_DEPRECATED_SINCE(6, 6) + QT_DEPRECATED QPropertyObserver(QUntypedPropertyData *aliasedPropertyPtr); +#endif QUntypedPropertyData *aliasedProperty() const { @@ -867,13 +871,16 @@ public: } }; +#if QT_DEPRECATED_SINCE(6, 6) template -class QPropertyAlias : public QPropertyObserver +class QT_DEPRECATED_X("Class was only meant for internal use, use a QProperty and add a binding to the target") +QPropertyAlias : public QPropertyObserver { Q_DISABLE_COPY_MOVE(QPropertyAlias) const QtPrivate::QBindableInterface *iface = nullptr; public: + QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED QPropertyAlias(QProperty *property) : QPropertyObserver(property), iface(&QtPrivate::QBindableInterfaceForProperty>::iface) @@ -989,7 +996,9 @@ public: { return aliasedProperty() != nullptr; } + QT_WARNING_POP }; +#endif template class QObjectBindableProperty : public QPropertyData diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h index 42daca036a7..3ae1bfcc23b 100644 --- a/src/corelib/kernel/qproperty_p.h +++ b/src/corelib/kernel/qproperty_p.h @@ -124,13 +124,17 @@ struct QPropertyObserverPointer void unlink() { unlink_common(); +#if QT_DEPRECATED_SINCE(6, 6) if (ptr->next.tag() == QPropertyObserver::ObserverIsAlias) ptr->aliasData = nullptr; +#endif } void unlink_fast() { +#if QT_DEPRECATED_SINCE(6, 6) Q_ASSERT(ptr->next.tag() != QPropertyObserver::ObserverIsAlias); +#endif unlink_common(); } @@ -881,8 +885,10 @@ inline void QPropertyObserverPointer::notify(QUntypedPropertyData *propertyDataP case QPropertyObserver::ObserverIsPlaceholder: // recursion is already properly handled somewhere else break; +#if QT_DEPRECATED_SINCE(6, 6) case QPropertyObserver::ObserverIsAlias: break; +#endif default: Q_UNREACHABLE(); } observer = next; diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index 335cc65b5ab..dbdcaa1a1b2 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -2240,6 +2240,8 @@ void tst_QProperty::selfBindingShouldNotCrash() void tst_QProperty::qpropertyAlias() { +#if QT_DEPRECATED_SINCE(6, 6) + QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED std::unique_ptr> i {new QProperty}; QPropertyAlias alias(i.get()); QVERIFY(alias.isValid()); @@ -2251,6 +2253,8 @@ void tst_QProperty::qpropertyAlias() QCOMPARE(alias.value(), 42); i.reset(); QVERIFY(!alias.isValid()); + QT_WARNING_POP +#endif } void tst_QProperty::scheduleNotify()