From aeb29e855ae2d915d6116b27b3f12f86da695ec9 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Sat, 3 Nov 2018 17:14:09 +0100 Subject: [PATCH] better compile time checks --- src/controls/QskShortcutMap.h | 110 ++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 38 deletions(-) diff --git a/src/controls/QskShortcutMap.h b/src/controls/QskShortcutMap.h index c379a8d3..7a094f8b 100644 --- a/src/controls/QskShortcutMap.h +++ b/src/controls/QskShortcutMap.h @@ -31,30 +31,40 @@ class QSK_EXPORT QskShortcutMap bool autoRepeat, const QObject* receiver, const char* method ); // functor based slots - template< typename T > - static int addShortcut( const QKeySequence&, - bool autoRepeat, T function ); + template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr > + static int addShortcut( const QKeySequence&, bool autoRepeat, T function ); - template< typename T > - static int addShortcut( const QKeySequence&, - bool autoRepeat, const QObject* context, T function ); + template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr > + static int addShortcut( QQuickItem*, const QKeySequence&, bool autoRepeat, T function ); - template< typename T > - static int addShortcut( QQuickItem*, const QKeySequence&, - bool autoRepeat, T function ); + template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr > + static int addShortcut( QQuickWindow*, const QKeySequence&, bool autoRepeat, T function ); - template< typename T > + template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr > + static int addShortcut( const QKeySequence&, bool autoRepeat, + const QObject* context, T function ); + + template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr > static int addShortcut( QQuickItem*, const QKeySequence&, bool autoRepeat, const QObject* context, T function ); - template< typename T > - static int addShortcut( QQuickWindow*, const QKeySequence&, - bool autoRepeat, T function ); - - template< typename T > + template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr > static int addShortcut( QQuickWindow*, const QKeySequence&, bool autoRepeat, const QObject* context, T function ); + template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr > + static int addShortcut( const QKeySequence&, bool autoRepeat, + const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function ); + + template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr > + static int addShortcut( QQuickItem*, const QKeySequence&, bool autoRepeat, + const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function ); + + template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr > + static int addShortcut( QQuickWindow*, const QKeySequence&, bool autoRepeat, + const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function ); + + static bool contextMatcher( const QQuickItem*, Qt::ShortcutContext ); private: @@ -90,14 +100,31 @@ inline int QskShortcutMap::addShortcut( return addMethod( item, sequence, autoRepeat, receiver, method ); } -template< typename T > +template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* > inline int QskShortcutMap::addShortcut( const QKeySequence& sequence, bool autoRepeat, T function ) { return addFunctionT( nullptr, sequence, autoRepeat, nullptr, function ); } -template< typename T > +template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* > +inline int QskShortcutMap::addShortcut( + QQuickItem* item, const QKeySequence& sequence, + bool autoRepeat, T function ) +{ + return addFunctionT( item, sequence, autoRepeat, nullptr, function ); +} + +template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* > +inline int QskShortcutMap::addShortcut( + QQuickWindow* window, const QKeySequence& sequence, + bool autoRepeat, T function ) +{ + auto item = window ? window->contentItem() : nullptr; + return addFunctionT( item, sequence, autoRepeat, nullptr, function ); +} + +template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* > inline int QskShortcutMap::addShortcut( const QKeySequence& sequence, bool autoRepeat, const QObject* context, T function ) @@ -105,33 +132,15 @@ inline int QskShortcutMap::addShortcut( return addFunctionT( nullptr, sequence, autoRepeat, context, function ); } -template< typename T > -inline int QskShortcutMap::addShortcut( - QQuickItem* item, const QKeySequence& sequence, - bool autoRepeat, T function ) -{ - return addFunctionT( item, sequence, autoRepeat, nullptr, function ); -} - -template< typename T > +template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* > inline int QskShortcutMap::addShortcut( QQuickItem* item, const QKeySequence& sequence, bool autoRepeat, const QObject* context, T function ) { - return addFunctionT( item, sequence, autoRepeat, - context, QskMetaFunction( function ) ); + return addFunctionT( item, sequence, autoRepeat, context, function ); } -template< typename T > -inline int QskShortcutMap::addShortcut( - QQuickWindow* window, const QKeySequence& sequence, - bool autoRepeat, T function ) -{ - auto item = window ? window->contentItem() : nullptr; - return addFunctionT( item, sequence, autoRepeat, nullptr, function ); -} - -template< typename T > +template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* > inline int QskShortcutMap::addShortcut( QQuickWindow* window, const QKeySequence& sequence, bool autoRepeat, const QObject* context, T function ) @@ -140,6 +149,31 @@ inline int QskShortcutMap::addShortcut( return addFunctionT( item, sequence, autoRepeat, context, function ); } +template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* > +inline int QskShortcutMap::addShortcut( + const QKeySequence& sequence, bool autoRepeat, + const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function ) +{ + return addFunctionT( nullptr, sequence, autoRepeat, receiver, function ); +} + +template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* > +inline int QskShortcutMap::addShortcut( + QQuickItem* item, const QKeySequence& sequence, bool autoRepeat, + const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function ) +{ + return addFunctionT( item, sequence, autoRepeat, receiver, function ); +} + +template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* > +inline int QskShortcutMap::addShortcut( + QQuickWindow* window, const QKeySequence& sequence, bool autoRepeat, + const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function ) +{ + auto item = window ? window->contentItem() : nullptr; + return addFunctionT( item, sequence, autoRepeat, receiver, function ); +} + template< typename T > inline int QskShortcutMap::addFunctionT( QQuickItem* item, const QKeySequence& sequence, bool autoRepeat,