forked from qt-creator/qt-creator
Clang: Share executeInLoop
Change-Id: Id02902e1e7abdb8b3430e7b228547c4372a424ce Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include <QDir>
|
||||
|
||||
#include <connectionserver.h>
|
||||
#include <executeinloop.h>
|
||||
#include <filepathcaching.h>
|
||||
#include <generatedfiles.h>
|
||||
#include <refactoringserver.h>
|
||||
@@ -51,48 +52,6 @@ using ClangBackEnd::RefactoringDatabaseInitializer;
|
||||
using ClangBackEnd::ConnectionServer;
|
||||
using ClangBackEnd::SymbolIndexing;
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
|
||||
template<typename CallableType>
|
||||
class CallableEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
using Callable = std::decay_t<CallableType>;
|
||||
CallableEvent(Callable &&callable)
|
||||
: QEvent(QEvent::None)
|
||||
, callable(std::move(callable))
|
||||
{}
|
||||
CallableEvent(const Callable &callable)
|
||||
: QEvent(QEvent::None)
|
||||
, callable(callable)
|
||||
{}
|
||||
|
||||
~CallableEvent() { callable(); }
|
||||
|
||||
public:
|
||||
Callable callable;
|
||||
};
|
||||
|
||||
template<typename Callable>
|
||||
void executeInLoop(Callable &&callable, QObject *object = QCoreApplication::instance())
|
||||
{
|
||||
if (QThread *thread = qobject_cast<QThread *>(object))
|
||||
object = QAbstractEventDispatcher::instance(thread);
|
||||
|
||||
QCoreApplication::postEvent(object,
|
||||
new CallableEvent<Callable>(std::forward<Callable>(callable)),
|
||||
Qt::HighEventPriority);
|
||||
}
|
||||
#else
|
||||
template<typename Callable>
|
||||
void executeInLoop(Callable &&callable, QObject *object = QCoreApplication::instance())
|
||||
{
|
||||
if (QThread *thread = qobject_cast<QThread *>(object))
|
||||
object = QAbstractEventDispatcher::instance(thread);
|
||||
|
||||
QMetaObject::invokeMethod(object, std::forward<Callable>(callable));
|
||||
}
|
||||
#endif
|
||||
|
||||
QStringList processArguments(QCoreApplication &application)
|
||||
{
|
||||
QCommandLineParser parser;
|
||||
|
||||
Reference in New Issue
Block a user