Upgrade to Qt 6.10.3, refactor AppState for LibraryModel integration, add ChunkMeasurer tests, and update CI/docker configurations.

This commit is contained in:
Agel committed 2026-04-03 13:55:28 +02:00
1 parent 0303107fa2
commit a31b20534a
53 files changed
+2095 -880

No files matched your search

+51 -16
View File
@@ -2,12 +2,20 @@
#define READINGMODEL_H
#include <QAbstractListModel>
#include <QFuture>
#include <QString>
#include <QStringList>
#include <QVector>
#include <memory>
#include "IImageLoader.h"
class FormatReader;
struct ContentChunk {
QString html; // empty when unloaded (lazy streaming)
int chapterIndex = 0; // which chapter owns this chunk
int chunkInChapter = 0; // 0-based index within chapter (-1 for cover)
int pixelHeight = -1; // -1 = not yet measured
};
class ReadingModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(QString chapterTitle READ chapterTitle NOTIFY chapterChanged)
@@ -17,17 +25,21 @@ class ReadingModel : public QAbstractListModel {
Q_PROPERTY(int currentPage READ currentPage NOTIFY currentPageChanged)
Q_PROPERTY(int totalPages READ totalPages NOTIFY totalPagesChanged)
Q_PROPERTY(bool hasChapters READ hasChapters NOTIFY totalChaptersChanged)
Q_PROPERTY(bool measuring READ measuring NOTIFY measuringChanged)
Q_PROPERTY(qreal totalPixelHeight READ totalPixelHeight NOTIFY totalPixelHeightChanged)
public:
enum Roles {
ContentRole = Qt::UserRole + 1
ContentRole = Qt::UserRole + 1,
PixelHeightRole = Qt::UserRole + 2,
ChapterRole = Qt::UserRole + 3,
};
explicit ReadingModel(QObject *parent = nullptr);
~ReadingModel() override;
// QAbstractListModel overrides
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
QString chapterTitle() const;
@@ -37,42 +49,65 @@ public:
int currentPage() const;
int totalPages() const;
bool hasChapters() const;
bool measuring() const;
qreal totalPixelHeight() const;
void setReader(FormatReader *reader);
void setCoverImageUrl(const QString &coverImageUrl);
// Called from QML on every scroll (real-time)
Q_INVOKABLE void setScrollInfo(int topChunkIndex, qreal offsetInChunk, bool atYEnd = false);
Q_INVOKABLE void setScrollInfo(int topChunkIndex, qreal proportion);
Q_INVOKABLE void nextChapter();
Q_INVOKABLE void previousChapter();
Q_INVOKABLE void goToChapter(int index);
// Measurement
Q_INVOKABLE void measure(bool isNew);
// Preferences & state
void setContentWidth(int width);
Q_INVOKABLE void setFontParams(int fontSize, qreal lineSpacing);
void setImageLoader(std::unique_ptr<IImageLoader> loader);
signals:
void chapterChanged();
void totalChaptersChanged();
void measuringChanged();
void totalPixelHeightChanged();
void currentPageChanged();
void totalPagesChanged();
void scrollToChunkRequested(int chunkIndex);
void restoreReady(int chunkIndex, int intraChunkOffset);
private:
static constexpr qreal page_ratio = 1.5;
void loadAllChapters();
void computeChunkBytes();
void recalculateCurrentPage();
void runMeasurement(const QStringList &htmls, bool isNew);
FormatReader *m_reader = nullptr;
QString m_coverImageUrl;
int m_currentChapter = 0;
int m_totalChapters = 0;
int m_currentPage = 0;
int m_totalPages = 0;
int m_topChunkIndex = 0;
bool m_atYEnd = false;
bool m_measuring = false;
QStringList m_chunks;
QVector<int> m_chapterStartIndices; // m_chapterStartIndices[i] = first global chunk index of chapter i
QVector<QString> m_chapterTitles; // title of each chapter
QVector<ContentChunk> m_chunks;
QVector<int> m_chapterStartIndices;
QVector<QString> m_chapterTitles;
QVector<qsizetype> m_chunkBytes; // UTF-8 byte size of each chunk (all chapters)
QVector<qsizetype> m_chunkByteOffsets; // prefix sums: offset[i] = sum of bytes[0..i-1]
qsizetype m_totalBookBytes = 0;
qreal m_totalPixelHeight = 0.0;
qreal m_yOffset = 0.0;
int m_contentWidth = 0;
int m_fontSize = 0;
qreal m_lineSpacing = 0;
std::unique_ptr<IImageLoader> m_imageLoader;
QFuture<void> m_measureFuture;
};
#endif // READINGMODEL_H