Simplify invokeMethod implementations using QSlotObject helpers
Remove duplication for overloads covering member function pointer or function pointer cases, as those are now covered by the new QtPrivate::makeSlotObject helper. Change-Id: Ife1e05416958e40a4759ca06cf7db185031b8a86 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
a443b5f2ec
commit
6ef5e186a9
@ -1720,31 +1720,19 @@ bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template<typename Functor, typename FunctorReturnType> bool QMetaObject::invokeMethod(QObject *context, Functor function, Qt::ConnectionType type, FunctorReturnType *ret)
|
||||
\fn template<typename Functor, typename FunctorReturnType> bool QMetaObject::invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type, FunctorReturnType *ret)
|
||||
\fn template<typename Functor, typename FunctorReturnType> bool QMetaObject::invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret)
|
||||
|
||||
\since 5.10
|
||||
|
||||
\threadsafe
|
||||
\overload
|
||||
|
||||
Invokes the \a function in the event loop of \a context. \a function can be a functor
|
||||
or a pointer to a member function. Returns \c true if the function could be invoked.
|
||||
Returns \c false if there is no such function or the parameters did not match.
|
||||
The return value of the function call is placed in \a ret.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template<typename Functor, typename FunctorReturnType> bool QMetaObject::invokeMethod(QObject *context, Functor function, FunctorReturnType *ret)
|
||||
|
||||
\since 5.10
|
||||
|
||||
\threadsafe
|
||||
\overload
|
||||
|
||||
Invokes the \a function in the event loop of \a context using the connection type Qt::AutoConnection.
|
||||
\a function can be a functor or a pointer to a member function. Returns \c true if the function could
|
||||
be invoked. Returns \c false if there is no such member or the parameters did not match.
|
||||
The return value of the function call is placed in \a ret.
|
||||
If \a type is set, then the function is invoked using that connection type. Otherwise,
|
||||
Qt::AutoConnection will be used.
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
@ -406,55 +406,29 @@ struct Q_CORE_EXPORT QMetaObject
|
||||
|
||||
#ifdef Q_QDOC
|
||||
template<typename Functor, typename FunctorReturnType>
|
||||
static bool invokeMethod(QObject *context, Functor function, Qt::ConnectionType type = Qt::AutoConnection, FunctorReturnType *ret = nullptr);
|
||||
static bool invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type = Qt::AutoConnection, FunctorReturnType *ret = nullptr);
|
||||
template<typename Functor, typename FunctorReturnType>
|
||||
static bool invokeMethod(QObject *context, Functor function, FunctorReturnType *ret);
|
||||
static bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret);
|
||||
#else
|
||||
|
||||
// invokeMethod() for member function pointer
|
||||
// invokeMethod() for member function pointer or function pointer
|
||||
template <typename Func>
|
||||
static typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
|
||||
&& !std::is_convertible<Func, const char*>::value
|
||||
&& QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
|
||||
invokeMethod(typename QtPrivate::FunctionPointer<Func>::Object *object,
|
||||
Func function,
|
||||
static typename std::enable_if<QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
|
||||
invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
|
||||
Func &&function,
|
||||
Qt::ConnectionType type = Qt::AutoConnection,
|
||||
typename QtPrivate::FunctionPointer<Func>::ReturnType *ret = nullptr)
|
||||
{
|
||||
return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs<Func>(function), type, ret);
|
||||
return invokeMethodImpl(object, QtPrivate::makeSlotObject<Func>(std::forward<Func>(function)), type, ret);
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
static typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
|
||||
&& !std::is_convertible<Func, const char*>::value
|
||||
&& QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
|
||||
invokeMethod(typename QtPrivate::FunctionPointer<Func>::Object *object,
|
||||
Func function,
|
||||
static typename std::enable_if<QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
|
||||
invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
|
||||
Func &&function,
|
||||
typename QtPrivate::FunctionPointer<Func>::ReturnType *ret)
|
||||
{
|
||||
return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs<Func>(function), Qt::AutoConnection, ret);
|
||||
}
|
||||
|
||||
// invokeMethod() for function pointer (not member)
|
||||
template <typename Func>
|
||||
static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
|
||||
&& !std::is_convertible<Func, const char*>::value
|
||||
&& QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
|
||||
invokeMethod(QObject *context, Func function,
|
||||
Qt::ConnectionType type = Qt::AutoConnection,
|
||||
typename QtPrivate::FunctionPointer<Func>::ReturnType *ret = nullptr)
|
||||
{
|
||||
return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn<Func>(function), type, ret);
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
|
||||
&& !std::is_convertible<Func, const char*>::value
|
||||
&& QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
|
||||
invokeMethod(QObject *context, Func function,
|
||||
typename QtPrivate::FunctionPointer<Func>::ReturnType *ret)
|
||||
{
|
||||
return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn<Func>(function), Qt::AutoConnection, ret);
|
||||
return invokeMethod(object, std::forward<Func>(function), Qt::AutoConnection, ret);
|
||||
}
|
||||
|
||||
// invokeMethod() for Functor
|
||||
|
Loading…
x
Reference in New Issue
Block a user