Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/BookModel.h
Show All 17 Lines | |||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | * | 19 | * | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #ifndef BOOKMODEL_H | 22 | #ifndef BOOKMODEL_H | ||
23 | #define BOOKMODEL_H | 23 | #define BOOKMODEL_H | ||
24 | 24 | | |||
25 | #include <QAbstractListModel> | 25 | #include <QAbstractListModel> | ||
26 | 26 | /** | |||
27 | * \brief Base Class to handle books, their pages and their metadata | ||||
28 | * | ||||
29 | * BookModel is an QAbstractListModel, holding the pages as a list of objects. | ||||
30 | * | ||||
31 | * It also holds metadata for the following entries as Q Properties: | ||||
32 | * | ||||
33 | * - filename. | ||||
34 | * - author | ||||
35 | * - publisher | ||||
36 | * - title | ||||
37 | * - page count. | ||||
38 | * - current page. | ||||
39 | * - acbf data | ||||
40 | * - processing | ||||
41 | * | ||||
42 | * The book model in turn is extended by ArchiveBookModel and FolderBookModel | ||||
43 | * to provide specialised functionality for archives(zip, rar, cbz, cbr) with | ||||
44 | * a book and Folders with a book and a description file. | ||||
45 | */ | ||||
27 | class BookModel : public QAbstractListModel | 46 | class BookModel : public QAbstractListModel | ||
28 | { | 47 | { | ||
29 | Q_OBJECT | 48 | Q_OBJECT | ||
49 | /** | ||||
50 | * \brief The filename of the archive that describes this book. | ||||
51 | */ | ||||
30 | Q_PROPERTY(QString filename READ filename WRITE setFilename NOTIFY filenameChanged) | 52 | Q_PROPERTY(QString filename READ filename WRITE setFilename NOTIFY filenameChanged) | ||
53 | /** | ||||
54 | * \brief The main author of this book. | ||||
55 | */ | ||||
31 | Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged) | 56 | Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged) | ||
57 | /** | ||||
58 | * \brief the name of the publisher of this book. | ||||
59 | */ | ||||
32 | Q_PROPERTY(QString publisher READ publisher WRITE setPublisher NOTIFY publisherChanged) | 60 | Q_PROPERTY(QString publisher READ publisher WRITE setPublisher NOTIFY publisherChanged) | ||
61 | /** | ||||
62 | * \brief The title of the book. | ||||
63 | */ | ||||
33 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) | 64 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) | ||
65 | /** | ||||
66 | * \brief The page count of the book. | ||||
67 | */ | ||||
34 | Q_PROPERTY(int pageCount READ pageCount NOTIFY pageCountChanged) | 68 | Q_PROPERTY(int pageCount READ pageCount NOTIFY pageCountChanged) | ||
69 | /** | ||||
70 | * \brief The page currently being read of the book. | ||||
71 | */ | ||||
35 | Q_PROPERTY(int currentPage READ currentPage WRITE setCurrentPage NOTIFY currentPageChanged) | 72 | Q_PROPERTY(int currentPage READ currentPage WRITE setCurrentPage NOTIFY currentPageChanged) | ||
36 | /** | 73 | /** | ||
37 | * The Advanced Comic Book Format data management instance associated with this book | 74 | * The Advanced Comic Book Format data management instance associated with this book | ||
38 | * This may be null | 75 | * This may be null | ||
39 | */ | 76 | */ | ||
40 | Q_PROPERTY(QObject* acbfData READ acbfData NOTIFY acbfDataChanged) | 77 | Q_PROPERTY(QObject* acbfData READ acbfData NOTIFY acbfDataChanged) | ||
78 | /** | ||||
79 | * \brief Whether or not the book is still being processed. | ||||
80 | */ | ||||
41 | Q_PROPERTY(bool processing READ processing WRITE setProcessing NOTIFY processingChanged) | 81 | Q_PROPERTY(bool processing READ processing WRITE setProcessing NOTIFY processingChanged) | ||
42 | public: | 82 | public: | ||
43 | explicit BookModel(QObject* parent = nullptr); | 83 | explicit BookModel(QObject* parent = nullptr); | ||
44 | ~BookModel() override; | 84 | ~BookModel() override; | ||
45 | 85 | | |||
86 | /** | ||||
87 | * Extra roles for the page data access. | ||||
88 | */ | ||||
46 | enum Roles { | 89 | enum Roles { | ||
47 | UrlRole = Qt::UserRole + 1, | 90 | UrlRole = Qt::UserRole + 1, // This allows access to the resource location of the page. | ||
48 | TitleRole, | 91 | TitleRole, // This allows access to the title of the page, if it has one. | ||
49 | }; | 92 | }; | ||
50 | 93 | | |||
94 | /** | ||||
95 | * \brief This gives names for the Roles enum. | ||||
96 | */ | ||||
51 | QHash<int, QByteArray> roleNames() const override; | 97 | QHash<int, QByteArray> roleNames() const override; | ||
98 | /** | ||||
99 | * \brief Access the data inside the BookModel. | ||||
100 | * @param index The QModelIndex at which you wish to access the data. | ||||
101 | * @param role An enumerator of the type of data you want to access. | ||||
102 | * Is extended by the Roles enum. | ||||
103 | * | ||||
104 | * @return a QVariant with the page data. | ||||
105 | */ | ||||
52 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | 106 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
107 | /** | ||||
108 | * @param parent The QModel index of the parent, not used here. | ||||
leinir: Very implementation detailed there, QAbstractListModels are incapable of handling tree data, so… | |||||
109 | * @returns the number of total pages there are in the Book. | ||||
110 | */ | ||||
53 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | 111 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
54 | 112 | | |||
113 | /** | ||||
114 | * \brief add a page to this book. | ||||
115 | * @param url The resource location of the page as an url. | ||||
116 | * @param title The title of the page. This is shown in a table of contents. | ||||
117 | */ | ||||
55 | virtual void addPage(QString url, QString title); | 118 | virtual void addPage(QString url, QString title); | ||
119 | /** | ||||
120 | * \brief remove all pages from the book. | ||||
121 | */ | ||||
56 | virtual void clearPages(); | 122 | virtual void clearPages(); | ||
57 | 123 | | |||
124 | /** | ||||
125 | * @return the filename of the file that describes this book. | ||||
126 | */ | ||||
58 | QString filename() const; | 127 | QString filename() const; | ||
128 | /** | ||||
129 | * \brief set the filename of the file that describes this book. | ||||
130 | */ | ||||
59 | virtual void setFilename(QString newFilename); | 131 | virtual void setFilename(QString newFilename); | ||
132 | /** | ||||
133 | * \brief Fires when the filename is changed via setfilename. | ||||
134 | */ | ||||
60 | Q_SIGNAL void filenameChanged(); | 135 | Q_SIGNAL void filenameChanged(); | ||
136 | /** | ||||
137 | * @returns the main author of the book as a QString. | ||||
138 | */ | ||||
61 | virtual QString author() const; | 139 | virtual QString author() const; | ||
140 | /** | ||||
141 | * \brief set the main author of the book as a single string. | ||||
142 | * @param newAuthor The new name associated with the author | ||||
143 | * as a single string. | ||||
144 | */ | ||||
62 | virtual void setAuthor(QString newAuthor); | 145 | virtual void setAuthor(QString newAuthor); | ||
146 | /** | ||||
147 | * \brief Fires when the author has changed via setAuthor. | ||||
148 | */ | ||||
63 | Q_SIGNAL void authorChanged(); | 149 | Q_SIGNAL void authorChanged(); | ||
150 | /** | ||||
151 | * @return the name of the publisher as a QString. | ||||
152 | */ | ||||
64 | virtual QString publisher() const; | 153 | virtual QString publisher() const; | ||
154 | /** | ||||
155 | * \brief Set the name of the publisher. | ||||
156 | * @param newPublisher String that describes the publisher's name. | ||||
157 | */ | ||||
65 | virtual void setPublisher(QString newPublisher); | 158 | virtual void setPublisher(QString newPublisher); | ||
159 | /** | ||||
160 | * \brief Fires when publisher's name has changed with setPublisher. | ||||
161 | */ | ||||
66 | Q_SIGNAL void publisherChanged(); | 162 | Q_SIGNAL void publisherChanged(); | ||
163 | /** | ||||
164 | * @return The proper title of the book as a Qstring. | ||||
165 | */ | ||||
67 | virtual QString title() const; | 166 | virtual QString title() const; | ||
167 | /** | ||||
168 | * \brief Set the title of the book. | ||||
169 | * @param newTitle A QString describing the new title. | ||||
170 | */ | ||||
68 | virtual void setTitle(QString newTitle); | 171 | virtual void setTitle(QString newTitle); | ||
172 | /** | ||||
173 | * \brief Fires when the book's title has changed via SetTitle | ||||
174 | */ | ||||
69 | Q_SIGNAL void titleChanged(); | 175 | Q_SIGNAL void titleChanged(); | ||
176 | /** | ||||
177 | * @return the total pages in the book as an int. | ||||
178 | */ | ||||
70 | virtual int pageCount() const; | 179 | virtual int pageCount() const; | ||
180 | /** | ||||
181 | * \brief Fires when the page count has changed, via for example pages | ||||
182 | * being added or removed. | ||||
183 | */ | ||||
71 | Q_SIGNAL void pageCountChanged(); | 184 | Q_SIGNAL void pageCountChanged(); | ||
72 | 185 | | |||
186 | /** | ||||
187 | * @return the number of the current page being viewed as an int. | ||||
188 | */ | ||||
73 | int currentPage() const; | 189 | int currentPage() const; | ||
74 | /** | 190 | /** | ||
75 | * | 191 | * \brief Set the current page. | ||
192 | * @param newCurrentPage Int with the index of the page to switch to. | ||||
76 | * @param updateFilesystem If this is set to false, the attributes do not get written back to the filesystem. Useful for when the information is first filled out | 193 | * @param updateFilesystem If this is set to false, the attributes do not get written back to the filesystem. Useful for when the information is first filled out | ||
77 | */ | 194 | */ | ||
78 | virtual void setCurrentPage(int newCurrentPage, bool updateFilesystem = true); | 195 | virtual void setCurrentPage(int newCurrentPage, bool updateFilesystem = true); | ||
196 | /** | ||||
197 | * \brief Fires when the current page has changed. | ||||
198 | */ | ||||
79 | Q_SIGNAL void currentPageChanged(); | 199 | Q_SIGNAL void currentPageChanged(); | ||
80 | 200 | | |||
201 | /** | ||||
202 | * @return an object with the acbf data, might be null. | ||||
203 | */ | ||||
81 | QObject* acbfData() const; | 204 | QObject* acbfData() const; | ||
82 | /** | 205 | /** | ||
83 | * This is used by subclasses who want to create one such. Until this is called | 206 | * This is used by subclasses who want to create one such. Until this is called | ||
84 | * with a valid object, acbfData is null. This function causes BookModel to take | 207 | * with a valid object, acbfData is null. This function causes BookModel to take | ||
85 | * ownership of the object. It will further delete any previous objects set as | 208 | * ownership of the object. It will further delete any previous objects set as | ||
86 | * acbfData. | 209 | * acbfData. | ||
87 | */ | 210 | */ | ||
88 | void setAcbfData(QObject* obj); | 211 | void setAcbfData(QObject* obj); | ||
212 | /** | ||||
213 | * \brief Fires when the ACBF data has changed. | ||||
214 | */ | ||||
89 | Q_SIGNAL void acbfDataChanged(); | 215 | Q_SIGNAL void acbfDataChanged(); | ||
90 | 216 | | |||
91 | // Whether or not the any processing is currently going on | 217 | /** | ||
218 | * @return Whether or not the any processing is currently going on | ||||
219 | */ | ||||
92 | bool processing() const; | 220 | bool processing() const; | ||
221 | /** | ||||
222 | * \brief Set whether it is processing or done. | ||||
223 | * @param processing Whether this model is being processed. | ||||
224 | */ | ||||
93 | void setProcessing(bool processing); | 225 | void setProcessing(bool processing); | ||
226 | /** | ||||
227 | * \brief Fires when the state of processing has changed. | ||||
228 | */ | ||||
94 | Q_SIGNAL void processingChanged(); | 229 | Q_SIGNAL void processingChanged(); | ||
230 | /** | ||||
231 | * \brief Fires when the book is done loading, and informs whether it was | ||||
232 | * succesful. | ||||
233 | * @param success Wether the book's loading was succesful | ||||
234 | * TODO: This isn't triggered by anything right now? | ||||
235 | */ | ||||
95 | Q_SIGNAL void loadingCompleted(bool success); | 236 | Q_SIGNAL void loadingCompleted(bool success); | ||
96 | 237 | | |||
97 | /** | 238 | /** | ||
98 | * @brief Swap the two pages at the specified indices | 239 | * @brief Swap the two pages at the specified indices | ||
99 | * | 240 | * | ||
100 | * @param swapThisIndex The index of the first page to be swapped | 241 | * @param swapThisIndex The index of the first page to be swapped | ||
101 | * @param withThisIndex The index of the page you want the first to be swapped with | 242 | * @param withThisIndex The index of the page you want the first to be swapped with | ||
102 | */ | 243 | */ | ||
103 | Q_INVOKABLE virtual void swapPages(int swapThisIndex, int withThisIndex); | 244 | Q_INVOKABLE virtual void swapPages(int swapThisIndex, int withThisIndex); | ||
104 | private: | 245 | private: | ||
105 | class Private; | 246 | class Private; | ||
106 | Private* d; | 247 | Private* d; | ||
107 | }; | 248 | }; | ||
108 | 249 | | |||
109 | #endif//BOOKMODEL_H | 250 | #endif//BOOKMODEL_H |
Very implementation detailed there, QAbstractListModels are incapable of handling tree data, so it seems like it would make sense to just say it gives the number of pages in the book :)