QProperty: clean up unnecessary sentinel class
Instead of introducing the nested class InheritsQUntypedPropertyData as a sentinel class for inheritance check, we can use BinaryTypeTrait to handle the check. By doing this, we no longer need to maintain the nested class. Change-Id: Ie3aae976015d5fae6b6d072cad6ee52cd30b769d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
ead408ca1b
commit
311f889632
@ -263,7 +263,8 @@ public:
|
||||
QPropertyObserver &operator=(QPropertyObserver &&other) noexcept;
|
||||
~QPropertyObserver();
|
||||
|
||||
template<typename Property, typename = typename Property::InheritsQUntypedPropertyData>
|
||||
template <typename Property,
|
||||
typename = std::enable_if_t<std::is_base_of_v<QUntypedPropertyData, Property>>>
|
||||
void setSource(const Property &property)
|
||||
{ setSource(property.bindingData()); }
|
||||
void setSource(const QtPrivate::QPropertyBindingData &property);
|
||||
@ -302,7 +303,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Property, typename = typename Property::InheritsQUntypedPropertyData>
|
||||
template <typename Property,
|
||||
typename = std::enable_if_t<std::is_base_of_v<QUntypedPropertyData, Property>>>
|
||||
Q_NODISCARD_CTOR
|
||||
QPropertyChangeHandler(const Property &property, Functor handler)
|
||||
: QPropertyObserver([](QPropertyObserver *self, QUntypedPropertyData *) {
|
||||
@ -332,7 +334,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Functor, typename Property, typename = typename Property::InheritsQUntypedPropertyData>
|
||||
template <typename Functor, typename Property,
|
||||
typename = std::enable_if_t<std::is_base_of_v<QUntypedPropertyData, Property>>>
|
||||
Q_NODISCARD_CTOR
|
||||
QPropertyNotifier(const Property &property, Functor handler)
|
||||
: QPropertyObserver([](QPropertyObserver *self, QUntypedPropertyData *) {
|
||||
@ -906,7 +909,8 @@ public:
|
||||
iface->setObserver(aliasedProperty(), this);
|
||||
}
|
||||
|
||||
template<typename Property, typename = typename Property::InheritsQUntypedPropertyData>
|
||||
template <typename Property,
|
||||
typename = std::enable_if_t<std::is_base_of_v<QUntypedPropertyData, Property>>>
|
||||
QPropertyAlias(Property *property)
|
||||
: QPropertyObserver(property),
|
||||
iface(&QtPrivate::QBindableInterfaceForProperty<Property>::iface)
|
||||
|
@ -125,8 +125,13 @@ struct QPropertyObserverPointer;
|
||||
class QUntypedPropertyData
|
||||
{
|
||||
public:
|
||||
#if QT_DEPRECATED_SINCE(6, 8)
|
||||
// sentinel to check whether a class inherits QUntypedPropertyData
|
||||
struct InheritsQUntypedPropertyData {};
|
||||
struct QT_DEPRECATED_VERSION_X_6_8("Use std::is_base_of instead.")
|
||||
InheritsQUntypedPropertyData
|
||||
{
|
||||
};
|
||||
#endif
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -29,6 +29,7 @@ class tst_QProperty : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void inheritQUntypedPropertyData();
|
||||
void functorBinding();
|
||||
void basicDependencies();
|
||||
void multipleDependencies();
|
||||
@ -109,6 +110,59 @@ private slots:
|
||||
void propertyUpdateViaSignaledProperty();
|
||||
};
|
||||
|
||||
namespace {
|
||||
template <class T>
|
||||
constexpr auto isDerivedFromQUntypedPropertyData = std::is_base_of_v<QUntypedPropertyData, T>;
|
||||
|
||||
template <typename Property>
|
||||
constexpr auto isDerivedFromQUntypedPropertyDataFunc(const Property &property)
|
||||
{
|
||||
Q_UNUSED(property);
|
||||
return isDerivedFromQUntypedPropertyData<Property>;
|
||||
}
|
||||
|
||||
template <typename Property>
|
||||
constexpr auto isDerivedFromQUntypedPropertyDataFunc(Property *property)
|
||||
{
|
||||
Q_UNUSED(property);
|
||||
return isDerivedFromQUntypedPropertyData<Property>;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void tst_QProperty::inheritQUntypedPropertyData()
|
||||
{
|
||||
class propertyPublic : public QUntypedPropertyData
|
||||
{
|
||||
};
|
||||
class propertyPrivate : private QUntypedPropertyData
|
||||
{
|
||||
};
|
||||
|
||||
// Compile time test
|
||||
static_assert(isDerivedFromQUntypedPropertyData<propertyPublic>);
|
||||
static_assert(isDerivedFromQUntypedPropertyData<propertyPrivate>);
|
||||
static_assert(isDerivedFromQUntypedPropertyData<QPropertyData<int>>);
|
||||
static_assert(isDerivedFromQUntypedPropertyData<QProperty<int>>);
|
||||
|
||||
// Run time test
|
||||
propertyPublic _propertyPublic;
|
||||
propertyPrivate _propertyPrivate;
|
||||
QPropertyData<int> qpropertyData;
|
||||
QProperty<int> qproperty;
|
||||
std::unique_ptr<propertyPublic> _propertyPublicPtr{ new propertyPublic };
|
||||
std::unique_ptr<propertyPrivate> _propertyPrivatePtr{ new propertyPrivate };
|
||||
std::unique_ptr<QPropertyData<int>> qpropertyDataPtr{ new QPropertyData<int> };
|
||||
std::unique_ptr<QProperty<int>> qpropertyPtr{ new QProperty<int> };
|
||||
QVERIFY(isDerivedFromQUntypedPropertyDataFunc(_propertyPublic));
|
||||
QVERIFY(isDerivedFromQUntypedPropertyDataFunc(_propertyPrivate));
|
||||
QVERIFY(isDerivedFromQUntypedPropertyDataFunc(qpropertyData));
|
||||
QVERIFY(isDerivedFromQUntypedPropertyDataFunc(qproperty));
|
||||
QVERIFY(isDerivedFromQUntypedPropertyDataFunc(_propertyPublicPtr.get()));
|
||||
QVERIFY(isDerivedFromQUntypedPropertyDataFunc(_propertyPrivatePtr.get()));
|
||||
QVERIFY(isDerivedFromQUntypedPropertyDataFunc(qpropertyDataPtr.get()));
|
||||
QVERIFY(isDerivedFromQUntypedPropertyDataFunc(qpropertyPtr.get()));
|
||||
}
|
||||
|
||||
void tst_QProperty::functorBinding()
|
||||
{
|
||||
QProperty<int> property([]() { return 42; });
|
||||
|
Loading…
x
Reference in New Issue
Block a user