#include "MeasurementController.h" #include "backend/ChunkMeasurer.h" #include MeasurementController::MeasurementController(QObject *parent) : QObject(parent) { } MeasurementController::~MeasurementController() { if (m_future.isRunning()) { m_future.cancel(); m_future.waitForFinished(); } } void MeasurementController::setImageLoader(std::unique_ptr loader) { m_imageLoader = std::move(loader); } bool MeasurementController::measuring() const { return m_measuring; } void MeasurementController::start(const QStringList &htmls, int contentWidth, int fontSize, qreal lineSpacing, bool isNew) { if (m_future.isRunning()) m_future.cancel(); m_measuring = true; emit measuringChanged(); std::unique_ptr loaderClone = m_imageLoader ? m_imageLoader->clone() : nullptr; auto measurer = std::make_shared(std::move(loaderClone), fontSize, lineSpacing); m_future = QtConcurrent::run([this, htmls, measurer, contentWidth, isNew]() { QVector heights = measurer->measure(htmls, contentWidth); QMetaObject::invokeMethod(this, [this, heights, isNew] { m_measuring = false; emit measuringChanged(); emit heightsReady(heights, isNew); }, Qt::QueuedConnection); }); }