QTfrontend/model/playerslistmodel.h
author unc0rr
Sat, 27 Feb 2016 18:02:24 +0300
changeset 11578 013264e25d71
parent 10753 e56db5d988ef
permissions -rw-r--r--
Recognize ghost points in checker
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     1
#ifndef PLAYERSLISTMODEL_H
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     2
#define PLAYERSLISTMODEL_H
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     3
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     4
#include <QAbstractListModel>
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     5
#include <QHash>
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     6
#include <QIcon>
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     7
#include <QModelIndex>
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
     8
#include <QSet>
9503
8f9b04138456 Icons for 'i' and 'c' flags
unc0rr
parents: 8891
diff changeset
     9
#include <QFont>
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    10
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    11
class PlayersListModel : public QAbstractListModel
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    12
{
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    13
    Q_OBJECT
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    14
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    15
public:
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    16
    enum StateFlag {
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    17
        Ready       = Qt::UserRole,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    18
        ServerAdmin = Qt::UserRole + 1,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    19
        RoomAdmin   = Qt::UserRole + 2,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    20
        Registered  = Qt::UserRole + 3,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    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
8f9b04138456 Icons for 'i' and 'c' flags
unc0rr
parents: 8891
diff changeset
    23
        InGame      = Qt::UserRole + 6,
8f9b04138456 Icons for 'i' and 'c' flags
unc0rr
parents: 8891
diff changeset
    24
        InRoom      = Qt::UserRole + 7,
8f9b04138456 Icons for 'i' and 'c' flags
unc0rr
parents: 8891
diff changeset
    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
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    28
    };
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    29
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    30
    enum SpecialRoles {
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    31
        SortRole       = Qt::UserRole + 100,
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    32
        RoomFilterRole = Qt::UserRole + 101
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    33
    };
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    34
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    35
    explicit PlayersListModel(QObject *parent = 0);
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    36
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    37
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    38
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    39
    QVariant data(const QModelIndex &index, int role) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    40
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
7737
ff63da8a3202 - Enable chat context menu actions
unc0rr
parents: 7732
diff changeset
    41
    void setFlag(const QString & nickname, StateFlag flagType, bool isSet);
ff63da8a3202 - Enable chat context menu actions
unc0rr
parents: 7732
diff changeset
    42
    bool isFlagSet(const QString & nickname, StateFlag flagType);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    43
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    44
    bool insertRow(int row, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    45
    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    46
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    47
9727
e89ed65f62da small cleanup etc
sheepluva
parents: 9725
diff changeset
    48
    QModelIndex nicknameIndex(const QString & nickname);
e89ed65f62da small cleanup etc
sheepluva
parents: 9725
diff changeset
    49
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    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
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    54
    void playerLeftRoom(const QString & nickname);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    55
    void resetRoomFlags();
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    56
    void setNickname(const QString & nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    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
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    65
private:
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    66
    QHash<quint32, QIcon> & m_icons();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    67
    typedef QHash<int, QVariant> DataEntry;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    68
    QList<DataEntry> m_data;
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    69
    QSet<QString> m_friendsSet, m_ignoredSet;
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    70
    QString m_nickname;
9503
8f9b04138456 Icons for 'i' and 'c' flags
unc0rr
parents: 8891
diff changeset
    71
    QFont m_fontInRoom;
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    72
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    73
    void updateIcon(const QModelIndex & index);
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    74
    void updateSortData(const QModelIndex & index);
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    75
    void loadSet(QSet<QString> & set, const QString & suffix);
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    76
    void saveSet(const QSet<QString> & set, const QString & suffix);
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    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
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    80
};
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    81
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    82
#endif // PLAYERSLISTMODEL_H