QTfrontend/model/playerslistmodel.h
author koda
Sun, 20 Jan 2013 22:51:26 +0100
changeset 8410 48a7986e46f8
parent 7765 1e162c1d6dc7
child 8891 bf67b4d7d7b4
permissions -rw-r--r--
fix out of source build
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>
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     9
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    10
class PlayersListModel : public QAbstractListModel
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    11
{
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    12
    Q_OBJECT
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    13
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    14
public:
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    15
    enum StateFlag {
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    16
        Ready       = Qt::UserRole,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    17
        ServerAdmin = Qt::UserRole + 1,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    18
        RoomAdmin   = Qt::UserRole + 2,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    19
        Registered  = Qt::UserRole + 3,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    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
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    23
    };
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    24
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    25
    enum SpecialRoles {
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    26
        SortRole       = Qt::UserRole + 100,
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    27
        RoomFilterRole = Qt::UserRole + 101
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    28
    };
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    29
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    30
    explicit PlayersListModel(QObject *parent = 0);
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    31
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    32
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    33
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    34
    QVariant data(const QModelIndex &index, int role) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    35
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
7737
ff63da8a3202 - Enable chat context menu actions
unc0rr
parents: 7732
diff changeset
    36
    void setFlag(const QString & nickname, StateFlag flagType, bool isSet);
ff63da8a3202 - Enable chat context menu actions
unc0rr
parents: 7732
diff changeset
    37
    bool isFlagSet(const QString & nickname, StateFlag flagType);
7725
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
    bool insertRow(int row, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    40
    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    41
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    42
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    43
public slots:
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    44
    void addPlayer(const QString & nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    45
    void removePlayer(const QString & nickname);
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    46
    void playerJoinedRoom(const QString & nickname);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    47
    void playerLeftRoom(const QString & nickname);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    48
    void resetRoomFlags();
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    49
    void setNickname(const QString & nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    50
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    51
private:
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    52
    QHash<quint32, QIcon> & m_icons();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    53
    typedef QHash<int, QVariant> DataEntry;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    54
    QList<DataEntry> m_data;
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    55
    QSet<QString> m_friendsSet, m_ignoredSet;
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    56
    QString m_nickname;
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    57
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    58
    void updateIcon(const QModelIndex & index);
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    59
    void updateSortData(const QModelIndex & index);
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    60
    void loadSet(QSet<QString> & set, const QString & suffix);
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    61
    void saveSet(const QSet<QString> & set, const QString & suffix);
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    62
    void checkFriendIgnore(const QModelIndex & mi);
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    63
};
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    64
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    65
#endif // PLAYERSLISTMODEL_H