1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 21:53:52 +00:00
openmw/apps/opencs/model/doc/operationholder.cpp

61 lines
1.3 KiB
C++
Raw Normal View History

#include "operationholder.hpp"
#include "operation.hpp"
2022-09-22 18:26:05 +00:00
CSMDoc::OperationHolder::OperationHolder(Operation* operation)
2018-10-09 06:21:12 +00:00
: mOperation(nullptr)
2022-09-22 18:26:05 +00:00
, mRunning(false)
{
if (operation)
2022-09-22 18:26:05 +00:00
setOperation(operation);
}
2022-09-22 18:26:05 +00:00
void CSMDoc::OperationHolder::setOperation(Operation* operation)
{
mOperation = operation;
2022-09-22 18:26:05 +00:00
mOperation->moveToThread(&mThread);
2022-09-22 18:26:05 +00:00
connect(mOperation, &Operation::progress, this, &OperationHolder::progress);
2022-09-22 18:26:05 +00:00
connect(mOperation, &Operation::reportMessage, this, &OperationHolder::reportMessage);
2022-09-22 18:26:05 +00:00
connect(mOperation, &Operation::done, this, &OperationHolder::doneSlot);
2022-09-22 18:26:05 +00:00
connect(this, &OperationHolder::abortSignal, mOperation, &Operation::abort);
2022-09-22 18:26:05 +00:00
connect(&mThread, &QThread::started, mOperation, &Operation::run);
}
bool CSMDoc::OperationHolder::isRunning() const
{
return mRunning;
}
void CSMDoc::OperationHolder::start()
{
mRunning = true;
mThread.start();
}
void CSMDoc::OperationHolder::abort()
{
mRunning = false;
emit abortSignal();
}
void CSMDoc::OperationHolder::abortAndWait()
{
if (mRunning)
{
mThread.quit();
mThread.wait();
}
}
2022-09-22 18:26:05 +00:00
void CSMDoc::OperationHolder::doneSlot(int type, bool failed)
{
mRunning = false;
mThread.quit();
2022-09-22 18:26:05 +00:00
emit done(type, failed);
}