author | Wuzzy <Wuzzy2@mail.ru> |
Sun, 02 Sep 2018 21:26:44 +0200 | |
changeset 13745 | 2bb7141496a9 |
parent 10753 | e56db5d988ef |
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> |
9503 | 9 |
#include <QFont> |
7723 | 10 |
|
7725 | 11 |
class PlayersListModel : public QAbstractListModel |
7723 | 12 |
{ |
13 |
Q_OBJECT |
|
7725 | 14 |
|
7723 | 15 |
public: |
7725 | 16 |
enum StateFlag { |
17 |
Ready = Qt::UserRole, |
|
18 |
ServerAdmin = Qt::UserRole + 1, |
|
19 |
RoomAdmin = Qt::UserRole + 2, |
|
20 |
Registered = Qt::UserRole + 3, |
|
21 |
Friend = Qt::UserRole + 4, |
|
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7737
diff
changeset
|
22 |
Ignore = Qt::UserRole + 5, |
9503 | 23 |
InGame = Qt::UserRole + 6, |
24 |
InRoom = Qt::UserRole + 7, |
|
25 |
Contributor = Qt::UserRole + 8 |
|
10753
e56db5d988ef
fix issue with contributor hat being displayed for wrong players
sheepluva
parents:
9727
diff
changeset
|
26 |
// if you add a role that will affect the player icon, |
e56db5d988ef
fix issue with contributor hat being displayed for wrong players
sheepluva
parents:
9727
diff
changeset
|
27 |
// then also add it to the flags Qlist in updateIcon()! |
7725 | 28 |
}; |
29 |
||
7728 | 30 |
enum SpecialRoles { |
7731 | 31 |
SortRole = Qt::UserRole + 100, |
32 |
RoomFilterRole = Qt::UserRole + 101 |
|
7728 | 33 |
}; |
34 |
||
7723 | 35 |
explicit PlayersListModel(QObject *parent = 0); |
36 |
||
7725 | 37 |
int rowCount(const QModelIndex &parent = QModelIndex()) const; |
38 |
||
39 |
QVariant data(const QModelIndex &index, int role) const; |
|
40 |
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole); |
|
7737 | 41 |
void setFlag(const QString & nickname, StateFlag flagType, bool isSet); |
42 |
bool isFlagSet(const QString & nickname, StateFlag flagType); |
|
7725 | 43 |
|
44 |
bool insertRow(int row, const QModelIndex &parent = QModelIndex()); |
|
45 |
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
46 |
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
47 |
||
9727 | 48 |
QModelIndex nicknameIndex(const QString & nickname); |
49 |
||
7723 | 50 |
public slots: |
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
51 |
void addPlayer(const QString & nickname, bool notify); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
52 |
void removePlayer(const QString & nickname, const QString & msg = QString()); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
53 |
void playerJoinedRoom(const QString & nickname, bool notify); |
7731 | 54 |
void playerLeftRoom(const QString & nickname); |
55 |
void resetRoomFlags(); |
|
7732 | 56 |
void setNickname(const QString & nickname); |
7725 | 57 |
|
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
58 |
signals: |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
59 |
void nickAdded(const QString& nick, bool notifyNick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
60 |
void nickRemoved(const QString& nick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
61 |
void nickAddedLobby(const QString& nick, bool notifyNick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
62 |
void nickRemovedLobby(const QString& nick); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
63 |
void nickRemovedLobby(const QString& nick, const QString& message); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7765
diff
changeset
|
64 |
|
7725 | 65 |
private: |
66 |
QHash<quint32, QIcon> & m_icons(); |
|
67 |
typedef QHash<int, QVariant> DataEntry; |
|
68 |
QList<DataEntry> m_data; |
|
7732 | 69 |
QSet<QString> m_friendsSet, m_ignoredSet; |
70 |
QString m_nickname; |
|
9503 | 71 |
QFont m_fontInRoom; |
7732 | 72 |
|
7725 | 73 |
void updateIcon(const QModelIndex & index); |
7728 | 74 |
void updateSortData(const QModelIndex & index); |
7732 | 75 |
void loadSet(QSet<QString> & set, const QString & suffix); |
76 |
void saveSet(const QSet<QString> & set, const QString & suffix); |
|
77 |
void checkFriendIgnore(const QModelIndex & mi); |
|
9725
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
78 |
bool isFriend(const QString & nickname); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
79 |
bool isIgnored(const QString & nickname); |
7723 | 80 |
}; |
81 |
||
82 |
#endif // PLAYERSLISTMODEL_H |