old render cleanup part 3

This commit is contained in:
Agel committed 2026-10-25 15:43:51 +01:00
1 parent cef762c3ee
commit 3faedd4251
45 files changed
+1057 -1135

No files matched your search

+81 -8
View File
@@ -10,8 +10,9 @@
class FakeMangaReader : public FormatReader {
public:
ReadingMode mode() const override { return ReadingMode::Comic; }
bool open(const QString &) override { return true; }
QString lastError() override { return {}; }
QString lastError() const override { return {}; }
QVector<PageInfo> pages() const override
{
return {
@@ -20,13 +21,37 @@ public:
{QStringLiteral("image://cbz/2.jpg"), QSize(800, 1200)}
};
}
QString title() override { return QStringLiteral("Manga Title"); }
QString author() override { return QStringLiteral("Manga Author"); }
QString filePath() override { return QStringLiteral("/fake/manga.cbz"); }
QString coverImagePath() override { return QStringLiteral("0.jpg"); }
QByteArray contentHash() override { return QByteArray("mangahash"); }
QString title() const override { return QStringLiteral("Manga Title"); }
QString author() const override { return QStringLiteral("Manga Author"); }
QString filePath() const override { return QStringLiteral("/fake/manga.cbz"); }
QString coverImageUrl() const override { return QStringLiteral("image://cbz/0.jpg?src=/fake/manga.cbz"); }
QByteArray contentHash() const override { return QByteArray("mangahash"); }
bool loadMetadata(const QString &) override { return true; }
QString fileType() const override { return QStringLiteral("cbz"); }
};
class FakeTextReader : public FormatReader {
public:
ReadingMode mode() const override { return ReadingMode::Text; }
bool open(const QString &) override { return true; }
QString lastError() const override { return {}; }
QString title() const override { return QStringLiteral("Text Book"); }
QString author() const override { return QStringLiteral("Text Author"); }
QString filePath() const override { return QStringLiteral("/fake/book.epub"); }
QString coverImageUrl() const override { return QStringLiteral("image://epub/cover.jpg?src=/fake/book.epub"); }
QByteArray contentHash() const override { return QByteArray("texthash"); }
bool loadMetadata(const QString &) override { return true; }
int chapterCount() const override { return 2; }
Chapter loadChapter(int index) const override
{
if (index == 0)
return {0, QStringLiteral("Chapter 1"), {QStringLiteral("<p>Chunk 1</p>"), QStringLiteral("<p>Chunk 2</p>")}};
return {1, QStringLiteral("Chapter 2"), {QStringLiteral("<p>Chunk 3</p>")}};
}
QVector<TocEntry> tableOfContents() const override
{
return {{QStringLiteral("Chapter 1"), 0, 0}, {QStringLiteral("Chapter 2"), 1, 0}};
}
};
class ReadingModelTest : public QObject {
@@ -53,6 +78,7 @@ private slots:
void initialState()
{
Ctx ctx; ReadingModel model(*ctx.store);
QVERIFY(!model.isTextMode());
QCOMPARE(model.progress(), 0.0);
QCOMPARE(model.currentPage(), 0);
QCOMPARE(model.totalPages(), 0);
@@ -69,6 +95,7 @@ private slots:
model.setReader(&reader);
QVERIFY(!model.isTextMode());
QCOMPARE(model.imageUrlForChunk(0), QStringLiteral("image://cbz/0.jpg"));
QCOMPARE(model.imageUrlForChunk(1), QStringLiteral("image://cbz/1.jpg"));
QCOMPARE(model.imageUrlForChunk(2), QStringLiteral("image://cbz/2.jpg"));
@@ -80,18 +107,24 @@ private slots:
QCOMPARE(restoreSpy.first().at(0).toInt(), 0);
}
void scrollInfoUpdatesCurrentPageAndProgress()
void scrollInfoUpdatesCurrentPageAndProgressAndSaves()
{
Ctx ctx; ReadingModel model(*ctx.store);
FakeMangaReader reader;
model.setReader(&reader);
QSignalSpy pageSpy(&model, &ReadingModel::currentPageChanged);
QSignalSpy savedSpy(&model, &ReadingModel::positionSaved);
model.setScrollInfo(1, 0.5);
QCOMPARE(model.currentPage(), 2);
QCOMPARE(model.progress(), 0.5);
QCOMPARE(pageSpy.count(), 1);
QCOMPARE(savedSpy.count(), 1);
const auto savedPos = ctx.store->load(reader.contentHash());
QCOMPARE(savedPos.chunkIndex, 1);
QCOMPARE(savedPos.progress, 0.5);
}
void landscapeModeAndPageShift()
@@ -134,6 +167,44 @@ private slots:
QVERIFY(!model.mangaRTL());
}
void textModeChaptersAndChunks()
{
Ctx ctx; ReadingModel model(*ctx.store);
FakeTextReader reader;
QSignalSpy modeSpy(&model, &ReadingModel::modeChanged);
QSignalSpy restoreSpy(&model, &ReadingModel::restoreReady);
model.setReader(&reader);
QCOMPARE(modeSpy.count(), 1);
QVERIFY(model.isTextMode());
QCOMPARE(model.chapterCount(), 2);
QCOMPARE(model.currentChapter(), 0);
QCOMPARE(model.chapterTitle(), QStringLiteral("Chapter 1"));
QCOMPARE(model.rowCount(), 2);
QCOMPARE(model.data(model.index(0, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk 1</p>"));
QCOMPARE(model.data(model.index(1, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk 2</p>"));
QTRY_COMPARE(restoreSpy.count(), 1);
// Next chapter navigation
QSignalSpy chapterSpy(&model, &ReadingModel::currentChapterChanged);
model.nextChapter();
QCOMPARE(chapterSpy.count(), 1);
QCOMPARE(model.currentChapter(), 1);
QCOMPARE(model.chapterTitle(), QStringLiteral("Chapter 2"));
QCOMPARE(model.rowCount(), 1);
QCOMPARE(model.data(model.index(0, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk 3</p>"));
// Previous chapter navigation
model.previousChapter();
QCOMPARE(model.currentChapter(), 0);
QCOMPARE(model.rowCount(), 2);
}
void setReaderNullResetsState()
{
Ctx ctx; ReadingModel model(*ctx.store);
@@ -145,6 +216,8 @@ private slots:
QCOMPARE(model.totalPages(), 0);
QCOMPARE(model.currentPage(), 0);
QCOMPARE(model.progress(), 0.0);
QVERIFY(!model.isTextMode());
QCOMPARE(model.rowCount(), 0);
}
};