-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchatrecordsmodel.h
More file actions
43 lines (34 loc) · 973 Bytes
/
chatrecordsmodel.h
File metadata and controls
43 lines (34 loc) · 973 Bytes
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
#ifndef CHATRECORDSMODEL_H
#define CHATRECORDSMODEL_H
#include <QObject>
#include<QAbstractListModel>
#include<QVector>
class ChatRecordItem;
class ChatRecordsModel : public QAbstractListModel
{
Q_OBJECT
public:
ChatRecordsModel(QObject *parent = nullptr);
Q_INVOKABLE void pushBack(QString content,bool direction);
Q_INVOKABLE void clear();
// QAbstractItemModel interface
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QHash<int, QByteArray> roleNames() const;
enum Role{
role1=1,
role2
};
private:
QVector<ChatRecordItem> items;
};
class ChatRecordItem{
public:
ChatRecordItem(QString content="",bool direction=false);
QString getContent() const;
bool getDirection() const;
private:
QString content;
bool direction;//true:send; false:recived
};
#endif // CHATRECORDSMODEL_H