25 lines
689 B
C++
25 lines
689 B
C++
#pragma once
|
|
|
|
#include <functional>
|
|
#include <QAtomicInt>
|
|
#include <QImage>
|
|
#include <QQuickImageResponse>
|
|
#include <QRunnable>
|
|
|
|
// Generic async image response: runs the given job on a thread pool and
|
|
// publishes the resulting image. Shared by all image providers.
|
|
class AsyncImageResponse : public QQuickImageResponse, public QRunnable {
|
|
// NO Q_OBJECT — already inherited from QQuickImageResponse
|
|
public:
|
|
explicit AsyncImageResponse(std::function<QImage()> job);
|
|
|
|
QQuickTextureFactory *textureFactory() const override;
|
|
void cancel() override;
|
|
void run() override;
|
|
|
|
private:
|
|
std::function<QImage()> m_job;
|
|
QAtomicInt m_cancelled{0};
|
|
QImage m_image;
|
|
};
|