hopefully true virtual list layout
This commit is contained in:
10 files changed
+522
-37
No files matched your search
@@ -51,6 +51,29 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class ManyChunksTextReader : 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("Many Chunks"); }
|
||||
QString author() const override { return QStringLiteral("Author"); }
|
||||
QString filePath() const override { return QStringLiteral("/fake/many.epub"); }
|
||||
QString coverImageUrl() const override { return {}; }
|
||||
QByteArray contentHash() const override { return QByteArray("manychunks"); }
|
||||
bool loadMetadata(const QString &) override { return true; }
|
||||
|
||||
QStringList chunks() const override
|
||||
{
|
||||
QStringList list;
|
||||
list.reserve(60);
|
||||
for (int i = 0; i < 60; ++i) {
|
||||
list.append(QStringLiteral("<p>Paragraph chunk number %1 with some text content.</p>").arg(i));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
};
|
||||
|
||||
class ReadingModelTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -243,6 +266,29 @@ private slots:
|
||||
model.setReader(nullptr);
|
||||
QCOMPARE(model.useBookColours(), false);
|
||||
}
|
||||
|
||||
void visibleFirstLayoutAndOnDemandLayout()
|
||||
{
|
||||
Ctx ctx;
|
||||
ReadingModel model(*ctx.store);
|
||||
ManyChunksTextReader reader;
|
||||
QSignalSpy restoreSpy(&model, &ReadingModel::restoreReady);
|
||||
|
||||
model.setReader(&reader);
|
||||
|
||||
// restoreReady must be emitted immediately from Phase 1 (<1ms)
|
||||
QCOMPARE(restoreSpy.count(), 1);
|
||||
QCOMPARE(restoreSpy.first().at(0).toInt(), 0);
|
||||
|
||||
// Row 0..25 are laid out immediately
|
||||
QVERIFY(model.data(model.index(0, 0), ReadingModel::PixelHeightRole).toReal() > 0);
|
||||
QVERIFY(!model.data(model.index(0, 0), ReadingModel::LayoutRole).value<ChunkLayout>().lines.isEmpty());
|
||||
|
||||
// Far-away row (e.g. 55) layout should be computed on-demand if queried
|
||||
QVERIFY(model.data(model.index(55, 0), ReadingModel::PixelHeightRole).toReal() > 0);
|
||||
const auto layout55 = model.data(model.index(55, 0), ReadingModel::LayoutRole).value<ChunkLayout>();
|
||||
QVERIFY(!layout55.lines.isEmpty());
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(ReadingModelTest)
|
||||
|
||||
Reference in new issue
Block a user