6ea3a1df08
cstdint) Make MessageElement to a class to fit better with the derived classes. Make MessageLayoutElement to a class to fit better with the derived classes. Remove virtual from override functions Replace all instances of boost::signals2 with pajlada::Signals. This lets us properly use clang code model to check for issues. Add missing virtual destructor to AbstractIrcServer Add missing virtual destructor to MessageLayoutElement Remove unused "connectedConnection" connection in TwitchChannel Fix typo in TrimChannelName function Fix typo in MessageParseArgs Replace some raw pointers with unique pointers where it made more sense. This allowed us to remove some manually written destructors whose only purpose was to delete that raw pointer. Reformat: Add namespace comments Reformat: Add empty empty lines between main namespace beginning and end Reformat: Re-order includes Reformat: Fix some includes that used quotes where they should use angle brackets Reformat: Replace some typedef's with using's Filter out more useless warnings
61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QRunnable>
|
|
#include <QThreadPool>
|
|
|
|
#include <functional>
|
|
|
|
#define async_exec(a) QThreadPool::globalInstance()->start(new LambdaRunnable(a));
|
|
|
|
namespace chatterino {
|
|
namespace util {
|
|
|
|
class LambdaRunnable : public QRunnable
|
|
{
|
|
public:
|
|
LambdaRunnable(std::function<void()> action)
|
|
{
|
|
this->action = action;
|
|
}
|
|
|
|
void run()
|
|
{
|
|
this->action();
|
|
}
|
|
|
|
private:
|
|
std::function<void()> action;
|
|
};
|
|
|
|
// Taken from
|
|
// https://stackoverflow.com/questions/21646467/how-to-execute-a-functor-or-a-lambda-in-a-given-thread-in-qt-gcd-style
|
|
// Qt 5/4 - preferred, has least allocations
|
|
template <typename F>
|
|
static void postToThread(F &&fun, QObject *obj = qApp)
|
|
{
|
|
struct Event : public QEvent {
|
|
using Fun = typename std::decay<F>::type;
|
|
Fun fun;
|
|
Event(Fun &&fun)
|
|
: QEvent(QEvent::None)
|
|
, fun(std::move(fun))
|
|
{
|
|
}
|
|
Event(const Fun &fun)
|
|
: QEvent(QEvent::None)
|
|
, fun(fun)
|
|
{
|
|
}
|
|
~Event() override
|
|
{
|
|
fun();
|
|
}
|
|
};
|
|
QCoreApplication::postEvent(obj, new Event(std::forward<F>(fun)));
|
|
}
|
|
|
|
} // namespace util
|
|
} // namespace chatterino
|