QTfrontend/model/playerslistmodel.h
author unc0rr
Mon, 08 Oct 2012 23:57:17 +0400
changeset 7731 262228c64f15
parent 7728 664738870325
child 7732 fad3408fdcc1
permissions -rw-r--r--
Room players list
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>
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     8
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     9
class PlayersListModel : public QAbstractListModel
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    10
{
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    11
    Q_OBJECT
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    12
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    13
public:
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    14
    enum StateFlag {
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    15
        Ready       = Qt::UserRole,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    16
        ServerAdmin = Qt::UserRole + 1,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    17
        RoomAdmin   = Qt::UserRole + 2,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    18
        Registered  = Qt::UserRole + 3,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    19
        Friend      = Qt::UserRole + 4,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    20
        Ignore      = Qt::UserRole + 5
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    21
    };
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    22
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    23
    enum SpecialRoles {
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    24
        SortRole       = Qt::UserRole + 100,
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    25
        RoomFilterRole = Qt::UserRole + 101
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    26
    };
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    27
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    28
    explicit PlayersListModel(QObject *parent = 0);
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    29
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    30
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    31
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    32
    QVariant data(const QModelIndex &index, int role) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    33
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    34
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    35
    bool insertRow(int row, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    36
    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    37
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    38
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    39
public slots:
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    40
    void addPlayer(const QString & nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    41
    void removePlayer(const QString & nickname);
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    42
    void playerJoinedRoom(const QString & nickname);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    43
    void playerLeftRoom(const QString & nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    44
    void setFlag(const QString & nickname, StateFlag flagType, bool isSet);
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    45
    void resetRoomFlags();
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    46
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    47
private:
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    48
    QHash<quint32, QIcon> & m_icons();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    49
    typedef QHash<int, QVariant> DataEntry;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    50
    QList<DataEntry> m_data;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    51
    void updateIcon(const QModelIndex & index);
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    52
    void updateSortData(const QModelIndex & index);
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    53
};
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    54
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    55
#endif // PLAYERSLISTMODEL_H