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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IntoGuiThreadMover::callInGuiThread()
|
|
|
|
{
|
2010-10-21 08:02:09 +00:00
|
|
|
QThread* gui_thread = QApplication::instance()->thread();
|
|
|
|
if (QThread::currentThread() == gui_thread) {
|
2010-10-20 23:50:49 +00:00
|
|
|
synchronousFunctionCall();
|
|
|
|
} else {
|
2010-10-21 08:02:09 +00:00
|
|
|
moveToThread(gui_thread);
|
|
|
|
connect(this, SIGNAL(triggerCall()), this, SLOT(doFunctionCall()),
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
// TODO try with condition, it's maybe cheaper
|
2010-10-20 23:50:49 +00:00
|
|
|
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
|
|
|
|
|
2010-10-21 00:24:57 +00:00
|
|
|
#include "moc_InGuiThread.cpp"
|