-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfriendsmodel.h
69 lines (58 loc) · 1.54 KB
/
friendsmodel.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
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef FRIENDSMODEL_H
#define FRIENDSMODEL_H
#include<QAbstractListModel>
#include<QVector>
#include<QMap>
class FriendItem;
class FriendsModel:public QAbstractListModel
{
Q_OBJECT
public:
FriendsModel(QObject* parent=NULL);
Q_INVOKABLE void pushBack(QString ipv4,QString nickName);
Q_INVOKABLE void clear();
Q_INVOKABLE void remove(int index);
//消息提醒
void clearNewMsgCount(int index);
void addNewMsgCount(int index);
int rowCount(const QModelIndex &parent= QModelIndex() ) const;
QVariant data(const QModelIndex &index, int role) const;
QHash<int, QByteArray> roleNames() const;
// model is find by the Role
enum Role{
role1=1,
role2,
role3
};
QVector<FriendItem> getItems() const;
private:
QVector<FriendItem> items;
// QAbstractItemModel interface
};
class FriendItem{
public:
FriendItem(QString ip="",QString name=""){
this->ipv4=ip;
this->nickName=name;
this->newMsgCount=0;
}
bool operator ==(const FriendItem& item1){
if(item1.ipv4==ipv4&&
item1.nickName==nickName){
return true;
}
else{
return false;
}
}
QString getIpv4() const;
QString getNickName() const;
int getNewMsgCount() const;
void setNewMsgCount(const int &value);
private:
//note: when add a property ,you must change data() & roleNames() functions
QString ipv4;
QString nickName;
int newMsgCount;
};
#endif // FRIENDSMODEL_H