author | koda |
Thu, 28 Feb 2013 22:59:22 +0100 | |
changeset 8609 | 3f6c08223aa1 |
parent 7765 | 1e162c1d6dc7 |
child 8891 | bf67b4d7d7b4 |
permissions | -rw-r--r-- |
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, |
|
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7737
diff
changeset
|
21 |
Ignore = Qt::UserRole + 5, |
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7737
diff
changeset
|
22 |
InGame = Qt::UserRole + 6 |
7725 | 23 |
}; |
24 |
||
7728 | 25 |
enum SpecialRoles { |
7731 | 26 |
SortRole = Qt::UserRole + 100, |
27 |
RoomFilterRole = Qt::UserRole + 101 |
|
7728 | 28 |
}; |
29 |
||
7723 | 30 |
explicit PlayersListModel(QObject *parent = 0); |
31 |
||
7725 | 32 |
int rowCount(const QModelIndex &parent = QModelIndex()) const; |
33 |
||
34 |
QVariant data(const QModelIndex &index, int role) const; |
|
35 |
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole); |
|
7737 | 36 |
void setFlag(const QString & nickname, StateFlag flagType, bool isSet); |
37 |
bool isFlagSet(const QString & nickname, StateFlag flagType); |
|
7725 | 38 |
|
39 |
bool insertRow(int row, const QModelIndex &parent = QModelIndex()); |
|
40 |
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
41 |
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
42 |
||
7723 | 43 |
public slots: |
44 |
void addPlayer(const QString & nickname); |
|
7725 | 45 |
void removePlayer(const QString & nickname); |
7731 | 46 |
void playerJoinedRoom(const QString & nickname); |
47 |
void playerLeftRoom(const QString & nickname); |
|
48 |
void resetRoomFlags(); |
|
7732 | 49 |
void setNickname(const QString & nickname); |
7725 | 50 |
|
51 |
private: |
|
52 |
QHash<quint32, QIcon> & m_icons(); |
|
53 |
typedef QHash<int, QVariant> DataEntry; |
|
54 |
QList<DataEntry> m_data; |
|
7732 | 55 |
QSet<QString> m_friendsSet, m_ignoredSet; |
56 |
QString m_nickname; |
|
57 |
||
7725 | 58 |
void updateIcon(const QModelIndex & index); |
7728 | 59 |
void updateSortData(const QModelIndex & index); |
7732 | 60 |
void loadSet(QSet<QString> & set, const QString & suffix); |
61 |
void saveSet(const QSet<QString> & set, const QString & suffix); |
|
62 |
void checkFriendIgnore(const QModelIndex & mi); |
|
7723 | 63 |
}; |
64 |
||
65 |
#endif // PLAYERSLISTMODEL_H |