Merge branch 'remove-chapters'
# Conflicts: # src/backend/ReadingModel.h # src/qml/components/Footer.qml # tests/ReadingModelTest.cpp
This commit is contained in:
commit
43e75d3d8f
4 files changed
+43
-1
No files matched your search
@@ -49,6 +49,11 @@ int ReadingModel::totalChapters() const
|
|||||||
return m_totalChapters;
|
return m_totalChapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ReadingModel::hasChapters() const
|
||||||
|
{
|
||||||
|
return m_totalChapters > 1;
|
||||||
|
}
|
||||||
|
|
||||||
double ReadingModel::progress() const
|
double ReadingModel::progress() const
|
||||||
{
|
{
|
||||||
if (m_totalChapters == 0)
|
if (m_totalChapters == 0)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class ReadingModel : public QAbstractListModel {
|
|||||||
Q_PROPERTY(double progress READ progress NOTIFY chapterChanged)
|
Q_PROPERTY(double progress READ progress NOTIFY chapterChanged)
|
||||||
Q_PROPERTY(int currentPage READ currentPage NOTIFY currentPageChanged)
|
Q_PROPERTY(int currentPage READ currentPage NOTIFY currentPageChanged)
|
||||||
Q_PROPERTY(int totalPages READ totalPages NOTIFY totalPagesChanged)
|
Q_PROPERTY(int totalPages READ totalPages NOTIFY totalPagesChanged)
|
||||||
|
Q_PROPERTY(bool hasChapters READ hasChapters NOTIFY totalChaptersChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Roles {
|
enum Roles {
|
||||||
@@ -35,6 +36,7 @@ public:
|
|||||||
double progress() const;
|
double progress() const;
|
||||||
int currentPage() const;
|
int currentPage() const;
|
||||||
int totalPages() const;
|
int totalPages() const;
|
||||||
|
bool hasChapters() const;
|
||||||
void setReader(FormatReader *reader);
|
void setReader(FormatReader *reader);
|
||||||
|
|
||||||
// Called from QML on resize
|
// Called from QML on resize
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Rectangle {
|
|||||||
Text {
|
Text {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
x: parent.width * 0.5
|
x: parent.width * 0.5
|
||||||
text: bookController.hasBook
|
text: bookController.hasBook && readingModel.hasChapters
|
||||||
? "Chapter " + (readingModel.currentChapter + 1) + " / " + readingModel.totalChapters
|
? "Chapter " + (readingModel.currentChapter + 1) + " / " + readingModel.totalChapters
|
||||||
: ""
|
: ""
|
||||||
font.pixelSize: 11
|
font.pixelSize: 11
|
||||||
|
|||||||
@@ -3,6 +3,17 @@
|
|||||||
#include "backend/ReadingModel.h"
|
#include "backend/ReadingModel.h"
|
||||||
#include "backend/FormatReader.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 {
|
class FakeReader : public FormatReader {
|
||||||
public:
|
public:
|
||||||
bool open(const QString &) override { return true; }
|
bool open(const QString &) override { return true; }
|
||||||
@@ -337,6 +348,30 @@ private slots:
|
|||||||
int secondPage = model.currentPage();
|
int secondPage = model.currentPage();
|
||||||
QVERIFY(secondPage >= firstPage);
|
QVERIFY(secondPage >= firstPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
QTEST_MAIN(ReadingModelTest)
|
||||||
|
|||||||
Reference in new issue
Block a user