2010-10-20 23:50:49 +00:00
|
|
|
/**
|
|
|
|
* \file InGuiThread.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Peter Kümmel
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2010-10-20 23:58:22 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2010-10-21 00:07:48 +00:00
|
|
|
#include "InGuiThread.h"
|
2010-10-20 23:50:49 +00:00
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
#include <QEventLoop>
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
|
|
IntoGuiThreadMover::IntoGuiThreadMover()
|
|
|
|
{
|
|
|
|
moveToThread(QApplication::instance()->thread());
|
|
|
|
connect(this, SIGNAL(triggerCall()), this, SLOT(doFunctionCall()),
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IntoGuiThreadMover::callInGuiThread()
|
|
|
|
{
|
|
|
|
if (QThread::currentThread() == QApplication::instance()->thread()) {
|
|
|
|
synchronousFunctionCall();
|
|
|
|
} else {
|
|
|
|
QEventLoop loop;
|
|
|
|
connect(this, SIGNAL(called()), &loop, SLOT(quit()));
|
|
|
|
Q_EMIT triggerCall();
|
|
|
|
loop.exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IntoGuiThreadMover::doFunctionCall()
|
|
|
|
{
|
|
|
|
synchronousFunctionCall();
|
|
|
|
Q_EMIT called();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
|