old render cleanup part 1
This commit is contained in:
38 files changed
+166
-1366
No files matched your search
@@ -1,50 +0,0 @@
|
||||
#include "MeasurementController.h"
|
||||
|
||||
#include "backend/ChunkMeasurer.h"
|
||||
|
||||
#include <QtConcurrent>
|
||||
|
||||
MeasurementController::MeasurementController(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
MeasurementController::~MeasurementController()
|
||||
{
|
||||
if (m_future.isRunning()) {
|
||||
m_future.cancel();
|
||||
m_future.waitForFinished();
|
||||
}
|
||||
}
|
||||
|
||||
void MeasurementController::setImageLoader(std::unique_ptr<IImageLoader> 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<IImageLoader> loaderClone = m_imageLoader ? m_imageLoader->clone() : nullptr;
|
||||
auto measurer = std::make_shared<ChunkMeasurer>(std::move(loaderClone), fontSize, lineSpacing);
|
||||
|
||||
m_future = QtConcurrent::run([this, htmls, measurer, contentWidth, isNew]() {
|
||||
QVector<int> heights = measurer->measure(htmls, contentWidth);
|
||||
QMetaObject::invokeMethod(this, [this, heights, isNew] {
|
||||
m_measuring = false;
|
||||
emit measuringChanged();
|
||||
emit heightsReady(heights, isNew);
|
||||
}, Qt::QueuedConnection);
|
||||
});
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QFuture>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
#include <memory>
|
||||
|
||||
#include "backend/IImageLoader.h"
|
||||
|
||||
// Runs chunk height measurement off the GUI thread and reports the results
|
||||
// back on it. Owns the image loader used to resolve embedded images and the
|
||||
// lifetime of the in-flight measurement.
|
||||
class MeasurementController : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MeasurementController(QObject *parent = nullptr);
|
||||
~MeasurementController() override;
|
||||
|
||||
void setImageLoader(std::unique_ptr<IImageLoader> loader);
|
||||
|
||||
// isNew is passed through untouched to heightsReady so the owner knows
|
||||
// whether this measurement should trigger a position restore.
|
||||
void start(const QStringList &htmls, int contentWidth,
|
||||
int fontSize, qreal lineSpacing, bool isNew);
|
||||
|
||||
bool measuring() const;
|
||||
|
||||
signals:
|
||||
void measuringChanged();
|
||||
void heightsReady(QVector<int> heights, bool isNew);
|
||||
|
||||
private:
|
||||
std::unique_ptr<IImageLoader> m_imageLoader;
|
||||
bool m_measuring = false;
|
||||
QFuture<void> m_future;
|
||||
};
|
||||
Reference in new issue
Block a user