2015-03-14 11:00:24 +00:00
|
|
|
#include "operationholder.hpp"
|
|
|
|
|
|
|
|
#include "operation.hpp"
|
|
|
|
|
2016-01-21 15:08:04 +00:00
|
|
|
CSMDoc::OperationHolder::OperationHolder(Operation* operation)
|
2018-10-09 06:21:12 +00:00
|
|
|
: mOperation(nullptr)
|
2016-01-21 15:08:04 +00:00
|
|
|
, mRunning(false)
|
2015-03-14 11:00:24 +00:00
|
|
|
{
|
|
|
|
if (operation)
|
|
|
|
setOperation(operation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMDoc::OperationHolder::setOperation(Operation* operation)
|
|
|
|
{
|
|
|
|
mOperation = operation;
|
|
|
|
mOperation->moveToThread(&mThread);
|
|
|
|
|
2022-08-23 02:28:58 +00:00
|
|
|
connect(mOperation, &Operation::progress, this, &OperationHolder::progress);
|
2015-03-14 11:00:24 +00:00
|
|
|
|
2022-08-23 02:28:58 +00:00
|
|
|
connect(mOperation, &Operation::reportMessage, this, &OperationHolder::reportMessage);
|
2015-03-14 11:00:24 +00:00
|
|
|
|
2022-08-23 02:28:58 +00:00
|
|
|
connect(mOperation, &Operation::done, this, &OperationHolder::doneSlot);
|
2015-03-14 11:00:24 +00:00
|
|
|
|
2022-08-23 02:28:58 +00:00
|
|
|
connect(this, &OperationHolder::abortSignal, mOperation, &Operation::abort);
|
2015-03-14 11:00:24 +00:00
|
|
|
|
2022-08-23 02:28:58 +00:00
|
|
|
connect(&mThread, &QThread::started, mOperation, &Operation::run);
|
2015-03-14 11:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMDoc::OperationHolder::doneSlot(int type, bool failed)
|
|
|
|
{
|
|
|
|
mRunning = false;
|
|
|
|
mThread.quit();
|
|
|
|
emit done(type, failed);
|
|
|
|
}
|