Reduce some code duplication

The r-value setBinding() overloads can be removed,
as they took a copy internally anyway.

Change-Id: I691265299e5cb336791f614b30788c81467df534
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Lars Knoll 2020-08-06 12:22:10 +02:00
parent 80745bfffe
commit 52bbb19fa4

View File

@ -276,20 +276,11 @@ public:
return oldBinding;
}
QPropertyBinding<T> setBinding(QPropertyBinding<T> &&newBinding)
{
QPropertyBinding<T> b(std::move(newBinding));
QPropertyBinding<T> oldBinding(d.priv.setBinding(b, &d));
notify();
return oldBinding;
}
bool setBinding(const QUntypedPropertyBinding &newBinding)
{
if (newBinding.valueMetaType().id() != qMetaTypeId<T>())
return false;
d.priv.setBinding(newBinding, &d);
notify();
setBinding(static_cast<const QPropertyBinding<T> &>(newBinding));
return true;
}
@ -461,41 +452,11 @@ public:
}
}
QPropertyBinding<T> setBinding(Class *owner, QPropertyBinding<T> &&newBinding)
{
QPropertyBinding<T> b(std::move(newBinding));
if constexpr (CallbackAcceptsOldValue) {
T oldValue = value();
QPropertyBinding<T> oldBinding(d.priv.setBinding(b, &d, owner, [](void *o, void *oldVal) {
(reinterpret_cast<Class *>(o)->*Callback)(*reinterpret_cast<T *>(oldVal));
}, GuardTE));
notify(owner, &oldValue);
return oldBinding;
} else {
QPropertyBinding<T> oldBinding(d.priv.setBinding(b, &d, owner, [](void *o, void *) {
(reinterpret_cast<Class *>(o)->*Callback)();
}, GuardTE));
notify(owner);
return oldBinding;
}
}
bool setBinding(Class *owner, const QUntypedPropertyBinding &newBinding)
{
if (newBinding.valueMetaType().id() != qMetaTypeId<T>())
return false;
if constexpr (CallbackAcceptsOldValue) {
T oldValue = value();
d.priv.setBinding(newBinding, &d, owner, [](void *o, void *oldVal) {
(reinterpret_cast<Class *>(o)->*Callback)(*reinterpret_cast<T *>(oldVal));
}, GuardTE);
notify(owner, &oldValue);
} else {
d.priv.setBinding(newBinding, &d, owner, [](void *o, void *) {
(reinterpret_cast<Class *>(o)->*Callback)();
}, GuardTE);
notify(owner);
}
setBinding(owner, static_cast<const QPropertyBinding<T> &>(newBinding));
return true;
}