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

+19 -33
View File
@@ -7,8 +7,6 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
Asteria Qt is a cross-platform desktop book/document reader built with Qt6/C++. It is a reimplementation of [asteria-bookreader](../asteria-bookreader) (Electron/React) using a native Qt stack.
**Target platforms:** Windows and Linux (both required from day one); macOS planned
**Current dev environment:** Linux
**Feature tier:** Minimal reader — open, read
### Format Support
@@ -39,7 +37,7 @@ Full target format list (derived from actual library inventory):
### Windows Build Environment
The toolchain is at `C:\msys64\mingw64\bin\`. Call binaries directly with full paths, but prepend `/c/msys64/mingw64/bin` to `PATH` so the compiler and its runtime DLLs are resolvable:
Qt 6.10.3 is installed at `C:\msys64\opt\qt\6.10.3\mingw_64` (by `scripts/install-deps-windows.sh`). The MinGW toolchain is at `C:\msys64\mingw64\bin\`. Call binaries directly with full paths, but prepend `/c/msys64/mingw64/bin` to `PATH` so the compiler and its runtime DLLs are resolvable:
```bash
# Configure
@@ -49,27 +47,27 @@ PATH="/c/msys64/mingw64/bin:$PATH" "C:/msys64/mingw64/bin/cmake.exe" \
-DCMAKE_MAKE_PROGRAM="C:/msys64/mingw64/bin/ninja.exe" \
-DCMAKE_C_COMPILER="C:/msys64/mingw64/bin/gcc.exe" \
-DCMAKE_CXX_COMPILER="C:/msys64/mingw64/bin/g++.exe" \
-DCMAKE_PREFIX_PATH="C:/msys64/mingw64"
-DCMAKE_PREFIX_PATH="c:\msys64\opt\qt\6.10.3\mingw_64"
# Build
PATH="/c/msys64/mingw64/bin:$PATH" "C:/msys64/mingw64/bin/ninja.exe" -C build
# Test
PATH="/c/msys64/mingw64/bin:$PATH" "C:/msys64/mingw64/bin/ctest.exe" --test-dir build --output-on-failure
# Test (Qt DLLs must be on PATH so test executables can load them)
PATH="/c/msys64/opt/qt/6.10.3/mingw_64/bin:/c/msys64/mingw64/bin:$PATH" "C:/msys64/mingw64/bin/ctest.exe" --test-dir build --output-on-failure
```
Use Unix-style paths (`/c/msys64/...`) for `PATH` assignments — Windows-style paths are not recognised by the shell.
### Linux Build Environment
Base: **Ubuntu 24.04**. Ubuntu apt only ships Qt 6.4, which is too old; Qt 6.10.1 is installed via `aqtinstall`.
Base: **Ubuntu 24.04**. Ubuntu apt only ships Qt 6.4, which is too old; Qt 6.10.3 is installed via `aqtinstall`.
Run `scripts/install-deps-ubuntu.sh` to install all system packages and Qt, then:
```bash
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_PREFIX_PATH=/opt/qt/6.10.1/gcc_64
-DCMAKE_PREFIX_PATH=/opt/qt/6.10.3/gcc_64
ninja -C build
ctest --test-dir build --output-on-failure
@@ -96,8 +94,8 @@ System packages installed by the script:
GitLab CI (`.gitlab-ci.yml`), stages: `build` → `package` → `wiki`.
The CI Docker image is built from `docker/Dockerfile.build` (Ubuntu 24.04 base) and contains:
- Native Linux toolchain + Qt 6.10.1 at `$QT_LINUX_DIR` (`/opt/qt/6.10.1/gcc_64`)
- MinGW-w64 cross-compilation toolchain + Qt 6.10.1 for Windows at `$QT_WINDOWS_DIR` (`/opt/qt/6.10.1/mingw_64`)
- Native Linux toolchain + Qt 6.10.3 at `$QT_LINUX_DIR` (`/opt/qt/6.10.3/gcc_64`)
- MinGW-w64 cross-compilation toolchain + Qt 6.10.3 for Windows at `$QT_WINDOWS_DIR` (`/opt/qt/6.10.3/mingw_64`)
- Cross-compiled Windows sysroot at `$MINGW_SYSROOT` (`/opt/mingw-sysroot`) with libiconv and uchardet
- AppImage packaging tools (linuxdeploy, appimagetool)
@@ -115,41 +113,28 @@ When `CMakeLists.txt` gains a new `find_package` or `pkg_check_modules` dependen
| `scripts/install-deps-windows.sh` | `pacman` package for Windows host builds |
| `docker/Dockerfile.build` | `apt` package for CI Linux build; cross-compiled lib for CI Windows cross-build if needed |
## Architecture
Strictly follow SOLID principles.
## Development
## Test-Driven Development
**All new backend logic must be test-driven.** Follow the red-green-refactor cycle strictly:
1. **Red** — write a failing test that specifies the desired behavior before writing any implementation
2. **Green** — write the minimum implementation to make the test pass
3. **Refactor** — clean up with tests still passing
### Rules
- Never write implementation code without a corresponding failing test first
- Tests live in `tests/` mirroring the `src/backend/` structure (e.g., `tests/formats/TxtReaderTest.cpp`)
- Keep test coverage high (80%+)
- Use `Qt Test` (`QTest`) framework — include `find_package(Qt6 REQUIRED COMPONENTS Test)` in CMakeLists
- Each format reader must have a test that loads a real sample file from `tests/fixtures/`
- `BookController`, `ReadingModel`, and `AppState` must each have unit tests
- QML-only UI code is exempt from TDD; backend logic extracted to C++ is not
- Run `ctest --test-dir build --output-on-failure` before considering any task complete
- Run `ctest --test-dir build --output-on-failure` and check for test coverage before considering any task complete
## Architecture
**Strictly follow SOLID principles.**
**Backend (C++)** handles all file I/O and format parsing. **QML** handles all UI. They communicate via `QObject` models exposed to the QML engine via `setContextProperty()`.
**Position restoration:** Pixel-perfect position restoration is mandatory. On every book open, `ChunkMeasurer` pre-measures chunk heights (in background, parallel, via `IImageLoader` for images) before restoring `contentY`. Never restore using pixel offsets that were calculated before heights were measured.
### QObjects Exposed to QML
| Object | Responsibility |
|---|---|
| `BookController` | Open/close book, owns reader (via `ReaderFactory`), exposes metadata (title, author), TOC |
| `ReadingModel` | QAbstractListModel exposing chapter chunks (ContentRole), position, next/prev navigation, progress % |
| `ReadingModel` | QAbstractListModel exposing chapter chunks (ContentRole), position, next/prev navigation, progress |
| `AppState` | Window geometry, last file, preferences (`QSettings`) |
Sidebar state, header state, etc. stay as pure QML properties — no C++ needed.
### Content Model
All format readers produce normalized HTML content organized into chapters. Each chapter's content is split into chunks (a `QStringList`) at the reader level, where the format structure is known. This enables virtualized rendering via `ListView` in QML. The content model is defined in `FormatReader.h`:
@@ -182,9 +167,11 @@ Chapter mapping by format: TXT = 1 chapter (whole file). FB2 = `<section>` eleme
**ReadingModel** is a `QAbstractListModel` exposing chunks via `ContentRole`. `PageView.qml` renders chunks in a `ListView` with `cacheBuffer` for seamless scrolling — no visible seams between chunks.
**Progress tracking** to track reading position ONLY ListView y offset must be used. Current page / progress percentage must be calculated using this and total height only.
### Reader Factory
`ReaderFactory` is separate from `FormatReader`. It provides a static `create(const QString &filePath)` method with a simple extension-to-reader map. No plugin system — a switch statement is fine for ~11 formats.
`ReaderFactory` is separate from `FormatReader`. It provides a static `create(const QString &filePath)` method backed by a registration map (extension → factory function). Adding a new format requires only a new map entry — no modifications to existing factory logic (OCP). No plugin system needed.
### Async Book Opening
@@ -248,7 +235,6 @@ tests/
- Use only Qt APIs for filesystem, paths, and dialogs — no platform-specific code
- Third-party libs must be available on Windows and Linux; prefer those with CMake `find_package` or vcpkg support
- Avoid `#ifdef Q_OS_WIN` / `#ifdef Q_OS_LINUX` except where genuinely unavoidable
## Design & Color Scheme