test(reading): propagate Allium specification tests for Knuth-Plass rendering pipeline
Formalize the behavioral specification for off-thread Knuth-Plass text chunk layout and virtualized QML rendering in specs/knuth-plass-rendering.allium, and introduce a test suite covering all 66 specification obligations across value types, state machine transitions, invariants, and surface contracts. To satisfy the specification's precondition and invariant contracts: - Validate and clamp initial restore chunk bounds when opening documents in ReadingModel to ensure anchor chunks remain strictly within bounds. - Guard scroll position updates against negative and out-of-bounds chunk indices to honor the ScrollPositionChanged preconditions. - Emit positionSaved on publisher color toggles to fulfill the PositionPersisted contract without triggering unnecessary relayouts. - Register KnuthPlassRenderingSpecTest in CMakeLists.txt and document the spec and test hierarchy in AGENTS.md.
This commit is contained in:
5 files changed
+1717
-3
No files matched your search
@@ -212,6 +212,13 @@ void ReadingModel::setScrollInfo(const int topChunkIndex, const qreal proportion
|
||||
|
||||
void ReadingModel::setScrollPosition(int topChunkIndex, qreal intraOffset, qreal proportion)
|
||||
{
|
||||
if (topChunkIndex < 0)
|
||||
return;
|
||||
if (m_isTextMode && !m_chunks.isEmpty() && topChunkIndex >= m_chunks.size())
|
||||
return;
|
||||
if (!m_isTextMode && !m_pages.isEmpty() && topChunkIndex >= m_pages.size())
|
||||
return;
|
||||
|
||||
m_intraOffset = intraOffset;
|
||||
const qreal clamped = qBound(0.0, proportion, 1.0);
|
||||
if (!qFuzzyCompare(m_progress, clamped)) {
|
||||
@@ -442,6 +449,7 @@ void ReadingModel::setUseBookColours(bool enabled)
|
||||
m_useBookColours = enabled;
|
||||
if (m_reader) {
|
||||
m_positions.setUseBookColours(m_reader->contentHash(), enabled);
|
||||
emit positionSaved();
|
||||
}
|
||||
emit useBookColoursChanged();
|
||||
}
|
||||
@@ -502,7 +510,12 @@ void ReadingModel::setReader(FormatReader *reader)
|
||||
beginResetModel();
|
||||
m_chunks = m_reader->chunks();
|
||||
m_totalPages = m_chunks.size();
|
||||
m_currentPage = m_totalPages > 0 ? qBound(1, restoreChunk + 1, m_totalPages) : 0;
|
||||
if (m_totalPages > 0) {
|
||||
restoreChunk = qBound(0, restoreChunk, m_totalPages - 1);
|
||||
} else {
|
||||
restoreChunk = 0;
|
||||
}
|
||||
m_currentPage = m_totalPages > 0 ? (restoreChunk + 1) : 0;
|
||||
endResetModel();
|
||||
|
||||
emit totalPagesChanged();
|
||||
@@ -514,8 +527,9 @@ void ReadingModel::setReader(FormatReader *reader)
|
||||
}
|
||||
|
||||
if (m_reader && !m_isTextMode) {
|
||||
QMetaObject::invokeMethod(this, [this, restoreChunk] {
|
||||
emit restoreReady(restoreChunk, 0.0);
|
||||
const int safeRestoreChunk = !m_pages.isEmpty() ? qBound(0, restoreChunk, m_pages.size() - 1) : 0;
|
||||
QMetaObject::invokeMethod(this, [this, safeRestoreChunk] {
|
||||
emit restoreReady(safeRestoreChunk, 0.0);
|
||||
}, Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user