diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-08-10 08:18:17 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-10-10 20:46:01 +0200 |
commit | 01103222dc59526b37d594b93b0b1cd7473e3f6f (patch) | |
tree | 8e3b679377571fd9b9014afbe62eeba6249d42e2 /lib/qt_connection_util.h | |
parent | 4f08c88d234119c2a76874ebd2b1433b81992427 (diff) | |
parent | 7b516cdf0b987e542b1e4cd4556ecb2bfbde3ff9 (diff) | |
download | libquotient-01103222dc59526b37d594b93b0b1cd7473e3f6f.tar.gz libquotient-01103222dc59526b37d594b93b0b1cd7473e3f6f.zip |
Merge branch 'master' into kitsune-fix-read-receipts-and-markers
Diffstat (limited to 'lib/qt_connection_util.h')
-rw-r--r-- | lib/qt_connection_util.h | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/qt_connection_util.h b/lib/qt_connection_util.h index c6fa037a..46294499 100644 --- a/lib/qt_connection_util.h +++ b/lib/qt_connection_util.h @@ -19,12 +19,7 @@ namespace _impl { decorated_slot_tt<ArgTs...> decoratedSlot, Qt::ConnectionType connType) { - // See https://bugreports.qt.io/browse/QTBUG-60339 -#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) - auto pc = std::make_shared<QMetaObject::Connection>(); -#else auto pc = std::make_unique<QMetaObject::Connection>(); -#endif auto& c = *pc; // Resolve a reference before pc is moved to lambda // Perfect forwarding doesn't work through signal-slot connections - @@ -73,6 +68,17 @@ namespace _impl { }), connType); } + + // TODO: get rid of it as soon as Apple Clang gets proper deduction guides + // for std::function<> + // ...or consider using QtPrivate magic used by QObject::connect() + // ...for inspiration, also check a possible std::not_fn implementation + // at https://en.cppreference.com/w/cpp/utility/functional/not_fn + template <typename FnT> + inline auto wrap_in_function(FnT&& f) + { + return typename function_traits<FnT>::function_type(std::forward<FnT>(f)); + } } // namespace _impl /*! \brief Create a connection that self-disconnects when its "slot" returns true @@ -90,7 +96,7 @@ inline auto connectUntil(SenderT* sender, SignalT signal, ContextT* context, const FunctorT& slot, Qt::ConnectionType connType = Qt::AutoConnection) { - return _impl::connectUntil(sender, signal, context, wrap_in_function(slot), + return _impl::connectUntil(sender, signal, context, _impl::wrap_in_function(slot), connType); } @@ -100,8 +106,13 @@ inline auto connectSingleShot(SenderT* sender, SignalT signal, ContextT* context, const FunctorT& slot, Qt::ConnectionType connType = Qt::AutoConnection) { +#if QT_VERSION_MAJOR >= 6 + return QObject::connect(sender, signal, context, slot, + Qt::ConnectionType(connType + | Qt::SingleShotConnection)); +#else return _impl::connectSingleShot( - sender, signal, context, wrap_in_function(slot), connType); + sender, signal, context, _impl::wrap_in_function(slot), connType); } // Specialisation for usual Qt slots passed as pointers-to-members. @@ -114,11 +125,12 @@ inline auto connectSingleShot(SenderT* sender, SignalT signal, { // TODO: when switching to C++20, use std::bind_front() instead return _impl::connectSingleShot(sender, signal, receiver, - wrap_in_function( + _impl::wrap_in_function( [receiver, slot](const ArgTs&... args) { (receiver->*slot)(args...); }), connType); +#endif } /*! \brief A guard pointer that disconnects an interested object upon destruction |