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