diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-09-25 19:54:49 +0200 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-11-14 19:59:23 +0100 |
commit | a4751f8824723acaee4b9d8aa78a59c2aa36cb3e (patch) | |
tree | b5dfe245009cdcd73e3833f812e045ee7bfab8a5 /src | |
parent | 41702d8455a9e88ac70108e500a10e7bd4df2771 (diff) |
QShortcut: add pmf ctor overloads
Provide pointer to member function overloads for the QShortcut ctor. The
ctor with two functors but no contexts is not provided since it creates
ambiguousness.
[ChangeLog][QtWidgets][QShortcut] QShortcut ctor has now pmf overloads
Fixes: QTBUG-77816
Change-Id: Ic9a759cde5150dbb94c2fd351b88ee8e447e0852
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/kernel/qshortcut.cpp | 74 | ||||
-rw-r--r-- | src/widgets/kernel/qshortcut.h | 60 |
2 files changed, 130 insertions, 4 deletions
diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp index eec65c8625..d469279ea5 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut.cpp @@ -419,6 +419,76 @@ static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidge \sa activated() */ +/*! + \fn template<typename Functor> + QShortcut(const QKeySequence &key, QWidget *parent, + Functor functor, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); + \since 5.15 + \overload + + This is a QShortcut convenience constructor which connects the shortcut's + \l{QShortcut::activated()}{activated()} signal to the \a functor. +*/ +/*! + \fn template<typename Functor> + QShortcut(const QKeySequence &key, QWidget *parent, + const QObject *context, Functor functor, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); + \since 5.15 + \overload + + This is a QShortcut convenience constructor which connects the shortcut's + \l{QShortcut::activated()}{activated()} signal to the \a functor. + + The \a functor can be a pointer to a member function of the \a context object. + + If the \a context object is destroyed, the \a functor will not be called. +*/ +/*! + \fn template<typename Functor, typename FunctorAmbiguous> + QShortcut(const QKeySequence &key, QWidget *parent, + const QObject *context1, Functor functor, + FunctorAmbiguous functorAmbiguous, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); + \since 5.15 + \overload + + This is a QShortcut convenience constructor which connects the shortcut's + \l{QShortcut::activated()}{activated()} signal to the \a functor and + \l{QShortcut::activatedAmbiguously()}{activatedAmbiguously()} + signal to the \a FunctorAmbiguous. + + The \a functor and \a FunctorAmbiguous can be a pointer to a member + function of the \a context object. + + If the \a context object is destroyed, the \a functor and + \a FunctorAmbiguous will not be called. +*/ +/*! + \fn template<typename Functor, typename FunctorAmbiguous> + QShortcut(const QKeySequence &key, QWidget *parent, + const QObject *context1, Functor functor, + const QObject *context2, FunctorAmbiguous functorAmbiguous, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); + \since 5.15 + \overload + + This is a QShortcut convenience constructor which connects the shortcut's + \l{QShortcut::activated()}{activated()} signal to the \a functor and + \l{QShortcut::activatedAmbiguously()}{activatedAmbiguously()} + signal to the \a FunctorAmbiguous. + + The \a functor can be a pointer to a member function of the + \a context1 object. + The \a FunctorAmbiguous can be a pointer to a member function of the + \a context2 object. + + If the \a context1 object is destroyed, the \a functor will not be called. + If the \a context2 object is destroyed, the \a FunctorAmbiguous + will not be called. +*/ + /* \internal Private data accessed through d-pointer. @@ -479,13 +549,13 @@ QShortcut::QShortcut(QWidget *parent) */ QShortcut::QShortcut(const QKeySequence &key, QWidget *parent, const char *member, const char *ambiguousMember, - Qt::ShortcutContext context) + Qt::ShortcutContext shortcutContext) : QShortcut(parent) { QAPP_CHECK("QShortcut"); Q_D(QShortcut); - d->sc_context = context; + d->sc_context = shortcutContext; d->sc_sequence = key; d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap); if (member) diff --git a/src/widgets/kernel/qshortcut.h b/src/widgets/kernel/qshortcut.h index 6dcf4971b2..4f9c5ba0f7 100644 --- a/src/widgets/kernel/qshortcut.h +++ b/src/widgets/kernel/qshortcut.h @@ -61,9 +61,65 @@ class Q_WIDGETS_EXPORT QShortcut : public QObject Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext) public: explicit QShortcut(QWidget *parent); - QShortcut(const QKeySequence& key, QWidget *parent, + QShortcut(const QKeySequence &key, QWidget *parent, const char *member = nullptr, const char *ambiguousMember = nullptr, - Qt::ShortcutContext context = Qt::WindowShortcut); + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); +#ifdef Q_CLANG_QDOC + template<typename Functor> + QShortcut(const QKeySequence &key, QWidget *parent, + Functor functor, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); + template<typename Functor> + QShortcut(const QKeySequence &key, QWidget *parent, + const QObject *context, Functor functor, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); + template<typename Functor, typename FunctorAmbiguous> + QShortcut(const QKeySequence &key, QWidget *parent, + const QObject *context1, Functor functor, + FunctorAmbiguous functorAmbiguous, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); + template<typename Functor, typename FunctorAmbiguous> + QShortcut(const QKeySequence &key, QWidget *parent, + const QObject *context1, Functor functor, + const QObject *context2, FunctorAmbiguous functorAmbiguous, + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); +#else + template<typename Func1> + QShortcut(const QKeySequence &key, QWidget *parent, + Func1 slot1, + Qt::ShortcutContext context = Qt::WindowShortcut) + : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) + { + connect(this, &QShortcut::activated, std::move(slot1)); + } + template<class Obj1, typename Func1> + QShortcut(const QKeySequence &key, QWidget *parent, + const Obj1 *object1, Func1 slot1, + Qt::ShortcutContext context = Qt::WindowShortcut) + : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) + { + connect(this, &QShortcut::activated, object1, std::move(slot1)); + } + template<class Obj1, typename Func1, typename Func2> + QShortcut(const QKeySequence &key, QWidget *parent, + const Obj1 *object1, Func1 slot1, Func2 slot2, + Qt::ShortcutContext context = Qt::WindowShortcut) + : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) + { + connect(this, &QShortcut::activated, object1, std::move(slot1)); + connect(this, &QShortcut::activatedAmbiguously, object1, std::move(slot2)); + } + template<class Obj1, typename Func1, class Obj2, typename Func2> + QShortcut(const QKeySequence &key, QWidget *parent, + const Obj1 *object1, Func1 slot1, + const Obj2 *object2, Func2 slot2, + Qt::ShortcutContext context = Qt::WindowShortcut) + : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) + { + connect(this, &QShortcut::activated, object1, std::move(slot1)); + connect(this, &QShortcut::activatedAmbiguously, object2, std::move(slot2)); + } +#endif ~QShortcut(); void setKey(const QKeySequence& key); |