Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/BookListModel.h
Show All 18 Lines | |||||
19 | * | 19 | * | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #ifndef BOOKLISTMODEL_H | 22 | #ifndef BOOKLISTMODEL_H | ||
23 | #define BOOKLISTMODEL_H | 23 | #define BOOKLISTMODEL_H | ||
24 | 24 | | |||
25 | #include "CategoryEntriesModel.h" | 25 | #include "CategoryEntriesModel.h" | ||
26 | #include <QQmlParserStatus> | 26 | #include <QQmlParserStatus> | ||
27 | 27 | /** | |||
28 | * \brief Main catalogue model class. | ||||
29 | * | ||||
30 | * BookListModel extends CategoryEntriesModel, and is the main model that | ||||
31 | * handles book entries and the different categories that books can be in. | ||||
32 | * | ||||
33 | * It also extends QQmlParseStatus to ensure that the loading the cache of | ||||
34 | * books is postponed until the application UI has been painted at least once. | ||||
leinir: It uses QQmlParseStatus to ensure that loading the cache of books is postponed until the… | |||||
35 | * | ||||
36 | * BookListModel keeps track of which books there are, how they can be sorted | ||||
37 | * and how far the reader is in reading a specific book. | ||||
38 | * | ||||
39 | * It caches its entries in the BookDataBase. | ||||
leinir: implementation-specific detail, it's enough to mention it's a cache :) | |||||
40 | * | ||||
41 | * ContentModel is the model used to enable searching the collection, it is | ||||
42 | * typically a ContentList. | ||||
43 | */ | ||||
28 | class BookListModel : public CategoryEntriesModel, public QQmlParserStatus | 44 | class BookListModel : public CategoryEntriesModel, public QQmlParserStatus | ||
29 | { | 45 | { | ||
30 | Q_OBJECT | 46 | Q_OBJECT | ||
47 | /** | ||||
48 | * \brief count holds how many entries there are in the catalogue. | ||||
49 | */ | ||||
31 | Q_PROPERTY(int count READ count NOTIFY countChanged) | 50 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
51 | /** | ||||
52 | * \brief The content model is an abstract list model that holds data to search through. | ||||
53 | */ | ||||
32 | Q_PROPERTY(QObject* contentModel READ contentModel WRITE setContentModel NOTIFY contentModelChanged) | 54 | Q_PROPERTY(QObject* contentModel READ contentModel WRITE setContentModel NOTIFY contentModelChanged) | ||
55 | /** | ||||
56 | * \brief The "newly added" category entries model manages the newly added entries. | ||||
57 | */ | ||||
33 | Q_PROPERTY(QObject* newlyAddedCategoryModel READ newlyAddedCategoryModel NOTIFY newlyAddedCategoryModelChanged) | 58 | Q_PROPERTY(QObject* newlyAddedCategoryModel READ newlyAddedCategoryModel NOTIFY newlyAddedCategoryModelChanged) | ||
59 | /** | ||||
60 | * \brief The "title" category entries model manages the sorting of entries by title. | ||||
61 | */ | ||||
34 | Q_PROPERTY(QObject* titleCategoryModel READ titleCategoryModel NOTIFY titleCategoryModelChanged) | 62 | Q_PROPERTY(QObject* titleCategoryModel READ titleCategoryModel NOTIFY titleCategoryModelChanged) | ||
63 | /** | ||||
64 | * \brief The "author" category entries model manages the sorting of entries by author. | ||||
65 | */ | ||||
35 | Q_PROPERTY(QObject* authorCategoryModel READ authorCategoryModel NOTIFY authorCategoryModelChanged) | 66 | Q_PROPERTY(QObject* authorCategoryModel READ authorCategoryModel NOTIFY authorCategoryModelChanged) | ||
67 | /** | ||||
68 | * \brief The "series" category entries model managed the sorting of entry by series. | ||||
69 | */ | ||||
36 | Q_PROPERTY(QObject* seriesCategoryModel READ seriesCategoryModel NOTIFY seriesCategoryModelChanged) | 70 | Q_PROPERTY(QObject* seriesCategoryModel READ seriesCategoryModel NOTIFY seriesCategoryModelChanged) | ||
71 | /** | ||||
72 | * \brief The "series" category entries model managed the sorting of entry by file system folder. | ||||
73 | */ | ||||
37 | Q_PROPERTY(QObject* folderCategoryModel READ folderCategoryModel NOTIFY folderCategoryModelChanged) | 74 | Q_PROPERTY(QObject* folderCategoryModel READ folderCategoryModel NOTIFY folderCategoryModelChanged) | ||
75 | /** | ||||
76 | * \brief cacheLoaded holds whether the database cache has been loaded.. | ||||
leinir: sql again :) | |||||
77 | */ | ||||
38 | Q_PROPERTY(bool cacheLoaded READ cacheLoaded NOTIFY cacheLoadedChanged) | 78 | Q_PROPERTY(bool cacheLoaded READ cacheLoaded NOTIFY cacheLoadedChanged) | ||
39 | Q_ENUMS(Grouping) | 79 | Q_ENUMS(Grouping) | ||
40 | Q_INTERFACES(QQmlParserStatus) | 80 | Q_INTERFACES(QQmlParserStatus) | ||
41 | public: | 81 | public: | ||
42 | explicit BookListModel(QObject* parent = nullptr); | 82 | explicit BookListModel(QObject* parent = nullptr); | ||
43 | ~BookListModel() override; | 83 | ~BookListModel() override; | ||
44 | 84 | | |||
85 | /** | ||||
86 | * Inherited from QmlParserStatus, not implemented. | ||||
87 | */ | ||||
45 | void classBegin() override {}; | 88 | void classBegin() override {}; | ||
89 | /** | ||||
90 | * \brief triggers the loading of the cache. | ||||
91 | * Inherited from QmlParserStatus | ||||
92 | */ | ||||
46 | void componentComplete() override; | 93 | void componentComplete() override; | ||
47 | 94 | | |||
95 | /** | ||||
96 | * \brief Enum holding the different categories implemented. | ||||
97 | */ | ||||
48 | enum Grouping { | 98 | enum Grouping { | ||
49 | GroupByNone = 0, | 99 | GroupByNone = 0, | ||
50 | GroupByRecentlyAdded, | 100 | GroupByRecentlyAdded, | ||
51 | GroupByRecentlyRead, | 101 | GroupByRecentlyRead, | ||
52 | GroupByTitle, | 102 | GroupByTitle, | ||
53 | GroupByAuthor, | 103 | GroupByAuthor, | ||
54 | GroupByPublisher | 104 | GroupByPublisher | ||
55 | }; | 105 | }; | ||
56 | 106 | | |||
leinir: (detail, whitespace, wouldn't mention it if there weren't other things ;) ) | |||||
107 | /** | ||||
108 | * @return the contentModel. Used for searching. | ||||
109 | */ | ||||
57 | QObject* contentModel() const; | 110 | QObject* contentModel() const; | ||
111 | /** | ||||
112 | * \brief set the ContentModel. | ||||
113 | * @param newModel The new content model. | ||||
114 | */ | ||||
58 | void setContentModel(QObject* newModel); | 115 | void setContentModel(QObject* newModel); | ||
116 | /** | ||||
117 | * \brief Fires when the content model has changed. | ||||
118 | */ | ||||
59 | Q_SIGNAL void contentModelChanged(); | 119 | Q_SIGNAL void contentModelChanged(); | ||
60 | 120 | | |||
121 | /** | ||||
122 | * @returns how many entries there are in the catelogue. | ||||
123 | */ | ||||
61 | int count() const; | 124 | int count() const; | ||
125 | /** | ||||
126 | * \brief Fires when the count has changed. | ||||
A random note on terminology, just 'cos and whatnot - signals "fire", they don't trigger - slots are triggered by signals firing :) leinir: A random note on terminology, just 'cos and whatnot - signals "fire", they don't trigger… | |||||
127 | */ | ||||
62 | Q_SIGNAL void countChanged(); | 128 | Q_SIGNAL void countChanged(); | ||
63 | 129 | | |||
130 | /** | ||||
131 | * @return The categoryEntriesModel that manages the sorting of entries by title. | ||||
132 | */ | ||||
64 | QObject* titleCategoryModel() const; | 133 | QObject* titleCategoryModel() const; | ||
134 | /** | ||||
135 | * \brief Fires when the titleCategoryModel has changed or finished initializing. | ||||
136 | */ | ||||
65 | Q_SIGNAL void titleCategoryModelChanged(); | 137 | Q_SIGNAL void titleCategoryModelChanged(); | ||
66 | 138 | | |||
139 | /** | ||||
140 | * @return The categoryEntriesModel that manages the recently added entries. | ||||
141 | */ | ||||
67 | QObject* newlyAddedCategoryModel() const; | 142 | QObject* newlyAddedCategoryModel() const; | ||
143 | /** | ||||
144 | * \brief Fires when the newlyAddedCategoryModel has changed or finished initializing. | ||||
145 | */ | ||||
68 | Q_SIGNAL void newlyAddedCategoryModelChanged(); | 146 | Q_SIGNAL void newlyAddedCategoryModelChanged(); | ||
69 | 147 | | |||
148 | /** | ||||
149 | * @return The categoryEntriesModel that manages the sorting of entries by author. | ||||
150 | */ | ||||
70 | QObject* authorCategoryModel() const; | 151 | QObject* authorCategoryModel() const; | ||
152 | /** | ||||
153 | * \brief Fires when the authorCategoryModel has changed or finished initializing. | ||||
154 | */ | ||||
71 | Q_SIGNAL void authorCategoryModelChanged(); | 155 | Q_SIGNAL void authorCategoryModelChanged(); | ||
72 | 156 | | |||
157 | /** | ||||
158 | * @return The categoryEntriesModel that manages the sorting of entries by series. | ||||
159 | */ | ||||
73 | QObject* seriesCategoryModel() const; | 160 | QObject* seriesCategoryModel() const; | ||
161 | /** | ||||
162 | * \brief Fires when the seriesCategoryModel has changed or finished initializing. | ||||
163 | */ | ||||
74 | Q_SIGNAL void seriesCategoryModelChanged(); | 164 | Q_SIGNAL void seriesCategoryModelChanged(); | ||
75 | // Returns the leaf model representing the series the entry with the passed URL is a part of | 165 | | ||
76 | // Base assumption: A book is only part of one series. This is not always true, but not sure how | 166 | /** | ||
77 | // to sensibly represent that | 167 | * Returns the leaf model representing the series the entry with the passed URL is a part of | ||
168 | * Base assumption: A book is only part of one series. This is not always true, but not sure how | ||||
169 | * to sensibly represent that. | ||||
170 | * | ||||
171 | * @param fileName the File Name of the entry to get the series of. | ||||
172 | */ | ||||
78 | Q_INVOKABLE QObject* seriesModelForEntry(QString fileName); | 173 | Q_INVOKABLE QObject* seriesModelForEntry(QString fileName); | ||
79 | 174 | | |||
175 | /** | ||||
176 | * @return The categoryEntriesModel that manages the sorting of entries by folder. | ||||
177 | */ | ||||
80 | QObject* folderCategoryModel() const; | 178 | QObject* folderCategoryModel() const; | ||
179 | /** | ||||
180 | * \brief Fires when the folderCategoryModel has changed or finished initializing. | ||||
181 | */ | ||||
81 | Q_SIGNAL void folderCategoryModelChanged(); | 182 | Q_SIGNAL void folderCategoryModelChanged(); | ||
82 | 183 | | |||
184 | /** | ||||
185 | * @returns whether the cache is loaded from the database. | ||||
186 | */ | ||||
83 | bool cacheLoaded() const; | 187 | bool cacheLoaded() const; | ||
188 | /** | ||||
189 | * \brief Fires when the cache is done loading. | ||||
190 | */ | ||||
84 | Q_SIGNAL void cacheLoadedChanged(); | 191 | Q_SIGNAL void cacheLoadedChanged(); | ||
85 | 192 | | |||
86 | // Update the data of a book at runtime - in particular, we need to update totalPages and currentPage | 193 | /** | ||
194 | * \brief Update the data of a book at runtime | ||||
195 | * | ||||
196 | * This is used in to update totalPages and currentPage. | ||||
197 | * | ||||
198 | * @param fileName The filename to update the page for. | ||||
199 | * @param property The property to update, can be "currentPage" or | ||||
200 | * "totalPages". | ||||
201 | * @param value The value to set it to. | ||||
202 | */ | ||||
87 | Q_INVOKABLE void setBookData(QString fileName, QString property, QString value); | 203 | Q_INVOKABLE void setBookData(QString fileName, QString property, QString value); | ||
88 | 204 | | |||
89 | // Delete a book from the model, and optionally delete the entry from file storage | 205 | /** | ||
206 | * Delete a book from the model, and optionally delete the entry from file storage. | ||||
207 | * @param fileName The filename of the book to remove. | ||||
208 | * @param deleteFile Whether to also delete the file from the disk. | ||||
209 | */ | ||||
90 | Q_INVOKABLE void removeBook(QString fileName, bool deleteFile = false); | 210 | Q_INVOKABLE void removeBook(QString fileName, bool deleteFile = false); | ||
91 | 211 | | |||
92 | // A list of the files currently known by the applications | 212 | /** | ||
213 | * \brief A list of the files currently known by the applications | ||||
214 | * @returns a QStringList with paths to known books. | ||||
215 | */ | ||||
93 | Q_INVOKABLE QStringList knownBookFiles() const; | 216 | Q_INVOKABLE QStringList knownBookFiles() const; | ||
94 | private: | 217 | private: | ||
95 | class Private; | 218 | class Private; | ||
96 | Private* d; | 219 | Private* d; | ||
97 | 220 | | |||
98 | Q_SLOT void contentModelItemsInserted(QModelIndex index,int first, int last); | 221 | Q_SLOT void contentModelItemsInserted(QModelIndex index,int first, int last); | ||
99 | }; | 222 | }; | ||
100 | 223 | | |||
101 | #endif//BOOKLISTMODEL_H | 224 | #endif//BOOKLISTMODEL_H |
It uses QQmlParseStatus to ensure that loading the cache of books is postponed until the application UI has been painted at least once.