hide chapters for formats that doesn't support it

This commit is contained in:
Agel committed 2026-03-19 22:34:34 +01:00
1 parent 353c82f6d6
commit cf1721f916
4 files changed
+45 -3

No files matched your search

+5
View File
@@ -44,6 +44,11 @@ int ReadingModel::totalChapters() const
return m_totalChapters;
}
bool ReadingModel::hasChapters() const
{
return m_totalChapters > 1;
}
double ReadingModel::progress() const
{
if (m_totalChapters == 0)
+2
View File
@@ -13,6 +13,7 @@ class ReadingModel : public QAbstractListModel {
Q_PROPERTY(int currentChapter READ currentChapter NOTIFY chapterChanged)
Q_PROPERTY(int totalChapters READ totalChapters NOTIFY totalChaptersChanged)
Q_PROPERTY(double progress READ progress NOTIFY chapterChanged)
Q_PROPERTY(bool hasChapters READ hasChapters NOTIFY totalChaptersChanged)
public:
enum Roles {
@@ -30,6 +31,7 @@ public:
int currentChapter() const;
int totalChapters() const;
double progress() const;
bool hasChapters() const;
void setReader(FormatReader *reader);
Q_INVOKABLE void nextChapter();
+3 -3
View File
@@ -15,7 +15,7 @@ Rectangle {
Text {
anchors.verticalCenter: parent.verticalCenter
x: parent.width * 0.5
text: bookController.hasBook
text: bookController.hasBook && readingModel.hasChapters
? "Chapter " + (readingModel.currentChapter + 1) + " / " + readingModel.totalChapters
: ""
font.pixelSize: 11
@@ -27,8 +27,8 @@ Rectangle {
anchors.right: parent.right
anchors.rightMargin: 16
anchors.verticalCenter: parent.verticalCenter
visible: bookController.hasBook
text: bookController.hasBook
visible: bookController.hasBook && readingModel.hasChapters
text: bookController.hasBook && readingModel.hasChapters
? (readingModel.currentChapter + 1) + "/" + readingModel.totalChapters
: ""
font.pixelSize: 11
+35
View File
@@ -3,6 +3,17 @@
#include "backend/ReadingModel.h"
#include "backend/FormatReader.h"
class SingleChapterReader : public FormatReader {
public:
bool open(const QString &) override { return true; }
QString lastError() override { return {}; }
int chapterCount() override { return 1; }
Chapter loadChapter(int) override { return {0, {}, {"<p>text</p>"}}; }
QList<TocEntry> tableOfContents() override { return {}; }
QString title() override { return {}; }
QString author() override { return {}; }
};
class FakeReader : public FormatReader {
public:
bool open(const QString &) override { return true; }
@@ -218,6 +229,30 @@ private slots:
QVERIFY(roles.contains(ReadingModel::ContentRole));
QCOMPARE(roles.value(ReadingModel::ContentRole), QByteArray("content"));
}
void hasChaptersFalseForSingleChapter()
{
ReadingModel model;
SingleChapterReader reader;
model.setReader(&reader);
QVERIFY(!model.hasChapters());
}
void hasChaptersTrueForMultipleChapters()
{
ReadingModel model;
FakeReader reader; // 3 chapters
model.setReader(&reader);
QVERIFY(model.hasChapters());
}
void hasChaptersFalseInitially()
{
ReadingModel model;
QVERIFY(!model.hasChapters());
}
};
QTEST_MAIN(ReadingModelTest)