added txt support

This commit is contained in:
Agel committed 2026-03-15 22:18:26 +01:00
1 parent 64a70bc4cf
commit 21656a3e9c
10 files changed
+441 -120

No files matched your search

+66 -5
View File
@@ -15,7 +15,8 @@ public:
return {index, {}, {}};
return {index,
QStringLiteral("Chapter %1").arg(index),
QStringLiteral("<p>Content %1</p>").arg(index)};
{QStringLiteral("<p>Chunk A of %1</p>").arg(index),
QStringLiteral("<p>Chunk B of %1</p>").arg(index)}};
}
QList<TocEntry> tableOfContents() override { return {}; }
@@ -32,8 +33,8 @@ private slots:
ReadingModel model;
QCOMPARE(model.totalChapters(), 0);
QCOMPARE(model.progress(), 0.0);
QVERIFY(model.chapterContent().isEmpty());
QVERIFY(model.chapterTitle().isEmpty());
QCOMPARE(model.rowCount(QModelIndex()), 0);
}
void setReaderLoadsFirstChapter()
@@ -45,7 +46,39 @@ private slots:
QCOMPARE(model.currentChapter(), 0);
QCOMPARE(model.totalChapters(), 3);
QCOMPARE(model.chapterTitle(), QStringLiteral("Chapter 0"));
QCOMPARE(model.chapterContent(), QStringLiteral("<p>Content 0</p>"));
}
void rowCountMatchesChunks()
{
ReadingModel model;
FakeReader reader;
model.setReader(&reader);
QCOMPARE(model.rowCount(QModelIndex()), 2);
}
void dataReturnsChunkContent()
{
ReadingModel model;
FakeReader reader;
model.setReader(&reader);
QModelIndex idx0 = model.index(0, 0);
QModelIndex idx1 = model.index(1, 0);
QCOMPARE(model.data(idx0, ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk A of 0</p>"));
QCOMPARE(model.data(idx1, ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk B of 0</p>"));
}
void dataInvalidForOutOfRange()
{
ReadingModel model;
FakeReader reader;
model.setReader(&reader);
QModelIndex badIdx = model.index(99, 0);
QVERIFY(!model.data(badIdx, ReadingModel::ContentRole).isValid());
}
void nextChapter()
@@ -60,6 +93,9 @@ private slots:
QCOMPARE(model.currentChapter(), 1);
QCOMPARE(model.chapterTitle(), QStringLiteral("Chapter 1"));
QCOMPARE(spy.count(), 1);
QCOMPARE(model.rowCount(QModelIndex()), 2);
QCOMPARE(model.data(model.index(0, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk A of 1</p>"));
}
void nextChapterAtEnd()
@@ -112,7 +148,9 @@ private slots:
model.goToChapter(2);
QCOMPARE(model.currentChapter(), 2);
QCOMPARE(model.chapterContent(), QStringLiteral("<p>Content 2</p>"));
QCOMPARE(model.rowCount(QModelIndex()), 2);
QCOMPARE(model.data(model.index(0, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk A of 2</p>"));
}
void goToChapterOutOfRange()
@@ -154,8 +192,31 @@ private slots:
QCOMPARE(model.totalChapters(), 0);
QCOMPARE(model.progress(), 0.0);
QVERIFY(model.chapterContent().isEmpty());
QVERIFY(model.chapterTitle().isEmpty());
QCOMPARE(model.rowCount(QModelIndex()), 0);
}
void navigationResetsModel()
{
ReadingModel model;
FakeReader reader;
model.setReader(&reader);
QCOMPARE(model.rowCount(QModelIndex()), 2);
// Navigate and verify model is reset with new chapter's chunks
model.nextChapter();
QCOMPARE(model.rowCount(QModelIndex()), 2);
QCOMPARE(model.data(model.index(0, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk A of 1</p>"));
}
void roleNamesContainsContent()
{
ReadingModel model;
QHash<int, QByteArray> roles = model.roleNames();
QVERIFY(roles.contains(ReadingModel::ContentRole));
QCOMPARE(roles.value(ReadingModel::ContentRole), QByteArray("content"));
}
};