QTfrontend/model/playerslistmodel.h
author sheepluva
Thu, 12 Jun 2014 14:42:48 +0200
changeset 10285 03b615d3c6e1
parent 9727 e89ed65f62da
child 10753 e56db5d988ef
permissions -rw-r--r--
further WIP (better error messages)
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
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    26
    };
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    27
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    28
    enum SpecialRoles {
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    29
        SortRole       = Qt::UserRole + 100,
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    30
        RoomFilterRole = Qt::UserRole + 101
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    31
    };
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    32
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    33
    explicit PlayersListModel(QObject *parent = 0);
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    34
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    35
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    36
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    37
    QVariant data(const QModelIndex &index, int role) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    38
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
7737
ff63da8a3202 - Enable chat context menu actions
unc0rr
parents: 7732
diff changeset
    39
    void setFlag(const QString & nickname, StateFlag flagType, bool isSet);
ff63da8a3202 - Enable chat context menu actions
unc0rr
parents: 7732
diff changeset
    40
    bool isFlagSet(const QString & nickname, StateFlag flagType);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    41
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    42
    bool insertRow(int row, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    43
    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    44
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    45
9727
e89ed65f62da small cleanup etc
sheepluva
parents: 9725
diff changeset
    46
    QModelIndex nicknameIndex(const QString & nickname);
e89ed65f62da small cleanup etc
sheepluva
parents: 9725
diff changeset
    47
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    48
public slots:
8891
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    49
    void addPlayer(const QString & nickname, bool notify);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    50
    void removePlayer(const QString & nickname, const QString & msg = QString());
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    51
    void playerJoinedRoom(const QString & nickname, bool notify);
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    52
    void playerLeftRoom(const QString & nickname);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    53
    void resetRoomFlags();
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    54
    void setNickname(const QString & nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    55
8891
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    56
signals:
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    57
    void nickAdded(const QString& nick, bool notifyNick);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    58
    void nickRemoved(const QString& nick);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    59
    void nickAddedLobby(const QString& nick, bool notifyNick);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    60
    void nickRemovedLobby(const QString& nick);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    61
    void nickRemovedLobby(const QString& nick, const QString& message);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    62
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    63
private:
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    64
    QHash<quint32, QIcon> & m_icons();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    65
    typedef QHash<int, QVariant> DataEntry;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    66
    QList<DataEntry> m_data;
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    67
    QSet<QString> m_friendsSet, m_ignoredSet;
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    68
    QString m_nickname;
9503
8f9b04138456 Icons for 'i' and 'c' flags
unc0rr
parents: 8891
diff changeset
    69
    QFont m_fontInRoom;
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    70
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    71
    void updateIcon(const QModelIndex & index);
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    72
    void updateSortData(const QModelIndex & index);
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    73
    void loadSet(QSet<QString> & set, const QString & suffix);
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    74
    void saveSet(const QSet<QString> & set, const QString & suffix);
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    75
    void checkFriendIgnore(const QModelIndex & mi);
9725
68b5d87cfdb0 regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents: 9503
diff changeset
    76
    bool isFriend(const QString & nickname);
68b5d87cfdb0 regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents: 9503
diff changeset
    77
    bool isIgnored(const QString & nickname);
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    78
};
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    79
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    80
#endif // PLAYERSLISTMODEL_H