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

+107 -186
View File
@@ -2,6 +2,7 @@
#include <QSignalSpy>
#include <QSettings>
#include "backend/AppState.h"
#include "backend/LibraryModel.h"
class AppStateTest : public QObject {
Q_OBJECT
@@ -30,54 +31,6 @@ private slots:
QCOMPARE(state2.lastFilePath(), QStringLiteral("/books/test.epub"));
}
void saveAndRestoreLastChapter()
{
{
AppState state;
state.setLastChapter(5);
state.save();
}
AppState state2;
state2.restore();
QCOMPARE(state2.lastChapter(), 5);
}
void saveAndRestoreLastScrollPosition()
{
{
AppState state;
state.setLastScrollPosition(542.5);
state.save();
}
AppState state2;
state2.restore();
QCOMPARE(state2.lastScrollPosition(), 542.5);
}
void saveAndRestoreLastScrollIndex()
{
{
AppState state;
state.setLastScrollIndex(42);
state.save();
}
AppState state2;
state2.restore();
QCOMPARE(state2.lastScrollIndex(), 42);
}
void saveAndRestoreLastScrollOffset()
{
{
AppState state;
state.setLastScrollOffset(123.75);
state.save();
}
AppState state2;
state2.restore();
QCOMPARE(state2.lastScrollOffset(), 123.75);
}
void saveAndRestoreMargins()
{
{
@@ -139,10 +92,6 @@ private slots:
AppState state;
state.restore();
QVERIFY(state.lastFilePath().isEmpty());
QCOMPARE(state.lastChapter(), 0);
QCOMPARE(state.lastScrollPosition(), 0.0);
QCOMPARE(state.lastScrollIndex(), 0);
QCOMPARE(state.lastScrollOffset(), 0.0);
QCOMPARE(state.horizontalMargin(), 32);
QCOMPARE(state.verticalMargin(), 8);
QCOMPARE(state.fontSize(), 16);
@@ -157,10 +106,6 @@ private slots:
{
AppState state;
QSignalSpy spyFilePath(&state, &AppState::lastFilePathChanged);
QSignalSpy spyChapter(&state, &AppState::lastChapterChanged);
QSignalSpy spyScroll(&state, &AppState::lastScrollPositionChanged);
QSignalSpy spyScrollIndex(&state, &AppState::lastScrollIndexChanged);
QSignalSpy spyScrollOffset(&state, &AppState::lastScrollOffsetChanged);
QSignalSpy spyHMargin(&state, &AppState::horizontalMarginChanged);
QSignalSpy spyVMargin(&state, &AppState::verticalMarginChanged);
QSignalSpy spyFontSize(&state, &AppState::fontSizeChanged);
@@ -171,10 +116,6 @@ private slots:
QSignalSpy spyY(&state, &AppState::windowYChanged);
state.setLastFilePath(QStringLiteral("/foo.txt"));
state.setLastChapter(3);
state.setLastScrollPosition(10.5);
state.setLastScrollIndex(7);
state.setLastScrollOffset(55.25);
state.setHorizontalMargin(64);
state.setVerticalMargin(24);
state.setFontSize(20);
@@ -185,10 +126,6 @@ private slots:
state.setWindowY(150);
QCOMPARE(spyFilePath.count(), 1);
QCOMPARE(spyChapter.count(), 1);
QCOMPARE(spyScroll.count(), 1);
QCOMPARE(spyScrollIndex.count(), 1);
QCOMPARE(spyScrollOffset.count(), 1);
QCOMPARE(spyHMargin.count(), 1);
QCOMPARE(spyVMargin.count(), 1);
QCOMPARE(spyFontSize.count(), 1);
@@ -202,49 +139,41 @@ private slots:
void saveAndLoadBookPosition()
{
AppState state;
state.saveBookPosition(QStringLiteral("/books/a.epub"), 3, 42, 123.5);
state.saveBookPosition(QStringLiteral("/books/a.epub"), 5, 120);
QVariantMap pos = state.loadBookPosition(QStringLiteral("/books/a.epub"));
QCOMPARE(pos["chapter"].toInt(), 3);
QCOMPARE(pos["scrollIndex"].toInt(), 42);
QCOMPARE(pos["scrollOffset"].toDouble(), 123.5);
QCOMPARE(pos[QStringLiteral("chunkIndex")].toInt(), 5);
QCOMPARE(pos[QStringLiteral("intraChunkOffset")].toInt(), 120);
}
void loadBookPositionForUnknownBook()
{
AppState state;
QVariantMap pos = state.loadBookPosition(QStringLiteral("/books/unknown.epub"));
QCOMPARE(pos["chapter"].toInt(), 0);
QCOMPARE(pos["scrollIndex"].toInt(), 0);
QCOMPARE(pos["scrollOffset"].toDouble(), 0.0);
QCOMPARE(pos[QStringLiteral("chunkIndex")].toInt(), 0);
QCOMPARE(pos[QStringLiteral("intraChunkOffset")].toInt(), 0);
}
void saveBookPositionForMultipleBooks()
{
AppState state;
state.saveBookPosition(QStringLiteral("/books/a.epub"), 1, 10, 50.0);
state.saveBookPosition(QStringLiteral("/books/b.epub"), 5, 99, 200.5);
state.saveBookPosition(QStringLiteral("/books/a.epub"), 10, 50);
state.saveBookPosition(QStringLiteral("/books/b.epub"), 20, 200);
QVariantMap posA = state.loadBookPosition(QStringLiteral("/books/a.epub"));
QVariantMap posB = state.loadBookPosition(QStringLiteral("/books/b.epub"));
QCOMPARE(posA["chapter"].toInt(), 1);
QCOMPARE(posA["scrollIndex"].toInt(), 10);
QCOMPARE(posB["chapter"].toInt(), 5);
QCOMPARE(posB["scrollIndex"].toInt(), 99);
QCOMPARE(posB["scrollOffset"].toDouble(), 200.5);
QCOMPARE(posA[QStringLiteral("chunkIndex")].toInt(), 10);
QCOMPARE(posA[QStringLiteral("intraChunkOffset")].toInt(), 50);
QCOMPARE(posB[QStringLiteral("chunkIndex")].toInt(), 20);
QCOMPARE(posB[QStringLiteral("intraChunkOffset")].toInt(), 200);
}
void saveBookPositionOverwritesPrevious()
{
AppState state;
state.saveBookPosition(QStringLiteral("/books/a.epub"), 1, 10, 50.0);
state.saveBookPosition(QStringLiteral("/books/a.epub"), 7, 33, 88.0);
state.saveBookPosition(QStringLiteral("/books/a.epub"), 10, 50);
state.saveBookPosition(QStringLiteral("/books/a.epub"), 15, 88);
QVariantMap pos = state.loadBookPosition(QStringLiteral("/books/a.epub"));
QCOMPARE(pos["chapter"].toInt(), 7);
QCOMPARE(pos["scrollIndex"].toInt(), 33);
QCOMPARE(pos["scrollOffset"].toDouble(), 88.0);
QCOMPARE(pos[QStringLiteral("chunkIndex")].toInt(), 15);
QCOMPARE(pos[QStringLiteral("intraChunkOffset")].toInt(), 88);
}
void restoreEmitsSingleSignal()
@@ -253,10 +182,6 @@ private slots:
QSignalSpy spyRestored(&state, &AppState::stateRestored);
QSignalSpy spyFilePath(&state, &AppState::lastFilePathChanged);
QSignalSpy spyChapter(&state, &AppState::lastChapterChanged);
QSignalSpy spyScroll(&state, &AppState::lastScrollPositionChanged);
QSignalSpy spyScrollIndex(&state, &AppState::lastScrollIndexChanged);
QSignalSpy spyScrollOffset(&state, &AppState::lastScrollOffsetChanged);
QSignalSpy spyHMargin(&state, &AppState::horizontalMarginChanged);
QSignalSpy spyVMargin(&state, &AppState::verticalMarginChanged);
QSignalSpy spyFontSize(&state, &AppState::fontSizeChanged);
@@ -271,10 +196,6 @@ private slots:
QCOMPARE(spyRestored.count(), 1);
QCOMPARE(spyFilePath.count(), 0);
QCOMPARE(spyChapter.count(), 0);
QCOMPARE(spyScroll.count(), 0);
QCOMPARE(spyScrollIndex.count(), 0);
QCOMPARE(spyScrollOffset.count(), 0);
QCOMPARE(spyHMargin.count(), 0);
QCOMPARE(spyVMargin.count(), 0);
QCOMPARE(spyFontSize.count(), 0);
@@ -343,153 +264,155 @@ private slots:
void libraryBooksInitiallyEmpty()
{
AppState state;
QVERIFY(state.libraryBooks().isEmpty());
auto* model = qobject_cast<QAbstractListModel*>(state.libraryModel());
QVERIFY(model->rowCount() == 0);
}
void addLibraryBookAddsEntry()
{
AppState state;
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Title A"),
QStringLiteral("Author A"), 0.0);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.0);
QVariantList books = state.libraryBooks();
QCOMPARE(books.size(), 1);
QVariantMap book = books.first().toMap();
QCOMPARE(book[QStringLiteral("filePath")].toString(), QStringLiteral("/books/a.epub"));
QCOMPARE(book[QStringLiteral("title")].toString(), QStringLiteral("Title A"));
QCOMPARE(book[QStringLiteral("author")].toString(), QStringLiteral("Author A"));
QCOMPARE(book[QStringLiteral("progress")].toDouble(), 0.0);
auto* model = qobject_cast<QAbstractListModel*>(state.libraryModel());
QCOMPARE(model->rowCount(), 1);
// Get data from the model
QModelIndex index = model->index(0);
QString filePath = model->data(index, LibraryModel::FilePathRole).toString();
double progress = model->data(index, LibraryModel::ProgressRole).toDouble();
QCOMPARE(filePath, QStringLiteral("/books/a.epub"));
QCOMPARE(progress, 0.0);
// Title and author are now loaded asynchronously from file metadata
// QString title = model->data(index, 2).toString(); // TitleRole = 2
// QString author = model->data(index, 3).toString(); // AuthorRole = 3
// QCOMPARE(title, QStringLiteral("Title A"));
// QCOMPARE(author, QStringLiteral("Author A"));
}
void addLibraryBookPersistsThroughSaveRestore()
{
{
AppState state;
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Title A"),
QStringLiteral("Author A"), 0.5);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.5);
state.save();
}
AppState state2;
state2.restore();
QVariantList books = state2.libraryBooks();
QCOMPARE(books.size(), 1);
QVariantMap book = books.first().toMap();
QCOMPARE(book[QStringLiteral("filePath")].toString(), QStringLiteral("/books/a.epub"));
QCOMPARE(book[QStringLiteral("title")].toString(), QStringLiteral("Title A"));
QCOMPARE(book[QStringLiteral("progress")].toDouble(), 0.5);
auto* model = qobject_cast<QAbstractListModel*>(state2.libraryModel());
QCOMPARE(model->rowCount(), 1);
QModelIndex index = model->index(0);
QString filePath = model->data(index, LibraryModel::FilePathRole).toString();
double progress = model->data(index, LibraryModel::ProgressRole).toDouble();
QCOMPARE(filePath, QStringLiteral("/books/a.epub"));
// Title is now loaded asynchronously from file metadata
// QString title = model->data(index, 2).toString(); // TitleRole = 2
// QCOMPARE(title, QStringLiteral("Title A"));
QCOMPARE(progress, 0.5);
}
void addLibraryBookUpdatesMetadata()
{
AppState state;
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Old Title"),
QStringLiteral("Old Author"), 0.3);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("New Title"),
QStringLiteral("New Author"), 0.3);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.3);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.3);
QVariantList books = state.libraryBooks();
QCOMPARE(books.size(), 1);
QVariantMap book = books.first().toMap();
QCOMPARE(book[QStringLiteral("title")].toString(), QStringLiteral("New Title"));
QCOMPARE(book[QStringLiteral("author")].toString(), QStringLiteral("New Author"));
auto* model = qobject_cast<QAbstractListModel*>(state.libraryModel());
QCOMPARE(model->rowCount(), 1);
QModelIndex index = model->index(0);
// Title and author are now loaded asynchronously from file metadata
// QString title = model->data(index, 2).toString(); // TitleRole = 2
// QString author = model->data(index, 3).toString(); // AuthorRole = 3
// QCOMPARE(title, QStringLiteral("New Title"));
// QCOMPARE(author, QStringLiteral("New Author"));
}
void addLibraryBookOverwritesProgress()
{
AppState state;
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Title A"),
QStringLiteral("Author A"), 0.6);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.6);
// Lower value should overwrite (always update, no max logic)
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Title A"),
QStringLiteral("Author A"), 0.2);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.2);
QVariantList books = state.libraryBooks();
QCOMPARE(books.size(), 1);
QCOMPARE(books.first().toMap()[QStringLiteral("progress")].toDouble(), 0.2);
auto* model = qobject_cast<QAbstractListModel*>(state.libraryModel());
QCOMPARE(model->rowCount(), 1);
QModelIndex index = model->index(0);
double progress = model->data(index, LibraryModel::ProgressRole).toDouble();
QCOMPARE(progress, 0.2);
}
void addLibraryBookSentinelPreservesProgress()
{
AppState state;
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Title A"),
QStringLiteral("Author A"), 0.5);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.5);
// -1.0 sentinel: update metadata but don't touch progress
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("New Title"),
QStringLiteral("Author A"), -1.0);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), -1.0);
QVariantList books = state.libraryBooks();
QCOMPARE(books.size(), 1);
QVariantMap book = books.first().toMap();
QCOMPARE(book[QStringLiteral("progress")].toDouble(), 0.5);
QCOMPARE(book[QStringLiteral("title")].toString(), QStringLiteral("New Title"));
auto* model = qobject_cast<QAbstractListModel*>(state.libraryModel());
QCOMPARE(model->rowCount(), 1);
QModelIndex index = model->index(0);
double progress = model->data(index, LibraryModel::ProgressRole).toDouble();
QCOMPARE(progress, 0.5);
// Title is now loaded asynchronously from file metadata
// QString title = model->data(index, 2).toString(); // TitleRole = 2
// QCOMPARE(title, QStringLiteral("New Title"));
}
void addNewLibraryBookWithSentinelStartsAtZero()
{
AppState state;
// New book added with sentinel should start at 0%
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Title A"),
QStringLiteral("Author A"), -1.0);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), -1.0);
QVariantList books = state.libraryBooks();
QCOMPARE(books.size(), 1);
QCOMPARE(books.first().toMap()[QStringLiteral("progress")].toDouble(), 0.0);
auto* model = qobject_cast<QAbstractListModel*>(state.libraryModel());
QCOMPARE(model->rowCount(), 1);
QModelIndex index = model->index(0);
double progress = model->data(index, LibraryModel::ProgressRole).toDouble();
QCOMPARE(progress, 0.0);
}
void removeLibraryBookRemovesEntry()
{
AppState state;
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Title A"),
QStringLiteral("Author A"), 0.5);
state.addOrUpdateLibraryBook(QStringLiteral("/books/b.epub"),
QStringLiteral("Title B"),
QStringLiteral("Author B"), 0.3);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.5);
state.addOrUpdateLibraryBook(QStringLiteral("/books/b.epub"), 0.3);
state.removeLibraryBook(QStringLiteral("/books/a.epub"));
QVariantList books = state.libraryBooks();
QCOMPARE(books.size(), 1);
QCOMPARE(books.first().toMap()[QStringLiteral("filePath")].toString(),
QStringLiteral("/books/b.epub"));
auto* model = qobject_cast<QAbstractListModel*>(state.libraryModel());
QCOMPARE(model->rowCount(), 1);
QModelIndex index = model->index(0);
QString filePath = model->data(index, LibraryModel::FilePathRole).toString();
QCOMPARE(filePath, QStringLiteral("/books/b.epub"));
}
void removeNonexistentLibraryBookIsNoop()
{
AppState state;
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Title A"),
QStringLiteral("Author A"), 0.5);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.5);
state.removeLibraryBook(QStringLiteral("/books/nonexistent.epub"));
QCOMPARE(state.libraryBooks().size(), 1);
auto* model = qobject_cast<QAbstractListModel*>(state.libraryModel());
QCOMPARE(model->rowCount(), 1);
}
void libraryBooksChangedSignalOnAdd()
{
AppState state;
QSignalSpy spy(&state, &AppState::libraryBooksChanged);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Title A"),
QStringLiteral("Author A"), 0.0);
auto* model = qobject_cast<QAbstractListModel*>(state.libraryModel());
QSignalSpy spy(model, &QAbstractListModel::rowsInserted);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.0);
QCOMPARE(spy.count(), 1);
}
void libraryBooksChangedSignalOnRemove()
{
AppState state;
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Title A"),
QStringLiteral("Author A"), 0.0);
QSignalSpy spy(&state, &AppState::libraryBooksChanged);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.0);
auto* model = qobject_cast<QAbstractListModel*>(state.libraryModel());
QSignalSpy spy(model, &QAbstractListModel::rowsRemoved);
state.removeLibraryBook(QStringLiteral("/books/a.epub"));
QCOMPARE(spy.count(), 1);
}
@@ -497,20 +420,18 @@ private slots:
void multipleLibraryBooksAreStoredInOrder()
{
AppState state;
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"),
QStringLiteral("Title A"),
QStringLiteral("Author A"), 0.1);
state.addOrUpdateLibraryBook(QStringLiteral("/books/b.epub"),
QStringLiteral("Title B"),
QStringLiteral("Author B"), 0.2);
state.addOrUpdateLibraryBook(QStringLiteral("/books/a.epub"), 0.1);
state.addOrUpdateLibraryBook(QStringLiteral("/books/b.epub"), 0.2);
QVariantList books = state.libraryBooks();
QCOMPARE(books.size(), 2);
auto* model = qobject_cast<QAbstractListModel*>(state.libraryModel());
QCOMPARE(model->rowCount(), 2);
// Most recently added/updated comes first
QCOMPARE(books.at(0).toMap()[QStringLiteral("filePath")].toString(),
QStringLiteral("/books/b.epub"));
QCOMPARE(books.at(1).toMap()[QStringLiteral("filePath")].toString(),
QStringLiteral("/books/a.epub"));
QModelIndex index0 = model->index(0);
QModelIndex index1 = model->index(1);
QString filePath0 = model->data(index0, LibraryModel::FilePathRole).toString();
QString filePath1 = model->data(index1, LibraryModel::FilePathRole).toString();
QCOMPARE(filePath0, QStringLiteral("/books/b.epub"));
QCOMPARE(filePath1, QStringLiteral("/books/a.epub"));
}
};