forked from kahduyi/cppBindqml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logmodel.h
44 lines (33 loc) · 793 Bytes
/
logmodel.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
#ifndef LOGMODEL_H
#define LOGMODEL_H
#include <QObject>
#include <QAbstractListModel>
#include <QDebug>
class Log
{
public:
Log(const QString&type, const QString&message);
QString type() const;
QString message() const;
private:
QString m_type;
QString m_message;
};
class LogModel : public QAbstractListModel
{
Q_OBJECT
public:
enum LogsRoles {
TypeRole = Qt::UserRole + 1,
MessageRole
};
explicit LogModel(QObject *parent = nullptr);
void addLog(const Log &log);
int rowCount(const QModelIndex & parent = QModelIndex()) const;
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
protected:
QHash<int, QByteArray> roleNames() const;
private:
QList<Log> m_logs;
};
#endif // LOGMODEL_H