7723
|
1 |
#ifndef PLAYERSLISTMODEL_H
|
|
2 |
#define PLAYERSLISTMODEL_H
|
|
3 |
|
7725
|
4 |
#include <QAbstractListModel>
|
|
5 |
#include <QHash>
|
|
6 |
#include <QIcon>
|
|
7 |
#include <QModelIndex>
|
7723
|
8 |
|
7725
|
9 |
class PlayersListModel : public QAbstractListModel
|
7723
|
10 |
{
|
|
11 |
Q_OBJECT
|
7725
|
12 |
|
7723
|
13 |
public:
|
7725
|
14 |
enum StateFlag {
|
|
15 |
Ready = Qt::UserRole,
|
|
16 |
ServerAdmin = Qt::UserRole + 1,
|
|
17 |
RoomAdmin = Qt::UserRole + 2,
|
|
18 |
Registered = Qt::UserRole + 3,
|
|
19 |
Friend = Qt::UserRole + 4,
|
|
20 |
Ignore = Qt::UserRole + 5
|
|
21 |
};
|
|
22 |
|
7728
|
23 |
enum SpecialRoles {
|
7731
|
24 |
SortRole = Qt::UserRole + 100,
|
|
25 |
RoomFilterRole = Qt::UserRole + 101
|
7728
|
26 |
};
|
|
27 |
|
7723
|
28 |
explicit PlayersListModel(QObject *parent = 0);
|
|
29 |
|
7725
|
30 |
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
31 |
|
|
32 |
QVariant data(const QModelIndex &index, int role) const;
|
|
33 |
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
|
|
34 |
|
|
35 |
bool insertRow(int row, const QModelIndex &parent = QModelIndex());
|
|
36 |
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
|
37 |
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
|
38 |
|
7723
|
39 |
public slots:
|
|
40 |
void addPlayer(const QString & nickname);
|
7725
|
41 |
void removePlayer(const QString & nickname);
|
7731
|
42 |
void playerJoinedRoom(const QString & nickname);
|
|
43 |
void playerLeftRoom(const QString & nickname);
|
7725
|
44 |
void setFlag(const QString & nickname, StateFlag flagType, bool isSet);
|
7731
|
45 |
void resetRoomFlags();
|
7725
|
46 |
|
|
47 |
private:
|
|
48 |
QHash<quint32, QIcon> & m_icons();
|
|
49 |
typedef QHash<int, QVariant> DataEntry;
|
|
50 |
QList<DataEntry> m_data;
|
|
51 |
void updateIcon(const QModelIndex & index);
|
7728
|
52 |
void updateSortData(const QModelIndex & index);
|
7723
|
53 |
};
|
|
54 |
|
|
55 |
#endif // PLAYERSLISTMODEL_H
|