2022-05-27 09:26:03 +02:00
|
|
|
#include <QtConcurrent>
|
|
|
|
#include "ipcpreviewworker.h"
|
|
|
|
#include "previewgeneratormapfunctor.h"
|
|
|
|
IPCPreviewWorker::IPCPreviewWorker()
|
|
|
|
{
|
2022-05-28 17:24:42 +02:00
|
|
|
this->connect(&previewWorkerWatcher, &QFutureWatcher<QByteArray>::resultReadyAt, this,
|
|
|
|
[this](int index) { emit previewGenerated(previewWorkerWatcher.resultAt(index)); });
|
|
|
|
connect(&previewWorkerWatcher, &QFutureWatcher<QByteArray>::finished, this, [this] { emit finished(); });
|
2022-05-27 09:26:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IPCPreviewWorker::start(RenderConfig config, const QVector<RenderTarget> &targets, QLocalSocket *peer)
|
|
|
|
{
|
2022-05-28 17:24:42 +02:00
|
|
|
stop();
|
2022-05-29 10:40:46 +02:00
|
|
|
auto mapFunctor = PreviewGeneratorMapFunctor();
|
|
|
|
mapFunctor.setRenderConfig(config);
|
2022-05-27 09:26:03 +02:00
|
|
|
|
2022-05-29 10:40:46 +02:00
|
|
|
previewWorkerWatcher.setFuture(QtConcurrent::mapped(targets, mapFunctor));
|
2022-05-27 09:26:03 +02:00
|
|
|
}
|
2022-05-28 17:24:42 +02:00
|
|
|
|
|
|
|
void IPCPreviewWorker::stop()
|
|
|
|
{
|
|
|
|
previewWorkerWatcher.cancel();
|
|
|
|
previewWorkerWatcher.waitForFinished();
|
|
|
|
}
|