-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooklistmodel.hpp
67 lines (62 loc) · 2.11 KB
/
booklistmodel.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef BOOKLISTMODEL_HPP
#define BOOKLISTMODEL_HPP
#include <QThread>
#include <QAbstractListModel>
#include <QStringBuilder>
#include <QQmlListProperty>
#include "barcode.hpp"
class BookListModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged)
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QString lastWorkingFile READ lastWorkingFile)
public:
enum Status { Good, Unregistered, OutOfOrder, StatusCount };
enum Role { RegistrationNumberRole = Qt::UserRole + 1, StatusRole, CallNumber, Title, Author };
BookListModel(QObject *parent = nullptr);
~BookListModel();
Q_INVOKABLE bool append(const QString ®istrationNumber);
Q_INVOKABLE void remove(int row);
Q_INVOKABLE void modify(int row, const QString ®istrationNumber);
Q_INVOKABLE QString registrationNumber(int row) const;
Q_INVOKABLE void load(const QString &fileName);
Q_INVOKABLE bool append(BarcodeObject *barcode);
Q_INVOKABLE QStringList getFileList() const;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
bool save() const;
int count() const;
QString lastWorkingFile() const;
bool isLoading() const;
signals:
void messageNotified(const QString &message);
void countChanged(int count);
void loadingChanged();
void loadingStarted();
void loadingFinished();
private slots:
void onLoadThreadFinished();
void emitCountChanged() { emit countChanged(count()); }
private:
friend class LoadThread;
void open();
void notify(const QString &number, const QString &message) {
emit messageNotified(number % ": " % message);
}
struct Data;
struct Row;
QSharedPointer<BookListModel::Data> m_data;
Data *d;
};
class LoadThread : public QThread {
Q_OBJECT
public:
LoadThread(const QString &fileName, BookListModel *model);
private:
void run();
QString m_fileName;
BookListModel *m_model;
QSharedPointer<BookListModel::Data> m_data;
};
#endif // BOOKLISTMODEL_HPP