Skip to content

Commit

Permalink
Fix usage of std::enable_if_t to SFINAE out QProperty APIs
Browse files Browse the repository at this point in the history
Declare an IfUntypedPropertyData alias and use that consistently.

Amends 311f889.

Pick-to: 6.7
Change-Id: If36ef8e2f9ce25e0ffe7b4b448c31ea5866acfc3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
  • Loading branch information
vohi committed Feb 2, 2024
1 parent 4b64df5 commit 216af5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
11 changes: 4 additions & 7 deletions src/corelib/kernel/qproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ class Q_CORE_EXPORT QPropertyObserver : public QPropertyObserverBase
QPropertyObserver &operator=(QPropertyObserver &&other) noexcept;
~QPropertyObserver();

template <typename Property,
typename = std::enable_if_t<std::is_base_of_v<QUntypedPropertyData, Property>>>
template <typename Property, QtPrivate::IsUntypedPropertyData<Property> = true>
void setSource(const Property &property)
{ setSource(property.bindingData()); }
void setSource(const QtPrivate::QPropertyBindingData &property);
Expand Down Expand Up @@ -303,8 +302,7 @@ class QPropertyChangeHandler : public QPropertyObserver
{
}

template <typename Property,
typename = std::enable_if_t<std::is_base_of_v<QUntypedPropertyData, Property>>>
template <typename Property, QtPrivate::IsUntypedPropertyData<Property> = true>
Q_NODISCARD_CTOR
QPropertyChangeHandler(const Property &property, Functor handler)
: QPropertyObserver([](QPropertyObserver *self, QUntypedPropertyData *) {
Expand Down Expand Up @@ -335,7 +333,7 @@ class QPropertyNotifier : public QPropertyObserver
}

template <typename Functor, typename Property,
typename = std::enable_if_t<std::is_base_of_v<QUntypedPropertyData, Property>>>
QtPrivate::IsUntypedPropertyData<Property> = true>
Q_NODISCARD_CTOR
QPropertyNotifier(const Property &property, Functor handler)
: QPropertyObserver([](QPropertyObserver *self, QUntypedPropertyData *) {
Expand Down Expand Up @@ -909,8 +907,7 @@ QPropertyAlias : public QPropertyObserver
iface->setObserver(aliasedProperty(), this);
}

template <typename Property,
typename = std::enable_if_t<std::is_base_of_v<QUntypedPropertyData, Property>>>
template <typename Property, QtPrivate::IsUntypedPropertyData<Property> = true>
QPropertyAlias(Property *property)
: QPropertyObserver(property),
iface(&QtPrivate::QBindableInterfaceForProperty<Property>::iface)
Expand Down
13 changes: 5 additions & 8 deletions src/corelib/kernel/qpropertyprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,13 @@ struct QPropertyObserverPointer;

class QUntypedPropertyData
{
public:
#if QT_DEPRECATED_SINCE(6, 8)
// sentinel to check whether a class inherits QUntypedPropertyData
struct QT_DEPRECATED_VERSION_X_6_8("Use std::is_base_of instead.")
InheritsQUntypedPropertyData
{
};
#endif
};

namespace QtPrivate {
template <typename T>
using IsUntypedPropertyData = std::enable_if_t<std::is_base_of_v<QUntypedPropertyData, T>, bool>;
}

template <typename T>
class QPropertyData;

Expand Down

0 comments on commit 216af5d

Please sign in to comment.