diff --git a/src/libs/vmisc/qt_dispatch/qt_dispatch.h b/src/libs/vmisc/qt_dispatch/qt_dispatch.h index ad3fa04fd..9b7c84a96 100644 --- a/src/libs/vmisc/qt_dispatch/qt_dispatch.h +++ b/src/libs/vmisc/qt_dispatch/qt_dispatch.h @@ -6,20 +6,19 @@ #ifndef THREAD_DISPATCHER_H #define THREAD_DISPATCHER_H -#include -#include -#include #include +#include #include - -#include +#include #include +#include +#include -typedef std::function voidBlock; +using voidBlock = std::function; class WorkerClass : public QObject { - Q_OBJECT // NOLINT + Q_OBJECT // NOLINT public: explicit WorkerClass(QThread *thread) @@ -28,43 +27,43 @@ public: connect(QThread::currentThread(), &QThread::finished, this, &WorkerClass::deleteLater); } public slots: - void DoWork(voidBlock block) + void DoWork(const voidBlock &block) { block(); deleteLater(); } }; -Q_DECL_UNUSED static inline void q_dispatch_async(QThread* thread, voidBlock block); -static inline void q_dispatch_async(QThread* thread, voidBlock block) +Q_DECL_UNUSED static inline void q_dispatch_async(QThread *thread, const voidBlock &block); +static inline void q_dispatch_async(QThread *thread, const voidBlock &block) { - qRegisterMetaType("voidBlock"); + qRegisterMetaType("voidBlock"); - WorkerClass *worker = new WorkerClass(thread); - QMetaObject::invokeMethod(worker, "DoWork", Qt::QueuedConnection, Q_ARG(voidBlock, block)); + auto *worker = new WorkerClass(thread); + QMetaObject::invokeMethod(worker, "DoWork", Qt::QueuedConnection, Q_ARG(voidBlock, block)); } -Q_DECL_UNUSED static inline void q_dispatch_async_main(voidBlock block); -static inline void q_dispatch_async_main(voidBlock block) +Q_DECL_UNUSED static inline void q_dispatch_async_main(const voidBlock &block); +static inline void q_dispatch_async_main(const voidBlock &block) { - QThread *mainThread = QCoreApplication::instance()->thread(); - q_dispatch_async(mainThread, block); + QThread *mainThread = QCoreApplication::instance()->thread(); + q_dispatch_async(mainThread, block); } -typedef std::function msgHandlerBlock; +using msgHandlerBlock = std::function; class MsgHandlerWorkerClass : public QObject { - Q_OBJECT // NOLINT + Q_OBJECT // NOLINT public: - MsgHandlerWorkerClass(QThread *thread, QtMsgType type, const QMessageLogContext &context, const QString &msg) - : m_type(type), - m_msg(msg), - m_line(context.line), - m_file(context.file), - m_function(context.function), - m_category(context.category) + MsgHandlerWorkerClass(QThread *thread, QtMsgType type, const QMessageLogContext &context, QString msg) + : m_type(type), + m_msg(std::move(msg)), + m_line(context.line), + m_file(context.file), + m_function(context.function), + m_category(context.category) { #ifndef V_NO_ASSERT assert(context.version == 2); @@ -73,12 +72,15 @@ public: connect(QThread::currentThread(), &QThread::finished, this, &WorkerClass::deleteLater); } public slots: - void DoWork(msgHandlerBlock block) + void DoWork(const msgHandlerBlock &block) { - block(m_type, QMessageLogContext(qUtf8Printable(m_file), m_line, qUtf8Printable(m_function), - qUtf8Printable(m_category)), m_msg); + block( + m_type, + QMessageLogContext(qUtf8Printable(m_file), m_line, qUtf8Printable(m_function), qUtf8Printable(m_category)), + m_msg); deleteLater(); } + private: QtMsgType m_type; QString m_msg; @@ -90,21 +92,21 @@ private: QString m_category; }; -Q_DECL_UNUSED static inline void q_dispatch_async(QThread* thread, msgHandlerBlock block, QtMsgType type, +Q_DECL_UNUSED static inline void q_dispatch_async(QThread *thread, const msgHandlerBlock &block, QtMsgType type, const QMessageLogContext &context, const QString &msg); -static inline void q_dispatch_async(QThread* thread, msgHandlerBlock block, QtMsgType type, +static inline void q_dispatch_async(QThread *thread, const msgHandlerBlock &block, QtMsgType type, const QMessageLogContext &context, const QString &msg) { - qRegisterMetaType("msgHandlerBlock"); + qRegisterMetaType("msgHandlerBlock"); - MsgHandlerWorkerClass *worker = new MsgHandlerWorkerClass(thread, type, context, msg); - QMetaObject::invokeMethod(worker, "DoWork", Qt::QueuedConnection, Q_ARG(msgHandlerBlock, block)); + auto *worker = new MsgHandlerWorkerClass(thread, type, context, msg); + QMetaObject::invokeMethod(worker, "DoWork", Qt::QueuedConnection, Q_ARG(msgHandlerBlock, block)); } -Q_DECL_UNUSED static inline void q_dispatch_async_main(msgHandlerBlock block, QtMsgType type, +Q_DECL_UNUSED static inline void q_dispatch_async_main(const msgHandlerBlock &block, QtMsgType type, const QMessageLogContext &context, const QString &msg); -static inline void q_dispatch_async_main(msgHandlerBlock block, QtMsgType type, const QMessageLogContext &context, - const QString &msg) +static inline void q_dispatch_async_main(const msgHandlerBlock &block, QtMsgType type, + const QMessageLogContext &context, const QString &msg) { QThread *mainThread = QCoreApplication::instance()->thread(); q_dispatch_async(mainThread, block, type, context, msg);