From 7d9cbc6b643b472304960842cd60ec4ba3319f37 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 9 Mar 2016 20:37:17 +0100 Subject: [PATCH] Fix Q_QDOC code for PointerToMemberFunction In functions such as QObject::connect and similar which are using pointer to member function or functor, we have a different declaration for qdoc because we don't want to show the QEnableIf and other type traits in the doc. However, The code still needs to be valid, as we will use clang to parse the documentation. Fix it by making 'PointerToMemberFunction' and 'Functor' template parameters (which they actually are). Change-Id: Ie2648407bae21ba6d1677f6de2d6f597486b5c98 Reviewed-by: Edward Welbourne Reviewed-by: Martin Smith --- src/corelib/kernel/qmetaobject.h | 10 +++------- src/corelib/kernel/qmetatype.h | 3 +++ src/corelib/kernel/qobject.h | 4 ++++ src/corelib/kernel/qtimer.h | 6 ++++++ src/corelib/statemachine/qsignaltransition.h | 1 + src/corelib/statemachine/qstate.h | 1 + src/corelib/tools/qsharedpointer.h | 1 + src/widgets/widgets/qmenu.h | 6 ++++++ src/widgets/widgets/qtoolbar.h | 6 ++++++ 9 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h index f7c60cc309..4d114a5616 100644 --- a/src/corelib/kernel/qmetaobject.h +++ b/src/corelib/kernel/qmetaobject.h @@ -168,19 +168,15 @@ public: inline bool isValid() const { return mobj != Q_NULLPTR; } -#ifdef Q_QDOC - static QMetaMethod fromSignal(PointerToMemberFunction signal); -#else - template - static inline QMetaMethod fromSignal(Func signal) + template + static inline QMetaMethod fromSignal(PointerToMemberFunction signal) { - typedef QtPrivate::FunctionPointer SignalType; + typedef QtPrivate::FunctionPointer SignalType; Q_STATIC_ASSERT_X(QtPrivate::HasQ_OBJECT_Macro::Value, "No Q_OBJECT in the class with the signal"); return fromSignalImpl(&SignalType::Object::staticMetaObject, reinterpret_cast(&signal)); } -#endif private: #if QT_DEPRECATED_SINCE(5,0) diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 7b9eb79bd0..e6ce31aaaa 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -600,8 +600,11 @@ public: } #ifdef Q_QDOC + template static bool registerConverter(MemberFunction function); + template static bool registerConverter(MemberFunctionOk function); + template static bool registerConverter(UnaryFunction function); #else // member function as in "QString QFont::toString() const" diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 1f3d3dcfc7..87d006bdc6 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -210,8 +210,11 @@ public: const char *member, Qt::ConnectionType type = Qt::AutoConnection) const; #ifdef Q_QDOC + template static QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type = Qt::AutoConnection); + template static QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor); + template static QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type = Qt::AutoConnection); #else //Connect a signal to a pointer to qobject member function @@ -360,6 +363,7 @@ public: static bool disconnect(const QMetaObject::Connection &); #ifdef Q_QDOC + template static bool disconnect(const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method); #else template diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h index dd52d52a1c..d97fe933b9 100644 --- a/src/corelib/kernel/qtimer.h +++ b/src/corelib/kernel/qtimer.h @@ -80,11 +80,17 @@ public: static void singleShot(int msec, Qt::TimerType timerType, const QObject *receiver, const char *member); #ifdef Q_QDOC + template static void singleShot(int msec, const QObject *receiver, PointerToMemberFunction method); + template static void singleShot(int msec, Qt::TimerType timerType, const QObject *receiver, PointerToMemberFunction method); + template static void singleShot(int msec, Functor functor); + template static void singleShot(int msec, Qt::TimerType timerType, Functor functor); + template static void singleShot(int msec, const QObject *context, Functor functor); + template static void singleShot(int msec, Qt::TimerType timerType, const QObject *context, Functor functor); #else // singleShot to a QObject slot diff --git a/src/corelib/statemachine/qsignaltransition.h b/src/corelib/statemachine/qsignaltransition.h index e8d413cd8a..d7cf8584da 100644 --- a/src/corelib/statemachine/qsignaltransition.h +++ b/src/corelib/statemachine/qsignaltransition.h @@ -60,6 +60,7 @@ public: QSignalTransition(const QObject *sender, const char *signal, QState *sourceState = Q_NULLPTR); #ifdef Q_QDOC + template QSignalTransition(const QObject *object, PointerToMemberFunction signal, QState *sourceState = Q_NULLPTR); #elif defined(Q_COMPILER_DELEGATING_CONSTRUCTORS) diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h index ee1ff3fea3..7a9dc9c132 100644 --- a/src/corelib/statemachine/qstate.h +++ b/src/corelib/statemachine/qstate.h @@ -82,6 +82,7 @@ public: void addTransition(QAbstractTransition *transition); QSignalTransition *addTransition(const QObject *sender, const char *signal, QAbstractState *target); #ifdef Q_QDOC + template QSignalTransition *addTransition(const QObject *sender, PointerToMemberFunction signal, QAbstractState *target); #else diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h index 901862e7a2..6742a66939 100644 --- a/src/corelib/tools/qsharedpointer.h +++ b/src/corelib/tools/qsharedpointer.h @@ -68,6 +68,7 @@ public: // constructors QSharedPointer(); explicit QSharedPointer(T *ptr); + template QSharedPointer(T *ptr, Deleter d); QSharedPointer(const QSharedPointer &other); QSharedPointer(const QWeakPointer &other); diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h index 7dda38456a..2e579899bc 100644 --- a/src/widgets/widgets/qmenu.h +++ b/src/widgets/widgets/qmenu.h @@ -85,11 +85,17 @@ public: QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0); #ifdef Q_QDOC + template QAction *addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0); + template QAction *addAction(const QString &text, Functor functor, const QKeySequence &shortcut = 0); + template QAction *addAction(const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0); + template QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0); + template QAction *addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut = 0); + template QAction *addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0); #else // addAction(QString): Connect to a QObject slot / functor or function pointer (with context) diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h index 774d47b913..c1d765598f 100644 --- a/src/widgets/widgets/qtoolbar.h +++ b/src/widgets/widgets/qtoolbar.h @@ -100,11 +100,17 @@ public: QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member); #ifdef Q_QDOC + template QAction *addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method); + template QAction *addAction(const QString &text, Functor functor); + template QAction *addAction(const QString &text, const QObject *context, Functor functor); + template QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method); + template QAction *addAction(const QIcon &icon, const QString &text, Functor functor); + template QAction *addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor); #else // addAction(QString): Connect to a QObject slot / functor or function pointer (with context)