author | koda |
Thu, 13 Jun 2013 17:01:26 +0200 | |
changeset 9221 | c4289023ddae |
parent 8891 | bf67b4d7d7b4 |
child 9503 | 8f9b04138456 |
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: |
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
44 |
void addPlayer(const QString & nickname, bool notify); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
45 |
void removePlayer(const QString & nickname, const QString & msg = QString()); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
46 |
void playerJoinedRoom(const QString & nickname, bool notify); |
7731 | 47 |
void playerLeftRoom(const QString & nickname); |
48 |
void resetRoomFlags(); |
|
7732 | 49 |
void setNickname(const QString & nickname); |
7725 | 50 |
|
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
51 |
signals: |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
52 |
void nickAdded(const QString& nick, bool notifyNick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
53 |
void nickRemoved(const QString& nick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
54 |
void nickAddedLobby(const QString& nick, bool notifyNick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
55 |
void nickRemovedLobby(const QString& nick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
56 |
void nickRemovedLobby(const QString& nick, const QString& message); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
57 |
|
7725 | 58 |
private: |
59 |
QHash<quint32, QIcon> & m_icons(); |
|
60 |
typedef QHash<int, QVariant> DataEntry; |
|
61 |
QList<DataEntry> m_data; |
|
7732 | 62 |
QSet<QString> m_friendsSet, m_ignoredSet; |
63 |
QString m_nickname; |
|
64 |
||
7725 | 65 |
void updateIcon(const QModelIndex & index); |
7728 | 66 |
void updateSortData(const QModelIndex & index); |
7732 | 67 |
void loadSet(QSet<QString> & set, const QString & suffix); |
68 |
void saveSet(const QSet<QString> & set, const QString & suffix); |
|
69 |
void checkFriendIgnore(const QModelIndex & mi); |
|
7723 | 70 |
}; |
71 |
||
72 |
#endif // PLAYERSLISTMODEL_H |