-
Notifications
You must be signed in to change notification settings - Fork 2
/
model.h
57 lines (46 loc) · 1.6 KB
/
model.h
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
#ifndef MODEL_H
#define MODEL_H
#include <QAbstractListModel>
#include <QDebug>
#include <QFileInfo>
#include <QMimeType>
#include <QMimeDatabase>
#define DB_HOSTNAME "localhost"
#define DB_NAME "modeldb.db"
#define DB_TABLE "debtors"
class Model : public QAbstractListModel
{
Q_OBJECT
public:
/*
* roles for each column. ROLE_END is a flag for iteration convenience
*/
enum {
pathRole = Qt::UserRole + 1,
sizeRole,
typeRole,
mimetypeRole,
ROLE_END
};
explicit Model(QObject *parent = nullptr);
// return number of data's
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
// return data by role and index
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
// set data by role and index
// bool setData(const QModelIndex &index, const QVariant &value,
// int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
QHash<int, QByteArray> roleNames() const override;
bool insert(const QString& filename, const QString& size, const QString& type, const QString& mimetype, const QString& path, const QModelIndex &parent = QModelIndex());
public slots:
// remove an element by index
bool remove(int index, const QModelIndex &parent = QModelIndex());
bool prepareAndInsert(QString filepath);
QString getFileInfo(int index) const;
private:
QList<QVariantList> vlist;
// list of columns
const QList<QByteArray> columns{"filename", "size", "type", "mimetype"};
};
#endif // MODEL_H